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

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

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

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

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

misc.c:constant_time_eq_s:
  124|  3.49k|{
  125|  3.49k|	return constant_time_is_zero_s(a ^ b);
  126|  3.49k|}
misc.c:constant_time_is_zero_s:
   91|  3.49k|{
   92|  3.49k|	return constant_time_msb_s(~a & (a - 1));
   93|  3.49k|}
misc.c:constant_time_msb_s:
   53|  3.49k|{
   54|  3.49k|	return 0 - (a >> (sizeof(a) * 8 - 1));
   55|  3.49k|}
mechanism.c:constant_time_eq_s:
  124|    186|{
  125|    186|	return constant_time_is_zero_s(a ^ b);
  126|    186|}
mechanism.c:constant_time_is_zero_s:
   91|    186|{
   92|    186|	return constant_time_msb_s(~a & (a - 1));
   93|    186|}
mechanism.c:constant_time_msb_s:
   53|    186|{
   54|    186|	return 0 - (a >> (sizeof(a) * 8 - 1));
   55|    186|}
framework-pkcs15.c:constant_time_eq_s:
  124|    185|{
  125|    185|	return constant_time_is_zero_s(a ^ b);
  126|    185|}
framework-pkcs15.c:constant_time_is_zero_s:
   91|    185|{
   92|    185|	return constant_time_msb_s(~a & (a - 1));
   93|    185|}
framework-pkcs15.c:constant_time_msb_s:
   53|   137k|{
   54|   137k|	return 0 - (a >> (sizeof(a) * 8 - 1));
   55|   137k|}
framework-pkcs15.c:constant_time_lt_s:
   98|   137k|{
   99|   137k|	return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));
  100|   137k|}
framework-pkcs15.c:constant_time_eq_i:
  130|     67|{
  131|     67|	return constant_time_eq((unsigned int)a, (unsigned int)b);
  132|     67|}
framework-pkcs15.c:constant_time_eq:
  118|     67|{
  119|     67|	return constant_time_is_zero(a ^ b);
  120|     67|}
framework-pkcs15.c:constant_time_is_zero:
   85|     67|{
   86|     67|	return constant_time_msb(~a & (a - 1));
   87|     67|}
framework-pkcs15.c:constant_time_msb:
   59|     67|{
   60|     67|	return 0 - (a >> (sizeof(a) * 8 - 1));
   61|     67|}
framework-pkcs15.c:constant_time_select_s:
   78|   137k|{
   79|   137k|	return (value_barrier_s(mask) & a) | (value_barrier_s(~mask) & b);
   80|   137k|}
framework-pkcs15.c:value_barrier_s:
   45|   274k|{
   46|   274k|	volatile size_t r = a;
   47|   274k|	return r;
   48|   274k|}
framework-pkcs15.c:constant_time_select_8:
   72|  68.6k|{
   73|  68.6k|	return (unsigned char)constant_time_select(mask, a, b);
   74|  68.6k|}
framework-pkcs15.c:constant_time_select:
   66|  68.6k|{
   67|  68.6k|	return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
   68|  68.6k|}
framework-pkcs15.c:value_barrier:
   38|   137k|{
   39|   137k|	volatile unsigned int r = a;
   40|   137k|	return r;
   41|   137k|}
padding.c:constant_time_is_zero:
   85|  27.5k|{
   86|  27.5k|	return constant_time_msb(~a & (a - 1));
   87|  27.5k|}
padding.c:constant_time_msb:
   59|  31.8k|{
   60|  31.8k|	return 0 - (a >> (sizeof(a) * 8 - 1));
   61|  31.8k|}
padding.c:constant_time_eq:
  118|    435|{
  119|    435|	return constant_time_is_zero(a ^ b);
  120|    435|}
padding.c:constant_time_select:
   66|   115k|{
   67|   115k|	return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
   68|   115k|}
padding.c:value_barrier:
   38|   231k|{
   39|   231k|	volatile unsigned int r = a;
   40|   231k|	return r;
   41|   231k|}
padding.c:constant_time_ge:
  110|     94|{
  111|     94|	return ~constant_time_lt(a, b);
  112|     94|}
padding.c:constant_time_lt:
  104|  4.29k|{
  105|  4.29k|	return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
  106|  4.29k|}
padding.c:constant_time_select_8:
   72|  98.1k|{
   73|  98.1k|	return (unsigned char)constant_time_select(mask, a, b);
   74|  98.1k|}

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

sc_apdu_get_length:
   43|  3.16k|{
   44|  3.16k|	size_t ret = 4;
   45|       |
   46|  3.16k|	switch (apdu->cse) {
   47|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (47:2): [True: 0, False: 3.16k]
  ------------------
   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|  3.16k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  3.16k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (51:2): [True: 3.16k, False: 0]
  ------------------
   52|  3.16k|		ret++;
   53|  3.16k|		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: 3.16k]
  ------------------
   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: 3.16k]
  ------------------
   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: 3.16k]
  ------------------
   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: 3.16k]
  ------------------
   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: 3.16k]
  ------------------
   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: 3.16k]
  ------------------
   70|      0|		return 0;
   71|  3.16k|	}
   72|  3.16k|	return ret;
   73|  3.16k|}
sc_apdu2bytes:
   85|  1.58k|{
   86|  1.58k|	u8     *p = out;
   87|       |
   88|  1.58k|	size_t len = sc_apdu_get_length(apdu, proto);
   89|       |
   90|  1.58k|	if (out == NULL || outlen < len)
  ------------------
  |  Branch (90:6): [True: 0, False: 1.58k]
  |  Branch (90:21): [True: 0, False: 1.58k]
  ------------------
   91|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|       |	/* CLA, INS, P1 and P2 */
   93|  1.58k|	*p++ = apdu->cla;
   94|  1.58k|	*p++ = apdu->ins;
   95|  1.58k|	*p++ = apdu->p1;
   96|  1.58k|	*p++ = apdu->p2;
   97|       |	/* case depend part */
   98|  1.58k|	switch (apdu->cse) {
  ------------------
  |  Branch (98:10): [True: 1.58k, False: 0]
  ------------------
   99|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (99:2): [True: 0, False: 1.58k]
  ------------------
  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|  1.58k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  1.58k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (104:2): [True: 1.58k, False: 0]
  ------------------
  105|  1.58k|		*p = (u8)apdu->le;
  106|  1.58k|		break;
  107|      0|	case SC_APDU_CASE_2_EXT:
  ------------------
  |  |  297|      0|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (107:2): [True: 0, False: 1.58k]
  ------------------
  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: 1.58k]
  ------------------
  119|      0|		*p++ = (u8)apdu->lc;
  120|      0|		memcpy(p, apdu->data, apdu->lc);
  121|      0|		break;
  122|      0|	case SC_APDU_CASE_3_EXT:
  ------------------
  |  |  298|      0|#define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  |  |  ------------------
  |  |               #define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (122:2): [True: 0, False: 1.58k]
  ------------------
  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: 1.58k]
  ------------------
  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: 1.58k]
  ------------------
  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|  1.58k|	}
  170|       |
  171|  1.58k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.58k|#define SC_SUCCESS				0
  ------------------
  172|  1.58k|}
sc_apdu_get_octets:
  176|  1.58k|{
  177|  1.58k|	size_t	nlen;
  178|  1.58k|	u8	*nbuf;
  179|       |
  180|  1.58k|	if (apdu == NULL || buf == NULL || len == NULL)
  ------------------
  |  Branch (180:6): [True: 0, False: 1.58k]
  |  Branch (180:22): [True: 0, False: 1.58k]
  |  Branch (180:37): [True: 0, False: 1.58k]
  ------------------
  181|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  182|       |
  183|       |	/* get the estimated length of encoded APDU */
  184|  1.58k|	nlen = sc_apdu_get_length(apdu, proto);
  185|  1.58k|	if (nlen == 0)
  ------------------
  |  Branch (185:6): [True: 0, False: 1.58k]
  ------------------
  186|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  187|  1.58k|	nbuf = malloc(nlen);
  188|  1.58k|	if (nbuf == NULL)
  ------------------
  |  Branch (188:6): [True: 0, False: 1.58k]
  ------------------
  189|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  190|       |	/* encode the APDU in the buffer */
  191|  1.58k|	if (sc_apdu2bytes(ctx, apdu, proto, nbuf, nlen) != SC_SUCCESS) {
  ------------------
  |  |   28|  1.58k|#define SC_SUCCESS				0
  ------------------
  |  Branch (191:6): [True: 0, False: 1.58k]
  ------------------
  192|      0|		free(nbuf);
  193|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  194|      0|	}
  195|  1.58k|	*buf = nbuf;
  196|  1.58k|	*len = nlen;
  197|       |
  198|  1.58k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.58k|#define SC_SUCCESS				0
  ------------------
  199|  1.58k|}
sc_check_apdu:
  257|   568k|{
  258|   568k|	if ((apdu->cse & ~SC_APDU_SHORT_MASK) == 0) {
  ------------------
  |  |  295|   568k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  |  Branch (258:6): [True: 567k, False: 1.76k]
  ------------------
  259|       |		/* length check for short APDU */
  260|   567k|		if (apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0))   {
  ------------------
  |  |  306|     20|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (260:7): [True: 14, False: 567k]
  |  Branch (260:26): [True: 20, False: 567k]
  |  Branch (260:44): [True: 0, False: 20]
  ------------------
  261|     14|			sc_log(card->ctx, "failed length check for short APDU");
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  262|     14|			goto error;
  263|     14|		}
  264|   567k|	}
  265|  1.76k|	else if ((apdu->cse & SC_APDU_EXT) != 0) {
  ------------------
  |  |  296|  1.76k|#define SC_APDU_EXT			0x10
  ------------------
  |  Branch (265:11): [True: 1.76k, False: 0]
  ------------------
  266|       |		/* check if the card supports extended APDUs */
  267|  1.76k|		if ((card->caps & SC_CARD_CAP_APDU_EXT) == 0) {
  ------------------
  |  |  547|  1.76k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (267:7): [True: 1, False: 1.76k]
  ------------------
  268|      1|			sc_log(card->ctx, "card doesn't support extended APDUs");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  269|      1|			goto error;
  270|      1|		}
  271|       |		/* length check for extended APDU */
  272|  1.76k|		if (apdu->le > 65536 || apdu->lc > 65535)   {
  ------------------
  |  Branch (272:7): [True: 0, False: 1.76k]
  |  Branch (272:27): [True: 0, False: 1.76k]
  ------------------
  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|  1.76k|	}
  277|      0|	else   {
  278|      0|		goto error;
  279|      0|	}
  280|       |
  281|   568k|	switch (apdu->cse & SC_APDU_SHORT_MASK) {
  ------------------
  |  |  295|   568k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  282|  3.67k|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|  3.67k|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (282:2): [True: 3.67k, False: 565k]
  ------------------
  283|       |		/* no data is sent or received */
  284|  3.67k|		if (apdu->datalen != 0 || apdu->lc != 0 || apdu->le != 0)
  ------------------
  |  Branch (284:7): [True: 0, False: 3.67k]
  |  Branch (284:29): [True: 0, False: 3.67k]
  |  Branch (284:46): [True: 0, False: 3.67k]
  ------------------
  285|      0|			goto error;
  286|  3.67k|		break;
  287|   219k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|   219k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (287:2): [True: 219k, False: 348k]
  ------------------
  288|       |		/* no data is sent */
  289|   219k|		if (apdu->datalen != 0 || apdu->lc != 0)
  ------------------
  |  Branch (289:7): [True: 0, False: 219k]
  |  Branch (289:29): [True: 0, False: 219k]
  ------------------
  290|      0|			goto error;
  291|       |		/* data is expected       */
  292|   219k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (292:7): [True: 2, False: 219k]
  |  Branch (292:29): [True: 0, False: 219k]
  ------------------
  293|      2|			goto error;
  294|   219k|		break;
  295|   219k|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|  69.5k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (295:2): [True: 69.5k, False: 499k]
  ------------------
  296|       |		/* data is sent */
  297|  69.5k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (297:7): [True: 0, False: 69.5k]
  |  Branch (297:29): [True: 0, False: 69.5k]
  |  Branch (297:51): [True: 0, False: 69.5k]
  ------------------
  298|      0|			goto error;
  299|       |		/* no data is expected    */
  300|  69.5k|		if (apdu->le != 0)
  ------------------
  |  Branch (300:7): [True: 0, False: 69.5k]
  ------------------
  301|      0|			goto error;
  302|       |		/* inconsistent datalen   */
  303|  69.5k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (303:7): [True: 0, False: 69.5k]
  ------------------
  304|      0|			goto error;
  305|  69.5k|		break;
  306|   275k|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|   275k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (306:2): [True: 275k, False: 293k]
  ------------------
  307|       |		/* data is sent */
  308|   275k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (308:7): [True: 27, False: 275k]
  |  Branch (308:29): [True: 0, False: 275k]
  |  Branch (308:51): [True: 0, False: 275k]
  ------------------
  309|     27|			goto error;
  310|       |		/* data is expected       */
  311|   275k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (311:7): [True: 0, False: 275k]
  |  Branch (311:29): [True: 0, False: 275k]
  ------------------
  312|      0|			goto error;
  313|       |		/* inconsistent datalen   */
  314|   275k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (314:7): [True: 0, False: 275k]
  ------------------
  315|      0|			goto error;
  316|   275k|		break;
  317|   275k|	default:
  ------------------
  |  Branch (317:2): [True: 0, False: 568k]
  ------------------
  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|   568k|	}
  321|   568k|	return SC_SUCCESS;
  ------------------
  |  |   28|   568k|#define SC_SUCCESS				0
  ------------------
  322|     44|error:
  323|     44|	sc_log(card->ctx, "Invalid Case %d %s APDU:\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__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  326|     88|		apdu->cse & SC_APDU_SHORT_MASK,
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|     44|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |  327|     88|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|     44|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  328|     88|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  |  |  |  |  329|     88|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  |  |  |  |  330|     88|		apdu->resp, (unsigned long) apdu->resplen,
  |  |  |  |  331|     88|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  |  |  ------------------
  ------------------
  324|     44|		"cse=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%lu le=%lu\n"
  325|     44|		"resp=%p resplen=%lu data=%p datalen=%lu flags=0x%8.8lx",
  326|     44|		apdu->cse & SC_APDU_SHORT_MASK,
  327|     44|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  328|     44|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  329|     44|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  330|     44|		apdu->resp, (unsigned long) apdu->resplen,
  331|     44|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  332|     44|	return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     44|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  333|   568k|}
sc_transmit_apdu:
  542|   550k|{
  543|   550k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   550k|#define SC_SUCCESS				0
  ------------------
  544|       |
  545|   550k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 550k]
  |  Branch (545:22): [True: 0, False: 550k]
  ------------------
  546|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  547|       |
  548|   550k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   550k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   550k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   550k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   550k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 550k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  549|       |
  550|       |	/* determine the APDU type if necessary, i.e. to use
  551|       |	 * short or extended APDUs  */
  552|   550k|	sc_detect_apdu_cse(card, apdu);
  553|       |	/* basic APDU consistency check */
  554|   550k|	r = sc_check_apdu(card, apdu);
  555|   550k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   550k|#define SC_SUCCESS				0
  ------------------
  |  Branch (555:6): [True: 44, False: 550k]
  ------------------
  556|     44|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     44|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  557|       |
  558|   550k|	r = sc_lock(card);	/* acquire card lock*/
  559|   550k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|   550k|#define SC_SUCCESS				0
  ------------------
  |  Branch (559:6): [True: 0, False: 550k]
  ------------------
  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|   550k|#if ENABLE_SM
  565|   550k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|  1.10M|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (565:6): [True: 7.22k, False: 542k]
  ------------------
  566|  7.22k|			&& (apdu->flags & SC_APDU_FLAGS_CHAINING) != 0
  ------------------
  |  |  306|  7.22k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (566:7): [True: 0, False: 7.22k]
  ------------------
  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|   550k|#endif
  572|   550k|	if ((apdu->flags & SC_APDU_FLAGS_CHAINING) != 0) {
  ------------------
  |  |  306|   550k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (572:6): [True: 13.0k, False: 537k]
  ------------------
  573|       |		/* divide et impera: transmit APDU in chunks with Lc <= max_send_size
  574|       |		 * bytes using command chaining */
  575|  13.0k|		size_t    len  = apdu->datalen;
  576|  13.0k|		const u8  *buf = apdu->data;
  577|  13.0k|		size_t    max_send_size = sc_get_max_send_size(card);
  578|       |
  579|  27.5k|		while (len != 0) {
  ------------------
  |  Branch (579:10): [True: 14.9k, False: 12.5k]
  ------------------
  580|  14.9k|			size_t    plen;
  581|  14.9k|			sc_apdu_t tapdu;
  582|  14.9k|			int       last = 0;
  583|       |
  584|  14.9k|			tapdu = *apdu;
  585|       |			/* clear chaining flag */
  586|  14.9k|			tapdu.flags &= ~SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  14.9k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  587|  14.9k|			if (len > max_send_size) {
  ------------------
  |  Branch (587:8): [True: 2.22k, False: 12.7k]
  ------------------
  588|       |				/* adjust APDU case: in case of CASE 4 APDU
  589|       |				 * the intermediate APDU are of CASE 3 */
  590|  2.22k|				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  295|  2.22k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
              				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  294|  2.22k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (590:9): [True: 2.22k, False: 0]
  ------------------
  591|  2.22k|					tapdu.cse--;
  592|       |				/* XXX: the chunk size must be adjusted when
  593|       |				 *      secure messaging is used */
  594|  2.22k|				plen          = max_send_size;
  595|  2.22k|				tapdu.cla    |= 0x10;
  596|       |				/* the intermediate APDU don't expect response data */
  597|  2.22k|				tapdu.le      = 0;
  598|  2.22k|				tapdu.resplen = 0;
  599|  2.22k|				tapdu.resp    = NULL;
  600|  12.7k|			} else {
  601|  12.7k|				plen = len;
  602|  12.7k|				last = 1;
  603|  12.7k|			}
  604|  14.9k|			tapdu.data    = buf;
  605|  14.9k|			tapdu.datalen = tapdu.lc = plen;
  606|       |
  607|  14.9k|			r = sc_check_apdu(card, &tapdu);
  608|  14.9k|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  14.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (608:8): [True: 0, False: 14.9k]
  ------------------
  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|  14.9k|			r = sc_transmit(card, &tapdu);
  614|  14.9k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  14.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (614:8): [True: 239, False: 14.7k]
  ------------------
  615|    239|				break;
  616|  14.7k|			if (last != 0) {
  ------------------
  |  Branch (616:8): [True: 12.5k, False: 2.22k]
  ------------------
  617|       |				/* in case of the last APDU set the SW1
  618|       |				 * and SW2 bytes in the original APDU */
  619|  12.5k|				apdu->sw1 = tapdu.sw1;
  620|  12.5k|				apdu->sw2 = tapdu.sw2;
  621|  12.5k|				apdu->resplen = tapdu.resplen;
  622|  12.5k|			} else {
  623|       |				/* otherwise check the status bytes */
  624|  2.22k|				r = sc_check_sw(card, tapdu.sw1, tapdu.sw2);
  625|  2.22k|				if (r != SC_SUCCESS)
  ------------------
  |  |   28|  2.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (625:9): [True: 281, False: 1.94k]
  ------------------
  626|    281|					break;
  627|  2.22k|			}
  628|  14.4k|			len -= plen;
  629|  14.4k|			buf += plen;
  630|  14.4k|		}
  631|   537k|	} else {
  632|       |		/* transmit single APDU */
  633|   537k|		r = sc_transmit(card, apdu);
  634|   537k|	}
  635|       |
  636|   550k|	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|  1.10M|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   550k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (636:6): [True: 0, False: 550k]
  |  Branch (636:34): [True: 0, False: 550k]
  ------------------
  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|   550k|	if (sc_unlock(card) != SC_SUCCESS)
  ------------------
  |  |   28|   550k|#define SC_SUCCESS				0
  ------------------
  |  Branch (643:6): [True: 0, False: 550k]
  ------------------
  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|   550k|	return r;
  647|   550k|}
sc_bytes2apdu:
  652|     71|{
  653|     71|	const unsigned char *p;
  654|     71|	size_t len0;
  655|       |
  656|     71|	if (!buf || !apdu)
  ------------------
  |  Branch (656:6): [True: 0, False: 71]
  |  Branch (656:14): [True: 0, False: 71]
  ------------------
  657|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  658|       |
  659|     71|	len0 = len;
  660|     71|	if (len < 4) {
  ------------------
  |  Branch (660:6): [True: 0, False: 71]
  ------------------
  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|     71|	memset(apdu, 0, sizeof *apdu);
  666|     71|	p = buf;
  667|     71|	apdu->cla = *p++;
  668|     71|	apdu->ins = *p++;
  669|     71|	apdu->p1 = *p++;
  670|     71|	apdu->p2 = *p++;
  671|     71|	len -= 4;
  672|       |
  673|     71|	if (!len) {
  ------------------
  |  Branch (673:6): [True: 0, False: 71]
  ------------------
  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|     71|	if (*p == 0 && len >= 3) {
  ------------------
  |  Branch (680:6): [True: 0, False: 71]
  |  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|     71|	else {
  723|       |		/* ...must be a short APDU */
  724|     71|		if (len == 1) {
  ------------------
  |  Branch (724:7): [True: 71, False: 0]
  ------------------
  725|     71|			apdu->le = *p++;
  726|     71|			if (apdu->le == 0)
  ------------------
  |  Branch (726:8): [True: 0, False: 71]
  ------------------
  727|      0|				apdu->le = 0xff+1;
  728|     71|			len--;
  729|     71|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|     71|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  730|     71|		}
  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|     71|	}
  754|     71|	if (len) {
  ------------------
  |  Branch (754:6): [True: 0, False: 71]
  ------------------
  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|     71|	sc_log(ctx, "Case %d %s APDU, %zu bytes:\tins=%02x p1=%02x p2=%02x lc=%04zx le=%04zx",
  ------------------
  |  |   71|     71|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  760|    142|			apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|     71|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |               			apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|     71|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  761|    142|			len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
  |  |  ------------------
  ------------------
  760|     71|			apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  761|     71|			len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
  762|       |
  763|     71|	return SC_SUCCESS;
  ------------------
  |  |   28|     71|#define SC_SUCCESS				0
  ------------------
  764|     71|}
apdu.c:sc_detect_apdu_cse:
  341|   550k|{
  342|   550k|	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  301|  1.10M|#define SC_APDU_CASE_2			0x22
  ------------------
              	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  302|   926k|#define SC_APDU_CASE_3			0x23
  ------------------
  |  Branch (342:6): [True: 174k, False: 375k]
  |  Branch (342:37): [True: 9, False: 375k]
  ------------------
  343|   375k|	    apdu->cse == SC_APDU_CASE_4) {
  ------------------
  |  |  303|   375k|#define SC_APDU_CASE_4			0x24
  ------------------
  |  Branch (343:6): [True: 8.22k, False: 367k]
  ------------------
  344|   182k|		int btype = apdu->cse & SC_APDU_SHORT_MASK;
  ------------------
  |  |  295|   182k|#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|   182k|		if ((apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0)) &&
  ------------------
  |  |  306|     17|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (349:8): [True: 1.67k, False: 180k]
  |  Branch (349:27): [True: 17, False: 180k]
  |  Branch (349:45): [True: 0, False: 17]
  ------------------
  350|  1.67k|		    (card->caps & SC_CARD_CAP_APDU_EXT) != 0)
  ------------------
  |  |  547|  1.67k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (350:7): [True: 1.66k, False: 14]
  ------------------
  351|  1.66k|			btype |= SC_APDU_EXT;
  ------------------
  |  |  296|  1.66k|#define SC_APDU_EXT			0x10
  ------------------
  352|   182k|		apdu->cse = btype;
  353|   182k|	}
  354|   550k|}
apdu.c:sc_transmit:
  508|   552k|{
  509|   552k|	struct sc_context *ctx  = card->ctx;
  510|   552k|	size_t       olen  = apdu->resplen;
  511|   552k|	int          r;
  512|       |
  513|   552k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   552k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   552k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   552k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   552k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 552k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|   552k|	r = sc_single_transmit(card, apdu);
  516|   552k|	LOG_TEST_RET(ctx, r, "transmit APDU failed");
  ------------------
  |  |  174|   552k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   552k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   552k|	int _ret = (r); \
  |  |  |  |  168|   552k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 529, False: 551k]
  |  |  |  |  ------------------
  |  |  |  |  169|    529|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    529|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    529|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    529|		return _ret; \
  |  |  |  |  172|    529|	} \
  |  |  |  |  173|   552k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 551k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|   551k|	if (apdu->sw1 == 0x6C && (apdu->flags & SC_APDU_FLAGS_NO_RETRY_WL) == 0) {
  ------------------
  |  |  312|  1.78k|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  |  Branch (522:6): [True: 1.78k, False: 549k]
  |  Branch (522:27): [True: 1.64k, False: 136]
  ------------------
  523|  1.64k|		r = sc_set_le_and_transmit(card, apdu, olen);
  524|  1.64k|		LOG_TEST_RET(ctx, r, "cannot re-transmit APDU ");
  ------------------
  |  |  174|  1.64k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.64k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.64k|	int _ret = (r); \
  |  |  |  |  168|  1.64k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.12k, False: 527]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.12k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.12k|		return _ret; \
  |  |  |  |  172|  1.12k|	} \
  |  |  |  |  173|  1.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 527]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|  1.64k|	}
  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|   550k|	if (apdu->sw1 == 0x61 && (apdu->flags & SC_APDU_FLAGS_NO_GET_RESP) == 0) {
  ------------------
  |  |  308|   124k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  |  Branch (532:6): [True: 124k, False: 425k]
  |  Branch (532:27): [True: 56.6k, False: 68.1k]
  ------------------
  533|  56.6k|		r = sc_get_response(card, apdu, olen);
  534|  56.6k|		LOG_TEST_RET(ctx, r, "cannot get all data with 'GET RESPONSE'");
  ------------------
  |  |  174|  56.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  56.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  56.6k|	int _ret = (r); \
  |  |  |  |  168|  56.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.04k, False: 50.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.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|  6.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.04k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.04k|		return _ret; \
  |  |  |  |  172|  6.04k|	} \
  |  |  |  |  173|  56.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 50.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|  56.6k|	}
  536|       |
  537|   544k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|   544k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   544k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   544k|	int _ret = r; \
  |  |  |  |  155|   544k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 544k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   544k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 544k]
  |  |  |  |  ------------------
  |  |  |  |  157|   544k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   544k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   544k|	return _ret; \
  |  |  |  |  163|   544k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|   544k|}
apdu.c:sc_single_transmit:
  359|   552k|{
  360|   552k|	struct sc_context *ctx  = card->ctx;
  361|   552k|	int rv;
  362|       |
  363|   552k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   552k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   552k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   552k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   552k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 552k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|   552k|	if (card->reader->ops->transmit == NULL)
  ------------------
  |  Branch (364:6): [True: 0, False: 552k]
  ------------------
  365|   552k|		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|   552k|	sc_log(ctx, "CLA:%X, INS:%X, P1:%X, P2:%X, data(%zu) %p",
  ------------------
  |  |   71|   552k|#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|   552k|			apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen, apdu->data);
  369|   552k|#ifdef ENABLE_SM
  370|   552k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|  1.10M|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (370:6): [True: 7.23k, False: 545k]
  ------------------
  371|  7.23k|		   	&& (apdu->flags & SC_APDU_FLAGS_NO_SM) == 0) {
  ------------------
  |  |  314|  7.23k|#define SC_APDU_FLAGS_NO_SM		0x00000008UL
  ------------------
  |  Branch (371:10): [True: 3.61k, False: 3.61k]
  ------------------
  372|  3.61k|		LOG_FUNC_RETURN(ctx, sc_sm_single_transmit(card, apdu));
  ------------------
  |  |  164|  3.61k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.61k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.61k|	int _ret = r; \
  |  |  |  |  155|  3.61k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.61k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.61k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    532|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 532, False: 3.08k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.61k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.61k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.61k|	return _ret; \
  |  |  |  |  163|  3.61k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|  3.61k|	}
  374|   549k|#endif
  375|       |
  376|       |	/* send APDU to the reader driver */
  377|   549k|	rv = card->reader->ops->transmit(card->reader, apdu);
  378|   549k|	LOG_TEST_RET(ctx, rv, "unable to transmit APDU");
  ------------------
  |  |  174|   549k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   549k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   549k|	int _ret = (r); \
  |  |  |  |  168|   549k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 549k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|   549k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 549k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|   549k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|   549k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   549k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   549k|	int _ret = r; \
  |  |  |  |  155|   549k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 549k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   549k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 549k]
  |  |  |  |  ------------------
  |  |  |  |  157|   549k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   549k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   549k|	return _ret; \
  |  |  |  |  163|   549k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|   549k|}
apdu.c:sc_set_le_and_transmit:
  386|  1.64k|{
  387|  1.64k|	struct sc_context *ctx  = card->ctx;
  388|  1.64k|	size_t nlen = apdu->sw2 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (388:16): [True: 970, False: 679]
  ------------------
  389|  1.64k|	int rv;
  390|       |
  391|  1.64k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.64k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.64k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.64k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.64k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |	/* we cannot re-transmit the APDU with the demanded Le value
  393|       |	 * as the buffer is too small => error */
  394|  1.64k|	if (olen < nlen)
  ------------------
  |  Branch (394:6): [True: 1.11k, False: 530]
  ------------------
  395|  1.64k|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_LENGTH, "wrong length: required length exceeds resplen");
  ------------------
  |  |  174|  1.11k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.11k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.11k|	int _ret = (r); \
  |  |  |  |  168|  1.11k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.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|  1.11k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.11k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.11k|		return _ret; \
  |  |  |  |  172|  1.11k|	} \
  |  |  |  |  173|  1.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|       |
  397|       |	/* don't try again if it doesn't work this time */
  398|    530|	apdu->flags  |= SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  312|    530|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  399|       |	/* set the new expected length */
  400|    530|	apdu->resplen = olen;
  401|    530|	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|    530|	rv = sc_single_transmit(card, apdu);
  412|    530|	LOG_TEST_RET(ctx, rv, "cannot re-transmit APDU");
  ------------------
  |  |  174|    530|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    530|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    530|	int _ret = (r); \
  |  |  |  |  168|    530|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 527]
  |  |  |  |  ------------------
  |  |  |  |  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|    530|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 527]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  413|       |
  414|    527|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    527|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    527|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    527|	int _ret = r; \
  |  |  |  |  155|    527|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 527, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    527|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 527]
  |  |  |  |  ------------------
  |  |  |  |  157|    527|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    527|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    527|	return _ret; \
  |  |  |  |  163|    527|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|    527|}
apdu.c:sc_get_response:
  420|  56.6k|{
  421|  56.6k|	struct sc_context *ctx  = card->ctx;
  422|  56.6k|	size_t le, minlen, buflen;
  423|  56.6k|	unsigned char *buf;
  424|  56.6k|	int rv;
  425|       |
  426|  56.6k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  56.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  56.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  56.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  56.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 56.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|  56.6k|	if (apdu->le == 0) {
  ------------------
  |  Branch (427:6): [True: 10.8k, False: 45.7k]
  ------------------
  428|       |		/* no data is requested => change return value to 0x9000 and ignore the remaining data */
  429|  10.8k|		apdu->sw1 = 0x90;
  430|  10.8k|		apdu->sw2 = 0x00;
  431|  10.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.8k|#define SC_SUCCESS				0
  ------------------
  432|  10.8k|	}
  433|       |
  434|       |	/* this should _never_ happen */
  435|  45.7k|	if (!card->ops->get_response)
  ------------------
  |  Branch (435:6): [True: 121, False: 45.6k]
  ------------------
  436|  45.7k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "no GET RESPONSE command");
  ------------------
  |  |  174|    121|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    121|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    121|	int _ret = (r); \
  |  |  |  |  168|    121|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 121, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    121|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    121|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    121|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    121|		return _ret; \
  |  |  |  |  172|    121|	} \
  |  |  |  |  173|    121|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  45.6k|	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|  45.6k|	buflen = olen - apdu->resplen;
  446|       |
  447|       |	/* 0x6100 means at least 256 more bytes to read */
  448|  45.6k|	le = apdu->sw2 != 0 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (448:7): [True: 39.7k, False: 5.91k]
  ------------------
  449|       |	/* we try to read at least as much as bytes as promised in the response bytes */
  450|  45.6k|	minlen = le;
  451|       |
  452|   113k|	do {
  453|   113k|		unsigned char resp[256];
  454|   113k|		size_t resp_len = le;
  455|       |
  456|       |		/* we have all the data the caller requested even if the card has more data */
  457|   113k|		if (buflen == 0)
  ------------------
  |  Branch (457:7): [True: 11.4k, False: 101k]
  ------------------
  458|  11.4k|			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|   101k|		memset(resp, 0, sizeof(resp));
  463|   101k|		rv = card->ops->get_response(card, &resp_len, resp);
  464|   101k|		if (rv < 0)   {
  ------------------
  |  Branch (464:7): [True: 5.92k, False: 95.8k]
  ------------------
  465|  5.92k|#ifdef ENABLE_SM
  466|  5.92k|			if (resp_len)   {
  ------------------
  |  Branch (466:8): [True: 3.69k, False: 2.22k]
  ------------------
  467|  3.69k|				sc_log_hex(ctx, "SM response data", resp, resp_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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  468|  3.69k|				sc_sm_update_apdu_response(card, resp, resp_len, rv, apdu);
  469|  3.69k|			}
  470|  5.92k|#endif
  471|  5.92k|			LOG_TEST_RET(ctx, rv, "GET RESPONSE error");
  ------------------
  |  |  174|  5.92k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.92k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.92k|	int _ret = (r); \
  |  |  |  |  168|  5.92k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.92k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.92k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.92k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.92k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.92k|		return _ret; \
  |  |  |  |  172|  5.92k|	} \
  |  |  |  |  173|  5.92k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  472|  5.92k|		}
  473|       |
  474|  95.8k|		le = resp_len;
  475|       |		/* copy as much as will fit in requested buffer */
  476|  95.8k|		if (buflen < le)
  ------------------
  |  Branch (476:7): [True: 16.8k, False: 78.9k]
  ------------------
  477|  16.8k|			le = buflen;
  478|       |
  479|  95.8k|		memcpy(buf, resp, le);
  480|  95.8k|		buf    += le;
  481|  95.8k|		buflen -= le;
  482|       |
  483|  95.8k|		minlen -= le;
  484|  95.8k|		if (rv != 0)
  ------------------
  |  Branch (484:7): [True: 67.5k, False: 28.2k]
  ------------------
  485|  67.5k|			le = minlen = (size_t)rv;
  486|  28.2k|		else
  487|       |			/* if the card has returned 0x9000 but we still expect data ask for more
  488|       |			 * until we have read enough bytes */
  489|  28.2k|			le = minlen;
  490|  95.8k|	} while (rv != 0 && minlen != 0);
  ------------------
  |  Branch (490:11): [True: 67.5k, False: 28.2k]
  |  Branch (490:22): [True: 67.5k, False: 0]
  ------------------
  491|       |
  492|       |	/* we've read all data, let's return 0x9000 */
  493|  39.7k|	apdu->resplen = buf - apdu->resp;
  494|  39.7k|	apdu->sw1 = 0x90;
  495|  39.7k|	apdu->sw2 = 0x00;
  496|       |
  497|  39.7k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  39.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  39.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  39.7k|	int _ret = r; \
  |  |  |  |  155|  39.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  39.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: 39.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  39.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  39.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|  39.7k|	return _ret; \
  |  |  |  |  163|  39.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  498|  39.7k|}

sc_asn1_read_tag:
   64|   256k|{
   65|   256k|	const u8 *p = *buf;
   66|   256k|	size_t left = buflen, len;
   67|   256k|	unsigned int cla, tag, i;
   68|       |
   69|   256k|	*buf = NULL;
   70|       |
   71|   256k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (71:6): [True: 10.1k, False: 246k]
  |  Branch (71:19): [True: 0, False: 246k]
  |  Branch (71:25): [True: 0, False: 246k]
  ------------------
   72|  10.1k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  10.1k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   73|   246k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (73:6): [True: 1.39k, False: 245k]
  |  Branch (73:20): [True: 9.83k, False: 235k]
  ------------------
   74|       |		/* end of data reached */
   75|  11.2k|		*taglen = 0;
   76|  11.2k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  194|  11.2k|#define SC_ASN1_TAG_EOC			0
  ------------------
   77|  11.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  11.2k|#define SC_SUCCESS				0
  ------------------
   78|  11.2k|	}
   79|       |
   80|       |	/* parse tag byte(s)
   81|       |	 * Resulted tag is presented by integer that has not to be
   82|       |	 * confused with the 'tag number' part of ASN.1 tag.
   83|       |	 */
   84|   235k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  184|   235k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  190|   235k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   85|   235k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  191|   235k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   86|   235k|	p++;
   87|   235k|	left--;
   88|   235k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  191|   235k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (88:6): [True: 2.87k, False: 232k]
  ------------------
   89|       |		/* high tag number */
   90|  2.87k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  145|  2.87k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   91|       |		/* search the last tag octet */
   92|  4.50k|		do {
   93|  4.50k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (93:8): [True: 176, False: 4.33k]
  |  Branch (93:21): [True: 136, False: 4.19k]
  ------------------
   94|       |				/* either an invalid tag or it doesn't fit in
   95|       |				 * unsigned int */
   96|    312|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    312|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   97|  4.19k|			tag <<= 8;
   98|  4.19k|			tag |= *p;
   99|  4.19k|			p++;
  100|  4.19k|			left--;
  101|  4.19k|			n--;
  102|  4.19k|		} while (tag & 0x80);
  ------------------
  |  Branch (102:12): [True: 1.63k, False: 2.55k]
  ------------------
  103|  2.87k|	}
  104|       |
  105|       |	/* parse length byte(s) */
  106|   235k|	if (left == 0)
  ------------------
  |  Branch (106:6): [True: 1.46k, False: 233k]
  ------------------
  107|  1.46k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.46k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  108|   233k|	len = *p;
  109|   233k|	p++;
  110|   233k|	left--;
  111|   233k|	if (len & 0x80) {
  ------------------
  |  Branch (111:6): [True: 41.0k, False: 192k]
  ------------------
  112|  41.0k|		len &= 0x7f;
  113|  41.0k|		unsigned int a = 0;
  114|  41.0k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (114:7): [True: 8.22k, False: 32.8k]
  |  Branch (114:25): [True: 212, False: 32.5k]
  ------------------
  115|  8.44k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  8.44k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  116|  61.6k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (116:15): [True: 29.0k, False: 32.5k]
  ------------------
  117|  29.0k|			a <<= 8;
  118|  29.0k|			a |= *p;
  119|  29.0k|			p++;
  120|  29.0k|			left--;
  121|  29.0k|		}
  122|  32.5k|		len = a;
  123|  32.5k|	}
  124|       |
  125|   225k|	*cla_out = cla;
  126|   225k|	*tag_out = tag;
  127|   225k|	*taglen = len;
  128|   225k|	*buf = p;
  129|       |
  130|   225k|	if (len > left)
  ------------------
  |  Branch (130:6): [True: 12.4k, False: 212k]
  ------------------
  131|  12.4k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  12.4k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  132|       |
  133|   212k|	return SC_SUCCESS;
  ------------------
  |  |   28|   212k|#define SC_SUCCESS				0
  ------------------
  134|   225k|}
sc_format_asn1_entry:
  138|   196k|{
  139|   196k|	entry->parm = parm;
  140|   196k|	entry->arg  = arg;
  141|   196k|	if (set_present)
  ------------------
  |  Branch (141:6): [True: 32.3k, False: 164k]
  ------------------
  142|  32.3k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  32.3k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  143|   196k|}
sc_copy_asn1_entry:
  147|  72.7k|{
  148|   281k|	while (src->name != NULL) {
  ------------------
  |  Branch (148:9): [True: 208k, False: 72.7k]
  ------------------
  149|   208k|		*dest = *src;
  150|   208k|		dest++;
  151|   208k|		src++;
  152|   208k|	}
  153|       |	dest->name = NULL;
  154|  72.7k|}
sc_asn1_find_tag:
  482|  43.7k|{
  483|  43.7k|	size_t left = buflen, taglen;
  484|  43.7k|	const u8 *p = buf;
  485|       |
  486|  43.7k|	*taglen_in = 0;
  487|  95.4k|	while (left >= 2) {
  ------------------
  |  Branch (487:9): [True: 88.5k, False: 6.88k]
  ------------------
  488|  88.5k|		unsigned int cla = 0, tag, mask = 0xff00;
  489|       |
  490|  88.5k|		buf = p;
  491|       |		/* read a tag */
  492|  88.5k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   177k|#define SC_SUCCESS				0
  ------------------
  |  Branch (492:7): [True: 9.57k, False: 78.9k]
  ------------------
  493|  78.9k|				|| p == NULL)
  ------------------
  |  Branch (493:8): [True: 6.48k, False: 72.4k]
  ------------------
  494|  16.0k|			return NULL;
  495|       |
  496|  72.4k|		left -= (p - buf);
  497|       |		/* we need to shift the class byte to the leftmost
  498|       |		 * byte of the tag */
  499|  74.0k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (499:10): [True: 1.53k, False: 72.4k]
  ------------------
  500|  1.53k|			cla  <<= 8;
  501|  1.53k|			mask <<= 8;
  502|  1.53k|		}
  503|       |		/* compare the read tag with the given tag */
  504|  72.4k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (504:7): [True: 20.7k, False: 51.6k]
  ------------------
  505|       |			/* we have a match => return length and value part */
  506|  20.7k|			if (taglen > left)
  ------------------
  |  Branch (506:8): [True: 0, False: 20.7k]
  ------------------
  507|      0|				return NULL;
  508|  20.7k|			*taglen_in = taglen;
  509|  20.7k|			return p;
  510|  20.7k|		}
  511|       |		/* otherwise continue reading tags */
  512|  51.6k|		left -= taglen;
  513|  51.6k|		p += taglen;
  514|  51.6k|	}
  515|  6.88k|	return NULL;
  516|  43.7k|}
sc_asn1_skip_tag:
  520|   104k|{
  521|   104k|	const u8 *p = *buf;
  522|   104k|	size_t len = *buflen, taglen;
  523|   104k|	unsigned int cla = 0, tag;
  524|       |
  525|   104k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   208k|#define SC_SUCCESS				0
  ------------------
  |  Branch (525:6): [True: 17.0k, False: 86.9k]
  ------------------
  526|  86.9k|			|| p == NULL)
  ------------------
  |  Branch (526:7): [True: 1.67k, False: 85.2k]
  ------------------
  527|  18.7k|		return NULL;
  528|  85.2k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (528:10): [True: 85.2k, False: 0]
  ------------------
  529|  58.6k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  185|  58.6k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (529:2): [True: 58.6k, False: 26.5k]
  ------------------
  530|  58.6k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  136|  58.6k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  137|  58.6k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (530:7): [True: 1.77k, False: 56.9k]
  ------------------
  531|  1.77k|			return NULL;
  532|  56.9k|		break;
  533|  56.9k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  186|  19.8k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (533:2): [True: 19.8k, False: 65.4k]
  ------------------
  534|  19.8k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  136|  19.8k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  138|  19.8k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (534:7): [True: 3.57k, False: 16.2k]
  ------------------
  535|  3.57k|			return NULL;
  536|  16.2k|		break;
  537|  16.2k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  187|  5.96k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (537:2): [True: 5.96k, False: 79.2k]
  ------------------
  538|  5.96k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  136|  5.96k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  139|  5.96k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (538:7): [True: 1.36k, False: 4.60k]
  ------------------
  539|  1.36k|			return NULL;
  540|  4.60k|		break;
  541|  4.60k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  188|    752|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (541:2): [True: 752, False: 84.4k]
  ------------------
  542|    752|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  136|    752|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  140|    752|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (542:7): [True: 752, False: 0]
  ------------------
  543|    752|			return NULL;
  544|      0|		break;
  545|  85.2k|	}
  546|  77.7k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  190|  77.7k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (546:6): [True: 35.4k, False: 42.2k]
  ------------------
  547|  35.4k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  141|  35.4k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (547:7): [True: 2.45k, False: 33.0k]
  ------------------
  548|  2.45k|			return NULL;
  549|  35.4k|	} else
  550|  42.2k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  141|  42.2k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (550:7): [True: 4.52k, False: 37.7k]
  ------------------
  551|  4.52k|			return NULL;
  552|  70.8k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  144|  70.8k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (552:6): [True: 8.80k, False: 62.0k]
  ------------------
  553|  8.80k|		return NULL;
  554|  62.0k|	len -= (p - *buf);	/* header size */
  555|  62.0k|	if (taglen > len) {
  ------------------
  |  Branch (555:6): [True: 0, False: 62.0k]
  ------------------
  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|  62.0k|	*buflen -= (p - *buf) + taglen;
  561|  62.0k|	*buf = p + taglen;	/* point to next tag */
  562|  62.0k|	*taglen_out = taglen;
  563|  62.0k|	return p;
  564|  62.0k|}
sc_asn1_verify_tag:
  568|  3.72k|{
  569|  3.72k|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  570|  3.72k|}
sc_asn1_decode_integer:
  729|  2.85k|{
  730|  2.85k|	int    a = 0, is_negative = 0;
  731|  2.85k|	size_t i = 0;
  732|       |
  733|  2.85k|	if (inlen == 0) {
  ------------------
  |  Branch (733:6): [True: 19, False: 2.83k]
  ------------------
  734|     19|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     19|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  735|     19|	}
  736|  2.83k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (736:6): [True: 28, False: 2.81k]
  ------------------
  737|     28|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     28|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  738|     28|	}
  739|  2.81k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (739:6): [True: 196, False: 2.61k]
  ------------------
  740|    196|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (740:7): [True: 0, False: 196]
  |  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|    196|		is_negative = 1;
  744|    196|		a |= 0xff^(*inbuf++);
  745|    196|		i = 1;
  746|  2.61k|	} else {
  747|  2.61k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (747:7): [True: 0, False: 2.61k]
  |  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|  2.61k|	}
  751|  5.64k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (751:9): [True: 2.83k, False: 2.81k]
  ------------------
  752|  2.83k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (752:7): [True: 0, False: 2.83k]
  |  Branch (752:29): [True: 0, False: 2.83k]
  ------------------
  753|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  754|      0|		}
  755|  2.83k|		a <<= 8;
  756|  2.83k|		if (is_negative) {
  ------------------
  |  Branch (756:7): [True: 126, False: 2.70k]
  ------------------
  757|    126|			a |= 0xff^(*inbuf++);
  758|  2.70k|		} else {
  759|  2.70k|			a |= *inbuf++;
  760|  2.70k|		}
  761|  2.83k|	}
  762|  2.81k|	if (is_negative) {
  ------------------
  |  Branch (762:6): [True: 196, False: 2.61k]
  ------------------
  763|       |		/* Calculate Two's complement from previously positive number */
  764|    196|		a = (-1 * a) - 1;
  765|    196|	}
  766|  2.81k|	*out = a;
  767|  2.81k|	return 0;
  768|  2.81k|}
sc_asn1_decode_object_id:
  829|  16.8k|{
  830|  16.8k|	int large_second_octet = 0;
  831|  16.8k|	unsigned int a = 0;
  832|  16.8k|	const u8 *p = inbuf;
  833|  16.8k|	int *octet;
  834|       |
  835|  16.8k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (835:6): [True: 990, False: 15.8k]
  |  Branch (835:20): [True: 3, False: 15.8k]
  |  Branch (835:37): [True: 0, False: 15.8k]
  ------------------
  836|    993|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    993|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  837|       |
  838|  15.8k|	sc_init_oid(id);
  839|  15.8k|	octet = id->value;
  840|       |
  841|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  842|  15.8k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   70|  15.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 13.3k, False: 2.48k]
  |  |  ------------------
  ------------------
  843|  15.8k|	*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|  15.8k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (848:6): [True: 13.5k, False: 2.32k]
  ------------------
  849|  13.5k|		*octet++ = *p - (a * 40);
  850|  13.5k|		inlen--;
  851|  13.5k|	} else {
  852|  2.32k|		large_second_octet = 1;
  853|  2.32k|	}
  854|       |
  855|  74.3k|	while (inlen) {
  ------------------
  |  Branch (855:9): [True: 61.2k, False: 13.0k]
  ------------------
  856|  61.2k|		if (!large_second_octet)
  ------------------
  |  Branch (856:7): [True: 58.9k, False: 2.32k]
  ------------------
  857|  58.9k|			p++;
  858|       |		/* This signalizes empty most significant bits, which means
  859|       |		 * the unsigned integer encoding is not minimal */
  860|  61.2k|		if (*p == 0x80) {
  ------------------
  |  Branch (860:7): [True: 994, False: 60.2k]
  ------------------
  861|    994|			sc_init_oid(id);
  862|    994|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    994|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  863|    994|		}
  864|       |		/* Use unsigned type here so we can process the whole INT range.
  865|       |		 * Values can not be negative */
  866|  60.2k|		a = *p & 0x7F;
  867|  60.2k|		inlen--;
  868|  88.5k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (868:10): [True: 76.5k, False: 11.9k]
  |  Branch (868:19): [True: 28.6k, False: 47.8k]
  ------------------
  869|       |			/* Limit the OID values to int size and do not overflow */
  870|  28.6k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (870:8): [True: 386, False: 28.3k]
  ------------------
  871|    386|				sc_init_oid(id);
  872|    386|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    386|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  873|    386|			}
  874|  28.3k|			p++;
  875|  28.3k|			a <<= 7;
  876|  28.3k|			a |= *p & 0x7F;
  877|  28.3k|			inlen--;
  878|  28.3k|		}
  879|  59.8k|		if (*p & 0x80) {
  ------------------
  |  Branch (879:7): [True: 981, False: 58.8k]
  ------------------
  880|       |			/* We dropped out from previous cycle on the end of
  881|       |			 * data while still expecting continuation of value */
  882|    981|			sc_init_oid(id);
  883|    981|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    981|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  884|    981|		}
  885|  58.8k|		if (large_second_octet) {
  ------------------
  |  Branch (885:7): [True: 921, False: 57.9k]
  ------------------
  886|    921|			a -= (2 * 40);
  887|    921|		}
  888|  58.8k|		if (a > INT_MAX) {
  ------------------
  |  Branch (888:7): [True: 219, False: 58.6k]
  ------------------
  889|    219|			sc_init_oid(id);
  890|    219|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    219|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  891|    219|		}
  892|  58.6k|		*octet++ = a;
  893|  58.6k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  58.6k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (893:7): [True: 230, False: 58.4k]
  ------------------
  894|    230|			sc_init_oid(id);
  895|    230|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    230|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  896|    230|		}
  897|  58.4k|		large_second_octet = 0;
  898|  58.4k|	}
  899|       |
  900|  13.0k|	return 0;
  901|  15.8k|}
sc_asn1_encode_object_id:
  905|  6.08k|{
  906|  6.08k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  907|  6.08k|	int	i;
  908|       |
  909|  6.08k|	if (!buflen || !id)
  ------------------
  |  Branch (909:6): [True: 0, False: 6.08k]
  |  Branch (909:17): [True: 0, False: 6.08k]
  ------------------
  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|  6.08k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (913:6): [True: 0, False: 6.08k]
  |  Branch (913:28): [True: 0, False: 6.08k]
  ------------------
  914|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  915|       |
  916|  43.5k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|  43.5k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (916:14): [True: 43.5k, False: 0]
  ------------------
  917|  43.5k|		unsigned int k, shift;
  918|       |
  919|  43.5k|		if (id->value[i] == -1)
  ------------------
  |  Branch (919:7): [True: 6.08k, False: 37.4k]
  ------------------
  920|  6.08k|			break;
  921|       |
  922|  37.4k|		k = id->value[i];
  923|  37.4k|		switch (i) {
  924|  6.08k|		case 0:
  ------------------
  |  Branch (924:3): [True: 6.08k, False: 31.3k]
  ------------------
  925|  6.08k|			if (k > 2)
  ------------------
  |  Branch (925:8): [True: 0, False: 6.08k]
  ------------------
  926|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  927|  6.08k|			*p = k * 40;
  928|  6.08k|			break;
  929|  6.08k|		case 1:
  ------------------
  |  Branch (929:3): [True: 6.08k, False: 31.3k]
  ------------------
  930|  6.08k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (930:8): [True: 0, False: 6.08k]
  |  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|  6.08k|			k += *p;
  936|       |			/* fall through */
  937|  31.3k|		default:
  ------------------
  |  Branch (937:3): [True: 25.2k, False: 12.1k]
  ------------------
  938|  31.3k|			shift = 28;
  939|   146k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (939:11): [True: 125k, False: 21.3k]
  |  Branch (939:20): [True: 115k, False: 9.99k]
  ------------------
  940|   115k|				shift -= 7;
  941|  41.5k|			while (shift) {
  ------------------
  |  Branch (941:11): [True: 10.1k, False: 31.3k]
  ------------------
  942|  10.1k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  943|  10.1k|				shift -= 7;
  944|  10.1k|			}
  945|  31.3k|			*p++ = k & 0x7F;
  946|  31.3k|			break;
  947|  37.4k|		}
  948|  37.4k|	}
  949|       |
  950|  6.08k|	*buflen = p - temp;
  951|       |
  952|  6.08k|	if (buf)   {
  ------------------
  |  Branch (952:6): [True: 6.08k, False: 0]
  ------------------
  953|  6.08k|		*buf = malloc(*buflen);
  954|  6.08k|		if (!*buf)
  ------------------
  |  Branch (954:7): [True: 0, False: 6.08k]
  ------------------
  955|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  956|  6.08k|		memcpy(*buf, temp, *buflen);
  957|  6.08k|	}
  958|  6.08k|	return 0;
  959|  6.08k|}
sc_asn1_put_tag:
  976|  11.6k|{
  977|  11.6k|	size_t c = 0;
  978|  11.6k|	unsigned int tag_len, ii;
  979|  11.6k|	u8 *p = out;
  980|  11.6k|	u8 tag_char[4] = {0, 0, 0, 0};
  981|       |
  982|       |	/* Check tag */
  983|  11.6k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (983:6): [True: 0, False: 11.6k]
  |  Branch (983:18): [True: 0, False: 11.6k]
  ------------------
  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|  23.3k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (987:20): [True: 11.6k, False: 11.6k]
  ------------------
  988|       |		/* Note: tag char will be reversed order. */
  989|  11.6k|		tag_char[tag_len++] = tag & 0xFF;
  990|  11.6k|	}
  991|       |
  992|  11.6k|	if (tag_len > 1)   {
  ------------------
  |  Branch (992:6): [True: 0, False: 11.6k]
  ------------------
  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|  11.6k|	if (datalen > 127) {
  ------------------
  |  Branch (1011:6): [True: 0, False: 11.6k]
  ------------------
 1012|      0|		c = 1;
 1013|      0|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1013:10): [True: 0, False: 0]
  ------------------
 1014|      0|			c++;
 1015|      0|	}
 1016|  11.6k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1016:6): [True: 48, False: 11.6k]
  |  Branch (1016:21): [True: 0, False: 11.6k]
  ------------------
 1017|       |		/* Caller only asks for the length that would be written. */
 1018|     48|		return (int)(tag_len + (c + 1) + datalen);
 1019|     48|	}
 1020|       |	/* We will write the tag, so check the length. */
 1021|  11.6k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1021:6): [True: 0, False: 11.6k]
  ------------------
 1022|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1023|  23.2k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1023:12): [True: 11.6k, False: 11.6k]
  ------------------
 1024|  11.6k|		*p++ = tag_char[tag_len - ii - 1];
 1025|       |
 1026|  11.6k|	if (c > 0) {
  ------------------
  |  Branch (1026:6): [True: 0, False: 11.6k]
  ------------------
 1027|      0|		*p++ = 0x80 | c;
 1028|      0|		while (c--)
  ------------------
  |  Branch (1028:10): [True: 0, False: 0]
  ------------------
 1029|      0|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1030|      0|	}
 1031|  11.6k|	else {
 1032|  11.6k|		*p++ = datalen & 0x7F;
 1033|  11.6k|	}
 1034|  11.6k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1034:5): [True: 11.5k, False: 48]
  |  Branch (1034:13): [True: 11.5k, False: 0]
  ------------------
 1035|  11.5k|		memcpy(p, data, datalen);
 1036|  11.5k|		p += datalen;
 1037|  11.5k|	}
 1038|  11.6k|	if (ptr != NULL)
  ------------------
  |  Branch (1038:6): [True: 11.6k, False: 0]
  ------------------
 1039|  11.6k|		*ptr = p;
 1040|  11.6k|	return 0;
 1041|  11.6k|}
sc_asn1_decode:
 1814|  20.5k|{
 1815|  20.5k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1816|  20.5k|}
sc_asn1_decode_choice:
 1820|  4.27k|{
 1821|  4.27k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1822|  4.27k|}
sc_asn1_encode:
 2082|  14.8k|{
 2083|  14.8k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2084|  14.8k|}
_sc_asn1_encode:
 2088|  6.08k|{
 2089|  6.08k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2090|  6.08k|}
_sc_asn1_decode:
 2096|  6.69k|{
 2097|  6.69k|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2098|  6.69k|}
sc_der_copy:
 2102|  3.45k|{
 2103|  3.45k|	if (!dst || !src)
  ------------------
  |  Branch (2103:6): [True: 0, False: 3.45k]
  |  Branch (2103:14): [True: 0, False: 3.45k]
  ------------------
 2104|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2105|  3.45k|	memset(dst, 0, sizeof(*dst));
 2106|  3.45k|	if (src->len) {
  ------------------
  |  Branch (2106:6): [True: 3.22k, False: 231]
  ------------------
 2107|  3.22k|		if (!src->value)
  ------------------
  |  Branch (2107:7): [True: 0, False: 3.22k]
  ------------------
 2108|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2109|  3.22k|		dst->value = malloc(src->len);
 2110|  3.22k|		if (!dst->value)
  ------------------
  |  Branch (2110:7): [True: 0, False: 3.22k]
  ------------------
 2111|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2112|  3.22k|		dst->len = src->len;
 2113|  3.22k|		memcpy(dst->value, src->value, src->len);
 2114|  3.22k|	}
 2115|  3.45k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.45k|#define SC_SUCCESS				0
  ------------------
 2116|  3.45k|}
sc_encode_oid:
 2121|  3.01k|{
 2122|  3.01k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2123|  3.01k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  159|  3.01k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  200|  3.01k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.01k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2124|  3.01k|		{ NULL, 0, 0, 0, NULL, NULL }
 2125|  3.01k|	};
 2126|  3.01k|	struct sc_asn1_entry asn1_object_id[2];
 2127|  3.01k|	int rv;
 2128|       |
 2129|  3.01k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2130|  3.01k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2131|       |
 2132|  3.01k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2133|  3.01k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|  3.01k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.01k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.01k|	int _ret = (r); \
  |  |  |  |  168|  3.01k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 3.01k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  3.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2134|       |
 2135|  3.01k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.01k|#define SC_SUCCESS				0
  ------------------
 2136|  3.01k|}
sc_asn1_sig_value_rs_to_sequence:
 2156|     23|{
 2157|     23|	struct sc_asn1_entry asn1_sig_value[C_ASN1_SIG_VALUE_SIZE];
 2158|     23|	struct sc_asn1_entry asn1_sig_value_coefficients[C_ASN1_SIG_VALUE_COEFFICIENTS_SIZE];
 2159|     23|	unsigned char *r = in, *s = in + inlen/2;
 2160|     23|	size_t r_len = inlen/2, s_len = inlen/2;
 2161|     23|	int rv;
 2162|       |
 2163|     23|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     23|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     23|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     23|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     23|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2164|       |
 2165|       |	/* R/S are filled up with zeroes, we do not want that in sequence format */
 2166|    172|	while(r_len > 1 && *r == 0x00) {
  ------------------
  |  Branch (2166:8): [True: 167, False: 5]
  |  Branch (2166:21): [True: 149, False: 18]
  ------------------
 2167|    149|		r++;
 2168|    149|		r_len--;
 2169|    149|	}
 2170|    292|	while(s_len > 1 && *s == 0x00) {
  ------------------
  |  Branch (2170:8): [True: 286, False: 6]
  |  Branch (2170:21): [True: 269, False: 17]
  ------------------
 2171|    269|		s++;
 2172|    269|		s_len--;
 2173|    269|	}
 2174|       |
 2175|     23|	sc_copy_asn1_entry(c_asn1_sig_value, asn1_sig_value);
 2176|     23|	sc_format_asn1_entry(asn1_sig_value + 0, asn1_sig_value_coefficients, NULL, 1);
 2177|       |
 2178|     23|	sc_copy_asn1_entry(c_asn1_sig_value_coefficients, asn1_sig_value_coefficients);
 2179|     23|	sc_format_asn1_entry(asn1_sig_value_coefficients + 0, r, &r_len, 1);
 2180|     23|	sc_format_asn1_entry(asn1_sig_value_coefficients + 1, s, &s_len, 1);
 2181|       |
 2182|     23|	rv = sc_asn1_encode(ctx, asn1_sig_value, buf, buflen);
 2183|     23|	LOG_TEST_RET(ctx, rv, "ASN.1 encoding ECDSA-SIg-Value failed");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2184|       |
 2185|     20|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2186|     20|}
sc_asn1_decode_ecdsa_signature:
 2235|     12|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|     12|	int i, r;
 2237|     12|	const unsigned char *pseq, *pint, *pend;
 2238|     12|	unsigned int cla, tag;
 2239|     12|	size_t seqlen, intlen;
 2240|       |
 2241|     12|	if (!ctx || !data || !out || !(*out)) {
  ------------------
  |  Branch (2241:6): [True: 0, False: 12]
  |  Branch (2241:14): [True: 0, False: 12]
  |  Branch (2241:23): [True: 0, False: 12]
  |  Branch (2241:31): [True: 0, False: 12]
  ------------------
 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|     12|	if (outlen < 2 * fieldsize) {
  ------------------
  |  Branch (2244:6): [True: 0, False: 12]
  ------------------
 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|     12|	memset(*out, 0, outlen);
 2249|       |
 2250|     12|	pseq = data;
 2251|     12|	r = sc_asn1_read_tag(&pseq, datalen, &cla, &tag, &seqlen);
 2252|     12|	if (pseq == NULL || r < 0 || seqlen == 0 || (cla | tag) != 0x30)
  ------------------
  |  Branch (2252:6): [True: 9, False: 3]
  |  Branch (2252:22): [True: 1, False: 2]
  |  Branch (2252:31): [True: 1, False: 1]
  |  Branch (2252:46): [True: 1, False: 0]
  ------------------
 2253|     12|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x30 tag");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|  2.49k|{
  575|  2.49k|	const u8 *in = inbuf;
  576|  2.49k|	u8 *out = (u8 *) outbuf;
  577|  2.49k|	int i, count = 0;
  578|  2.49k|	int zero_bits;
  579|  2.49k|	size_t octets_left;
  580|       |
  581|  2.49k|	if (inlen < 1)
  ------------------
  |  Branch (581:6): [True: 2, False: 2.48k]
  ------------------
  582|      2|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#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|  2.48k|	if (strict) {
  ------------------
  |  Branch (586:6): [True: 0, False: 2.48k]
  ------------------
  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|  2.48k|	memset(outbuf, 0, outlen);
  597|  2.48k|	zero_bits = *in & 0x07;
  598|  2.48k|	in++;
  599|  2.48k|	octets_left = inlen - 1;
  600|  2.48k|	if (outlen < octets_left)
  ------------------
  |  Branch (600:6): [True: 1, False: 2.48k]
  ------------------
  601|      1|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  602|       |
  603|   154k|	while (octets_left) {
  ------------------
  |  Branch (603:9): [True: 152k, False: 2.46k]
  ------------------
  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|   152k|		int bits_to_go;
  608|       |
  609|   152k|		*out = 0;
  610|   152k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (610:7): [True: 2.33k, False: 149k]
  |  Branch (610:27): [True: 1.92k, False: 410]
  ------------------
  611|  1.92k|			bits_to_go = 8 - zero_bits;
  612|       |			/* Verify the padding is zero bits */
  613|  1.92k|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (613:8): [True: 20, False: 1.90k]
  ------------------
  614|     20|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     20|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  615|     20|			}
  616|  1.92k|		} else
  617|   150k|			bits_to_go = 8;
  618|   152k|		if (invert)
  ------------------
  |  Branch (618:7): [True: 14, False: 151k]
  ------------------
  619|     97|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (619:16): [True: 83, False: 14]
  ------------------
  620|     83|				*out |= ((*in >> (7 - i)) & 1) << i;
  621|     83|			}
  622|   151k|		else {
  623|   151k|			*out = *in;
  624|   151k|		}
  625|   152k|		out++;
  626|   152k|		in++;
  627|   152k|		octets_left--;
  628|   152k|		count++;
  629|   152k|	}
  630|  2.46k|	return (count * 8) - zero_bits;
  631|  2.48k|}
asn1.c:asn1_write_element:
 1051|  23.5k|{
 1052|  23.5k|	unsigned char t;
 1053|  23.5k|	unsigned char *buf, *p;
 1054|  23.5k|	int c = 0;
 1055|  23.5k|	unsigned short_tag;
 1056|  23.5k|	unsigned char tag_char[3] = {0, 0, 0};
 1057|  23.5k|	size_t tag_len, ii;
 1058|       |
 1059|  23.5k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  144|  23.5k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1060|  47.1k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1060:20): [True: 23.5k, False: 23.5k]
  ------------------
 1061|  23.5k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1062|  23.5k|	if (!tag_len)
  ------------------
  |  Branch (1062:6): [True: 0, False: 23.5k]
  ------------------
 1063|      0|		tag_len = 1;
 1064|       |
 1065|  23.5k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1065:6): [True: 0, False: 23.5k]
  ------------------
 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|  23.5k|	t = tag_char[tag_len - 1] & 0x1F;
 1078|       |
 1079|  23.5k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  136|  23.5k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1079:10): [True: 23.5k, False: 0]
  ------------------
 1080|  16.3k|	case SC_ASN1_UNI:
  ------------------
  |  |  137|  16.3k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1080:2): [True: 16.3k, False: 7.21k]
  ------------------
 1081|  16.3k|		break;
 1082|  7.21k|	case SC_ASN1_APP:
  ------------------
  |  |  138|  7.21k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1082:2): [True: 7.21k, False: 16.3k]
  ------------------
 1083|  7.21k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  186|  7.21k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1084|  7.21k|		break;
 1085|      0|	case SC_ASN1_CTX:
  ------------------
  |  |  139|      0|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1085:2): [True: 0, False: 23.5k]
  ------------------
 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: 23.5k]
  ------------------
 1089|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  188|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1090|      0|		break;
 1091|  23.5k|	}
 1092|  23.5k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  141|  23.5k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1092:6): [True: 6.48k, False: 17.0k]
  ------------------
 1093|  6.48k|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  190|  6.48k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1094|  23.5k|	if (datalen > 127) {
  ------------------
  |  Branch (1094:6): [True: 356, False: 23.2k]
  ------------------
 1095|    356|		c = 1;
 1096|    395|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1096:10): [True: 39, False: 356]
  ------------------
 1097|     39|			c++;
 1098|    356|	}
 1099|       |
 1100|  23.5k|	*outlen = tag_len + 1 + c + datalen;
 1101|  23.5k|	buf = malloc(*outlen);
 1102|  23.5k|	if (buf == NULL)
  ------------------
  |  Branch (1102:6): [True: 0, False: 23.5k]
  ------------------
 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|  23.5k|	*out = p = buf;
 1106|  23.5k|	*p++ = t;
 1107|  23.5k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1107:12): [True: 0, False: 23.5k]
  ------------------
 1108|      0|		*p++ = tag_char[tag_len - ii - 1];
 1109|       |
 1110|  23.5k|	if (c) {
  ------------------
  |  Branch (1110:6): [True: 356, False: 23.2k]
  ------------------
 1111|    356|		*p++ = 0x80 | c;
 1112|    751|		while (c--)
  ------------------
  |  Branch (1112:10): [True: 395, False: 356]
  ------------------
 1113|    395|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1114|    356|	}
 1115|  23.2k|	else   {
 1116|  23.2k|		*p++ = datalen & 0x7F;
 1117|  23.2k|	}
 1118|  23.5k|	if (datalen && data) {
  ------------------
  |  Branch (1118:6): [True: 23.3k, False: 195]
  |  Branch (1118:17): [True: 23.3k, False: 0]
  ------------------
 1119|  23.3k|		memcpy(p, data, datalen);
 1120|  23.3k|	}
 1121|       |
 1122|  23.5k|	return SC_SUCCESS;
  ------------------
  |  |   28|  23.5k|#define SC_SUCCESS				0
  ------------------
 1123|  23.5k|}
asn1.c:asn1_decode:
 1723|  41.4k|{
 1724|  41.4k|	int r, idx = 0;
 1725|  41.4k|	const u8 *p = in, *obj;
 1726|  41.4k|	struct sc_asn1_entry *entry = asn1;
 1727|  41.4k|	size_t left = len, objlen;
 1728|       |
 1729|  41.4k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*s""called, left=%zu, depth %d%s",
  ------------------
  |  |   70|  82.8k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 4.28k, False: 37.1k]
  |  |  ------------------
  ------------------
 1730|  41.4k|			depth, depth, "", left, depth, choice ? ", choice" : "");
 1731|       |
 1732|  41.4k|	if (!p)
  ------------------
  |  Branch (1732:6): [True: 1, False: 41.4k]
  ------------------
 1733|      1|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      1|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1734|  41.4k|	if (left < 2) {
  ------------------
  |  Branch (1734:6): [True: 2.46k, False: 38.9k]
  ------------------
 1735|  5.64k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|  4.22k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1735:10): [True: 4.22k, False: 1.41k]
  |  Branch (1735:24): [True: 3.17k, False: 1.05k]
  ------------------
 1736|  3.17k|			asn1++;
 1737|       |		/* If all elements were optional, there's nothing
 1738|       |		 * to complain about */
 1739|  2.46k|		if (asn1->name == NULL)
  ------------------
  |  Branch (1739:7): [True: 1.41k, False: 1.05k]
  ------------------
 1740|  1.41k|			return 0;
 1741|  1.05k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|  1.05k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1742|  1.05k|			      "non-optional field \"%s\" not found\n",
 1743|  1.05k|			      asn1->name);
 1744|  1.05k|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|  1.05k|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1745|  2.46k|	}
 1746|  38.9k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1746:6): [True: 1.17k, False: 37.7k]
  |  Branch (1746:19): [True: 114, False: 37.6k]
  |  Branch (1746:35): [True: 0, False: 37.6k]
  ------------------
 1747|  1.28k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  1.28k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1748|       |
 1749|   125k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1749:16): [True: 97.0k, False: 28.8k]
  ------------------
 1750|  97.0k|		entry = &asn1[idx];
 1751|       |
 1752|  97.0k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|  97.0k|#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|  97.0k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1754|  97.0k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|  97.0k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1753|  97.0k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1754|  97.0k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1755|       |
 1756|       |		/* Special case CHOICE has no tag */
 1757|  97.0k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  97.0k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1757:7): [True: 11, False: 97.0k]
  ------------------
 1758|     11|			r = asn1_decode(ctx,
 1759|     11|				(struct sc_asn1_entry *) entry->parm,
 1760|     11|				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|     11|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|     11|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1766:8): [True: 0, False: 11]
  |  Branch (1766:18): [True: 0, False: 11]
  ------------------
 1767|      0|				r = 0;
 1768|     11|			goto decode_ok;
 1769|     11|		}
 1770|       |
 1771|  97.0k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1772|  97.0k|		if (obj == NULL) {
  ------------------
  |  Branch (1772:7): [True: 39.9k, False: 57.1k]
  ------------------
 1773|  39.9k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  39.9k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1774|  39.9k|			if (choice)
  ------------------
  |  Branch (1774:8): [True: 4.66k, False: 35.2k]
  ------------------
 1775|  4.66k|				continue;
 1776|  35.2k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  148|  35.2k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1776:8): [True: 31.7k, False: 3.53k]
  ------------------
 1777|  31.7k|				continue;
 1778|  3.53k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  3.53k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1779|  3.53k|			if (left) {
  ------------------
  |  Branch (1779:8): [True: 3.41k, False: 117]
  ------------------
 1780|  3.41k|				u8 line[128], *linep = line;
 1781|  3.41k|				size_t i;
 1782|       |
 1783|  3.41k|				line[0] = 0;
 1784|  34.6k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1784:17): [True: 31.8k, False: 2.83k]
  |  Branch (1784:27): [True: 31.2k, False: 582]
  ------------------
 1785|  31.2k|					sprintf((char *) linep, "%02X ", p[i]);
 1786|  31.2k|					linep += 3;
 1787|  31.2k|				}
 1788|  3.41k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  3.41k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1789|  3.41k|			}
 1790|  3.53k|			sc_free_entry(asn1);
 1791|  3.53k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  3.53k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.53k|	int _ret = r; \
  |  |  155|  3.53k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.53k, False: 0]
  |  |  ------------------
  |  |  156|  3.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|  3.53k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.53k, False: 0]
  |  |  ------------------
  |  |  157|  3.53k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.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|  3.53k|	return _ret; \
  |  |  163|  3.53k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1792|  3.53k|		}
 1793|  57.1k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1794|       |
 1795|  57.1k|decode_ok:
 1796|  57.1k|		if (r)
  ------------------
  |  Branch (1796:7): [True: 1.14k, False: 55.9k]
  ------------------
 1797|  1.14k|			return r;
 1798|  55.9k|		if (choice)
  ------------------
  |  Branch (1798:7): [True: 4.17k, False: 51.8k]
  ------------------
 1799|  4.17k|			break;
 1800|  55.9k| 	}
 1801|  32.9k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1801:7): [True: 4.22k, False: 28.7k]
  |  Branch (1801:17): [True: 51, False: 4.17k]
  ------------------
 1802|     51|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     51|	int _ret = r; \
  |  |  155|     51|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 51, False: 0]
  |  |  ------------------
  |  |  156|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 51, False: 0]
  |  |  ------------------
  |  |  157|     51|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     51|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     51|	return _ret; \
  |  |  163|     51|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1803|  32.9k| 	if (newp != NULL)
  ------------------
  |  Branch (1803:7): [True: 10.5k, False: 22.3k]
  ------------------
 1804|  10.5k|		*newp = p;
 1805|  32.9k| 	if (len_left != NULL)
  ------------------
  |  Branch (1805:7): [True: 10.5k, False: 22.3k]
  ------------------
 1806|  10.5k|		*len_left = left;
 1807|  32.9k|	if (choice)
  ------------------
  |  Branch (1807:6): [True: 4.17k, False: 28.7k]
  ------------------
 1808|  4.17k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  153|  4.17k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  4.17k|	int _ret = r; \
  |  |  155|  4.17k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 47, False: 4.12k]
  |  |  ------------------
  |  |  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|  4.12k|	} else { \
  |  |  159|  4.12k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  4.12k|			"returning with: %d\n", _ret); \
  |  |  161|  4.12k|	} \
  |  |  162|  4.17k|	return _ret; \
  |  |  163|  4.17k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1809|  28.7k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  153|  28.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  28.7k|	int _ret = r; \
  |  |  155|  28.7k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 28.7k, False: 0]
  |  |  ------------------
  |  |  156|  28.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: 28.7k]
  |  |  ------------------
  |  |  157|  28.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  28.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|  28.7k|	return _ret; \
  |  |  163|  28.7k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1810|  28.7k|}
asn1.c:sc_free_entry:
 1688|  13.3k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1689|  13.3k|	int idx = 0;
 1690|  13.3k|	struct sc_asn1_entry *entry = asn1;
 1691|       |
 1692|  13.3k|	if (!asn1)
  ------------------
  |  Branch (1692:6): [True: 496, False: 12.8k]
  ------------------
 1693|    496|		return;
 1694|       |
 1695|  62.1k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1695:16): [True: 49.3k, False: 12.8k]
  ------------------
 1696|  49.3k|		entry = &asn1[idx];
 1697|  49.3k|		switch (entry->type) {
 1698|  3.53k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  170|  3.53k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1698:3): [True: 3.53k, False: 45.8k]
  ------------------
 1699|  9.77k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  9.77k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1699:3): [True: 6.23k, False: 43.1k]
  ------------------
 1700|  9.77k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1701|  9.77k|			break;
 1702|  10.2k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  10.2k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1702:3): [True: 10.2k, False: 39.0k]
  ------------------
 1703|  10.3k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  10.3k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1703:3): [True: 46, False: 49.3k]
  ------------------
 1704|  10.3k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  10.3k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1704:3): [True: 62, False: 49.2k]
  ------------------
 1705|  10.6k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|  10.6k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1705:3): [True: 223, False: 49.1k]
  ------------------
 1706|  10.9k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|  10.9k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1706:3): [True: 342, False: 49.0k]
  ------------------
 1707|  12.8k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  12.8k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1707:3): [True: 1.87k, False: 47.4k]
  ------------------
 1708|  12.8k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  149|  12.8k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  1.09k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1708:8): [True: 1.09k, False: 11.7k]
  |  Branch (1708:42): [True: 238, False: 852]
  ------------------
 1709|    238|				u8 **buf = (u8 **)entry->parm;
 1710|    238|				free(*buf);
 1711|    238|				*buf = NULL;
 1712|    238|			}
 1713|  12.8k|			break;
 1714|  26.7k|		default:
  ------------------
  |  Branch (1714:3): [True: 26.7k, False: 22.5k]
  ------------------
 1715|  26.7k|			break;
 1716|  49.3k|		}
 1717|  49.3k|	}
 1718|  12.8k|}
asn1.c:asn1_decode_entry:
 1486|  57.1k|{
 1487|  57.1k|	void *parm = entry->parm;
 1488|  57.1k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1489|  57.1k|			     size_t nobjlen, int ndepth);
 1490|  57.1k|	size_t *len = (size_t *) entry->arg;
 1491|  57.1k|	int r = 0;
 1492|       |
 1493|  57.1k|	callback_func = parm;
 1494|       |
 1495|  57.1k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|   228k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 21.2k, False: 35.8k]
  |  |  |  Branch (70:115): [True: 21.2k, False: 35.8k]
  |  |  ------------------
  ------------------
 1496|  57.1k|		depth, depth, "", entry->name,
 1497|  57.1k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1498|  57.1k|		objlen > 16 ? "..." : "");
 1499|       |
 1500|  57.1k|	switch (entry->type) {
 1501|  14.5k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  14.5k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1501:2): [True: 14.5k, False: 42.5k]
  ------------------
 1502|  14.5k|		if (parm != NULL)
  ------------------
  |  Branch (1502:7): [True: 9.50k, False: 5.05k]
  ------------------
 1503|  9.50k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1504|  9.50k|				       objlen, NULL, NULL, 0, depth + 1);
 1505|  14.5k|		break;
 1506|    422|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    422|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1506:2): [True: 422, False: 56.6k]
  ------------------
 1507|    422|		break;
 1508|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1508:2): [True: 0, False: 57.1k]
  ------------------
 1509|      0|		if (parm != NULL) {
  ------------------
  |  Branch (1509:7): [True: 0, False: 0]
  ------------------
 1510|      0|			if (objlen != 1) {
  ------------------
  |  Branch (1510:8): [True: 0, False: 0]
  ------------------
 1511|      0|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 object length: %zu", objlen);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1512|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1513|      0|			} else
 1514|      0|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1514:23): [True: 0, False: 0]
  ------------------
 1515|      0|		}
 1516|      0|		break;
 1517|  2.85k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  2.85k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1517:2): [True: 2.85k, False: 54.2k]
  ------------------
 1518|  2.85k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  2.85k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1518:2): [True: 0, False: 57.1k]
  ------------------
 1519|  2.85k|		if (parm != NULL) {
  ------------------
  |  Branch (1519:7): [True: 2.85k, False: 0]
  ------------------
 1520|  2.85k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1521|  2.85k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.85k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1521:8): [True: 2.81k, False: 47]
  ------------------
 1522|  2.81k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  2.81k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1523|  2.81k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1524|  2.81k|			}
 1525|  2.85k|		}
 1526|  2.85k|		break;
 1527|  2.37k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  2.37k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1527:2): [True: 2.37k, False: 54.7k]
  ------------------
 1528|  4.54k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  4.54k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1528:2): [True: 2.17k, False: 54.9k]
  ------------------
 1529|  4.54k|		if (parm != NULL) {
  ------------------
  |  Branch (1529:7): [True: 2.37k, False: 2.17k]
  ------------------
 1530|  2.37k|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  155|  2.37k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1530:17): [True: 0, False: 2.37k]
  ------------------
 1531|  2.37k|			if (len == NULL)
  ------------------
  |  Branch (1531:8): [True: 0, False: 2.37k]
  ------------------
 1532|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1533|  2.37k|			if (objlen < 1) {
  ------------------
  |  Branch (1533:8): [True: 16, False: 2.35k]
  ------------------
 1534|     16|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     16|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1535|     16|				break;
 1536|     16|			}
 1537|  2.35k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  2.35k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1537:8): [True: 2.35k, False: 0]
  ------------------
 1538|  2.35k|				u8 **buf = (u8 **) parm;
 1539|  2.35k|				if (objlen > 1) {
  ------------------
  |  Branch (1539:9): [True: 2.32k, False: 28]
  ------------------
 1540|  2.32k|					*buf = malloc(objlen-1);
 1541|  2.32k|					if (*buf == NULL) {
  ------------------
  |  Branch (1541:10): [True: 0, False: 2.32k]
  ------------------
 1542|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1543|      0|						break;
 1544|      0|					}
 1545|  2.32k|				} else {
 1546|     28|					*buf = NULL;
 1547|     28|				}
 1548|  2.35k|				*len = objlen-1;
 1549|  2.35k|				parm = *buf;
 1550|  2.35k|			}
 1551|  2.35k|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1552|  2.35k|			if (r >= 0) {
  ------------------
  |  Branch (1552:8): [True: 2.32k, False: 32]
  ------------------
 1553|  2.32k|				*len = r;
 1554|  2.32k|				r = 0;
 1555|  2.32k|			}
 1556|  2.35k|		}
 1557|  4.52k|		break;
 1558|  4.52k|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|    136|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1558:2): [True: 136, False: 56.9k]
  ------------------
 1559|    136|		if (parm != NULL)
  ------------------
  |  Branch (1559:7): [True: 136, False: 0]
  ------------------
 1560|    136|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1561|    136|		break;
 1562|  16.1k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  16.1k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1562:2): [True: 16.1k, False: 41.0k]
  ------------------
 1563|  16.1k|		if (parm != NULL) {
  ------------------
  |  Branch (1563:7): [True: 16.0k, False: 67]
  ------------------
 1564|  16.0k|			size_t c;
 1565|  16.0k|			if (len == NULL)
  ------------------
  |  Branch (1565:8): [True: 0, False: 16.0k]
  ------------------
 1566|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1567|       |
 1568|       |			/* Strip off padding zero */
 1569|  16.0k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  16.0k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1569:8): [True: 2.62k, False: 13.4k]
  ------------------
 1570|  2.62k|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1570:9): [True: 2.56k, False: 66]
  |  Branch (1570:23): [True: 1.55k, False: 1.00k]
  ------------------
 1571|  1.55k|				objlen--;
 1572|  1.55k|				obj++;
 1573|  1.55k|			}
 1574|       |
 1575|       |			/* Allocate buffer if needed */
 1576|  16.0k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  16.0k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1576:8): [True: 10.1k, False: 5.84k]
  ------------------
 1577|  10.1k|				u8 **buf = (u8 **) parm;
 1578|  10.1k|				if (objlen > 0) {
  ------------------
  |  Branch (1578:9): [True: 10.0k, False: 140]
  ------------------
 1579|  10.0k|					*buf = malloc(objlen);
 1580|  10.0k|					if (*buf == NULL) {
  ------------------
  |  Branch (1580:10): [True: 0, False: 10.0k]
  ------------------
 1581|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1582|      0|						break;
 1583|      0|					}
 1584|  10.0k|				} else {
 1585|    140|					*buf = NULL;
 1586|    140|				}
 1587|  10.1k|				c = *len = objlen;
 1588|  10.1k|				parm = *buf;
 1589|  10.1k|			} else
 1590|  5.84k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1590:9): [True: 281, False: 5.56k]
  ------------------
 1591|       |
 1592|  16.0k|			memcpy(parm, obj, c);
 1593|  16.0k|			*len = c;
 1594|  16.0k|		}
 1595|  16.1k|		break;
 1596|  16.1k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1596:2): [True: 0, False: 57.1k]
  ------------------
 1597|      0|		if (parm != NULL) {
  ------------------
  |  Branch (1597:7): [True: 0, False: 0]
  ------------------
 1598|      0|			size_t c;
 1599|      0|			if (len == NULL)
  ------------------
  |  Branch (1599:8): [True: 0, False: 0]
  ------------------
 1600|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1601|      0|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|      0|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1601:8): [True: 0, False: 0]
  ------------------
 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|      0|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1615:9): [True: 0, False: 0]
  ------------------
 1616|       |
 1617|      0|			memcpy(parm, obj, c);
 1618|      0|			*len = c;
 1619|      0|		}
 1620|      0|		break;
 1621|  10.7k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  10.7k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1621:2): [True: 10.7k, False: 46.3k]
  ------------------
 1622|  10.7k|		if (parm != NULL)
  ------------------
  |  Branch (1622:7): [True: 10.7k, False: 55]
  ------------------
 1623|  10.7k|			r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *) parm);
 1624|  10.7k|		break;
 1625|      3|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      3|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1625:2): [True: 3, False: 57.1k]
  ------------------
 1626|     98|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|     98|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1626:2): [True: 95, False: 57.0k]
  ------------------
 1627|     98|		if (parm != NULL) {
  ------------------
  |  Branch (1627:7): [True: 97, False: 1]
  ------------------
 1628|     97|			if (len == NULL)
  ------------------
  |  Branch (1628:8): [True: 0, False: 97]
  ------------------
 1629|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1630|     97|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|     97|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1630:8): [True: 0, False: 97]
  ------------------
 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|     97|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1641|     97|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|     97|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1641:8): [True: 0, False: 97]
  ------------------
 1642|      0|				*len -= 1;
 1643|      0|			}
 1644|     97|		}
 1645|     98|		break;
 1646|    435|	case SC_ASN1_PATH:
  ------------------
  |  |  174|    435|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1646:2): [True: 435, False: 56.6k]
  ------------------
 1647|    435|		if (entry->parm != NULL)
  ------------------
  |  Branch (1647:7): [True: 435, False: 0]
  ------------------
 1648|    435|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1649|    435|		break;
 1650|      2|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|      2|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1650:2): [True: 2, False: 57.1k]
  ------------------
 1651|      2|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1651:7): [True: 2, False: 0]
  ------------------
 1652|      2|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1653|      2|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1653:15): [True: 0, False: 2]
  ------------------
 1654|       |
 1655|      2|			memcpy(id->value, obj, c);
 1656|      2|			id->len = c;
 1657|      2|		}
 1658|      2|		break;
 1659|     11|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|     11|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1659:2): [True: 11, False: 57.1k]
  ------------------
 1660|     11|		if (entry->parm != NULL)
  ------------------
  |  Branch (1660:7): [True: 11, False: 0]
  ------------------
 1661|     11|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1662|     11|		break;
 1663|  4.66k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|  4.66k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1663:2): [True: 4.66k, False: 52.4k]
  ------------------
 1664|  4.66k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1664:7): [True: 4.66k, False: 0]
  ------------------
 1665|  4.66k|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1666|  4.66k|		break;
 1667|      9|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      9|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1667:2): [True: 9, False: 57.1k]
  ------------------
 1668|      9|		if (entry->parm != NULL)
  ------------------
  |  Branch (1668:7): [True: 9, False: 0]
  ------------------
 1669|      9|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1670|      9|		break;
 1671|  2.48k|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|  2.48k|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1671:2): [True: 2.48k, False: 54.6k]
  ------------------
 1672|  2.48k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1672:7): [True: 2.48k, False: 0]
  ------------------
 1673|  2.48k|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1674|  2.48k|		break;
 1675|      0|	default:
  ------------------
  |  Branch (1675:2): [True: 0, False: 57.1k]
  ------------------
 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|  57.1k|	}
 1679|  57.1k|	if (r) {
  ------------------
  |  Branch (1679:6): [True: 1.13k, False: 55.9k]
  ------------------
 1680|  1.13k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|  1.13k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1681|  1.13k|		      sc_strerror(r));
 1682|  1.13k|		return r;
 1683|  1.13k|	}
 1684|  55.9k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  55.9k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1685|  55.9k|	return 0;
 1686|  57.1k|}
asn1.c:decode_bit_field:
  687|    136|{
  688|    136|	u8		data[sizeof(unsigned int)];
  689|    136|	unsigned int	field = 0;
  690|    136|	int		i, n;
  691|       |
  692|    136|	if (outlen != sizeof(data))
  ------------------
  |  Branch (692:6): [True: 0, False: 136]
  ------------------
  693|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  694|       |
  695|    136|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  696|    136|	if (n < 0)
  ------------------
  |  Branch (696:6): [True: 22, False: 114]
  ------------------
  697|     22|		return n;
  698|       |
  699|    126|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (699:14): [True: 12, False: 114]
  ------------------
  700|     12|		field |= ((unsigned int) data[i/8] << i);
  701|     12|	}
  702|    114|	memcpy(outbuf, &field, outlen);
  703|    114|	return 0;
  704|    136|}
asn1.c:sc_asn1_decode_utf8string:
  963|     97|{
  964|     97|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (964:6): [True: 0, False: 97]
  ------------------
  965|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  966|     97|	*outlen = inlen+1;
  967|     97|	memcpy(out, inbuf, inlen);
  968|     97|	out[inlen] = 0;
  969|     97|	return 0;
  970|     97|}
asn1.c:asn1_decode_path:
 1145|    435|{
 1146|    435|	int idx, count, r;
 1147|    435|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1148|    435|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1149|    435|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1150|       |
 1151|    435|	memset(path, 0, sizeof(struct sc_path));
 1152|       |
 1153|    435|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1154|    435|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1155|       |
 1156|    435|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1157|    435|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1158|       |
 1159|    435|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1160|    435|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1161|    435|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1162|    435|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1163|       |
 1164|    435|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1165|    435|	if (r)
  ------------------
  |  Branch (1165:6): [True: 25, False: 410]
  ------------------
 1166|     25|		return r;
 1167|       |
 1168|    410|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    410|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1168:6): [True: 0, False: 410]
  ------------------
 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|    410|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    410|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1176:11): [True: 295, False: 115]
  ------------------
 1177|       |		/* path present: set 'path' */
 1178|    295|		memcpy(path->value, path_value, path_len);
 1179|    295|		path->len = path_len;
 1180|    295|	}
 1181|    115|	else   {
 1182|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1183|    115|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    115|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1184|    115|	}
 1185|       |
 1186|    295|	if (path->len == 2)
  ------------------
  |  Branch (1186:6): [True: 82, False: 213]
  ------------------
 1187|     82|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     82|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1188|    213|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1188:13): [True: 0, False: 213]
  |  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|    213|	else
 1191|    213|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    213|#define SC_PATH_TYPE_PATH		2
  ------------------
 1192|       |
 1193|    295|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    295|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|     27|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1193:6): [True: 27, False: 268]
  |  Branch (1193:48): [True: 0, False: 27]
  ------------------
 1194|      0|		path->index = idx;
 1195|      0|		path->count = count;
 1196|      0|	}
 1197|    295|	else {
 1198|    295|		path->index = 0;
 1199|    295|		path->count = -1;
 1200|    295|	}
 1201|       |
 1202|    295|	return SC_SUCCESS;
  ------------------
  |  |   28|    295|#define SC_SUCCESS				0
  ------------------
 1203|    410|}
asn1.c:asn1_decode_p15_object:
 1391|     11|{
 1392|     11|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1393|     11|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1394|     11|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1395|     11|	size_t flags_len = sizeof(p15_obj->flags);
 1396|     11|	size_t label_len = sizeof(p15_obj->label);
 1397|     11|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1398|     11|	int r, ii;
 1399|       |
 1400|     99|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|     99|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1400:13): [True: 88, False: 11]
  ------------------
 1401|     88|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1402|     11|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1403|       |
 1404|       |
 1405|     11|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1406|     11|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1407|     11|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1408|     11|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1409|     11|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1410|     11|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1411|       |
 1412|     99|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|     99|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1412:13): [True: 88, False: 11]
  ------------------
 1413|     88|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1414|     88|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1415|     88|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1416|     88|	}
 1417|     11|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1418|       |
 1419|     11|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1420|     11|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1421|     11|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1422|     11|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1423|       |
 1424|     11|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1425|     11|	return r;
 1426|     11|}
asn1.c:asn1_decode_se_info:
 1239|      9|{
 1240|      9|	struct sc_pkcs15_sec_env_info **ses;
 1241|      9|	const unsigned char *ptr = obj;
 1242|      9|	size_t idx, ptrlen = objlen;
 1243|      9|	int ret;
 1244|       |
 1245|      9|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      9|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      9|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1246|       |
 1247|      9|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|      9|#define SC_MAX_SE_NUM			8
  ------------------
 1248|      9|	if (ses == NULL) {
  ------------------
  |  Branch (1248:6): [True: 0, False: 9]
  ------------------
 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|      9|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|     18|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1252:14): [True: 9, False: 0]
  |  Branch (1252:37): [True: 1, False: 8]
  ------------------
 1253|      1|		struct sc_asn1_entry asn1_se[2];
 1254|      1|		struct sc_asn1_entry asn1_se_info[4];
 1255|      1|		struct sc_pkcs15_sec_env_info si;
 1256|       |
 1257|      1|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1258|      1|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1259|       |
 1260|      1|		si.aid.len = sizeof(si.aid.value);
 1261|      1|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1262|      1|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1263|      1|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1264|      1|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1265|       |
 1266|      1|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1267|      1|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (1267:7): [True: 1, False: 0]
  ------------------
 1268|      1|			goto err;
 1269|      0|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1269:7): [True: 0, False: 0]
  ------------------
 1270|      0|			sc_init_oid(&si.owner);
 1271|       |
 1272|      0|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1273|      0|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1273:7): [True: 0, False: 0]
  ------------------
 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|      0|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1279|      0|		idx++;
 1280|      0|	}
 1281|       |
 1282|      8|	*se  = ses;
 1283|      8|	*num = idx;
 1284|      8|	ret = SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 1285|      9|err:
 1286|      9|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|      9|#define SC_SUCCESS				0
  ------------------
  |  Branch (1286:6): [True: 1, False: 8]
  ------------------
 1287|      1|		size_t i;
 1288|      1|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1288:15): [True: 0, False: 1]
  ------------------
 1289|      0|			if (ses[i])
  ------------------
  |  Branch (1289:8): [True: 0, False: 0]
  ------------------
 1290|      0|				free(ses[i]);
 1291|      1|		free(ses);
 1292|      1|	}
 1293|       |
 1294|      9|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      9|	int _ret = r; \
  |  |  155|      9|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  ------------------
  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 8]
  |  |  ------------------
  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      9|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      9|	return _ret; \
  |  |  163|      9|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1295|      9|}
asn1.c:asn1_encode:
 2039|  22.1k|{
 2040|  22.1k|	int r, idx = 0;
 2041|  22.1k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2042|  22.1k|	size_t total = 0, objsize;
 2043|       |
 2044|  22.1k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2044:6): [True: 0, False: 22.1k]
  ------------------
 2045|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2046|      0|	}
 2047|       |
 2048|  55.8k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2048:16): [True: 33.6k, False: 22.1k]
  ------------------
 2049|  33.6k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2050|  33.6k|		if (r) {
  ------------------
  |  Branch (2050:7): [True: 40, False: 33.6k]
  ------------------
 2051|     40|			if (obj)
  ------------------
  |  Branch (2051:8): [True: 0, False: 40]
  ------------------
 2052|      0|				free(obj);
 2053|     40|			if (buf)
  ------------------
  |  Branch (2053:8): [True: 11, False: 29]
  ------------------
 2054|     11|				free(buf);
 2055|     40|			return r;
 2056|     40|		}
 2057|       |		/* in case of an empty (optional) element continue with
 2058|       |		 * the next asn1 element */
 2059|  33.6k|		if (!objsize)
  ------------------
  |  Branch (2059:7): [True: 10.0k, False: 23.5k]
  ------------------
 2060|  10.0k|			continue;
 2061|  23.5k|		tmp = (u8 *) realloc(buf, total + objsize);
 2062|  23.5k|		if (!tmp) {
  ------------------
  |  Branch (2062:7): [True: 0, False: 23.5k]
  ------------------
 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|  23.5k|		buf = tmp;
 2070|  23.5k|		memcpy(buf + total, obj, objsize);
 2071|  23.5k|		free(obj);
 2072|  23.5k|		obj = NULL;
 2073|  23.5k|		total += objsize;
 2074|  23.5k|	}
 2075|  22.1k|	*ptr = buf;
 2076|  22.1k|	*size = total;
 2077|  22.1k|	return 0;
 2078|  22.1k|}
asn1.c:asn1_encode_entry:
 1826|  33.6k|{
 1827|  33.6k|	void *parm = entry->parm;
 1828|  33.6k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1829|  33.6k|			     size_t *nobjlen, int ndepth);
 1830|  33.6k|	const size_t *len = (const size_t *) entry->arg;
 1831|  33.6k|	int r = 0;
 1832|  33.6k|	u8 * buf = NULL;
 1833|  33.6k|	size_t buflen = 0;
 1834|       |
 1835|  33.6k|	callback_func = parm;
 1836|       |
 1837|  33.6k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|  33.6k|#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|  33.6k|	       	depth, depth, "", entry->name,
  |  |  |  | 1839|  33.6k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  33.6k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1838|  33.6k|	       	depth, depth, "", entry->name,
 1839|  33.6k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1840|  33.6k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  33.6k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1840:6): [True: 10.0k, False: 23.5k]
  ------------------
 1841|  10.0k|		goto no_object;
 1842|  23.5k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*stype=%d, tag=0x%02x, parm=%p, len=%zu",
  ------------------
  |  |   70|  47.1k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 15.0k, False: 8.54k]
  |  |  ------------------
  ------------------
 1843|  23.5k|			depth, depth, "", entry->type, entry->tag, parm, len ? *len : 0);
 1844|       |
 1845|  23.5k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  23.5k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1845:6): [True: 0, False: 23.5k]
  ------------------
 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|  23.5k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  158|  47.1k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1870:6): [True: 23.4k, False: 195]
  |  Branch (1870:37): [True: 14, False: 23.3k]
  ------------------
 1871|     14|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "unexpected parm == NULL\n");
  ------------------
  |  |   70|     14|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1872|     14|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     14|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1873|     14|	}
 1874|       |
 1875|  23.5k|	switch (entry->type) {
 1876|  1.23k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  1.23k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1876:2): [True: 1.23k, False: 22.3k]
  ------------------
 1877|  1.23k|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1878|  1.23k|				&buflen, depth + 1);
 1879|  1.23k|		break;
 1880|    195|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    195|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1880:2): [True: 195, False: 23.3k]
  ------------------
 1881|    195|		buf = NULL;
 1882|    195|		buflen = 0;
 1883|    195|		break;
 1884|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1884:2): [True: 0, False: 23.5k]
  ------------------
 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: 23.5k]
  ------------------
 1894|      0|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|      0|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1894:2): [True: 0, False: 23.5k]
  ------------------
 1895|      0|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1896|      0|		break;
 1897|  1.03k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  1.03k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1897:2): [True: 1.03k, False: 22.5k]
  ------------------
 1898|  1.03k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  1.03k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1898:2): [True: 0, False: 23.5k]
  ------------------
 1899|  1.03k|		if (len != NULL) {
  ------------------
  |  Branch (1899:7): [True: 1.03k, False: 0]
  ------------------
 1900|  1.03k|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  155|  1.03k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1900:8): [True: 0, False: 1.03k]
  ------------------
 1901|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1902|  1.03k|			else
 1903|  1.03k|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1904|  1.03k|		} else {
 1905|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1906|      0|		}
 1907|  1.03k|		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: 23.5k]
  ------------------
 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: 23.5k]
  ------------------
 1916|  14.0k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  14.0k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1916:2): [True: 14.0k, False: 9.57k]
  ------------------
 1917|  14.0k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  14.0k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1917:2): [True: 0, False: 23.5k]
  ------------------
 1918|  14.0k|		if (len != NULL) {
  ------------------
  |  Branch (1918:7): [True: 14.0k, False: 0]
  ------------------
 1919|  14.0k|			buf = malloc(*len + 1);
 1920|  14.0k|			if (buf == NULL) {
  ------------------
  |  Branch (1920:8): [True: 0, False: 14.0k]
  ------------------
 1921|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1922|      0|				break;
 1923|      0|			}
 1924|  14.0k|			buflen = 0;
 1925|       |			/* If the integer is supposed to be unsigned, insert
 1926|       |			 * a padding byte if the MSB is one */
 1927|  14.0k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  14.0k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1927:8): [True: 391, False: 13.6k]
  ------------------
 1928|    391|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1928:9): [True: 199, False: 192]
  ------------------
 1929|    199|				buf[buflen++] = 0x00;
 1930|    199|			}
 1931|  14.0k|			memcpy(buf + buflen, parm, *len);
 1932|  14.0k|			buflen += *len;
 1933|  14.0k|		} else {
 1934|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1935|      0|		}
 1936|  14.0k|		break;
 1937|  14.0k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1937:2): [True: 0, False: 23.5k]
  ------------------
 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|  6.08k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  6.08k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1950:2): [True: 6.08k, False: 17.5k]
  ------------------
 1951|  6.08k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1952|  6.08k|		break;
 1953|      0|	case SC_ASN1_PATH:
  ------------------
  |  |  174|      0|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1953:2): [True: 0, False: 23.5k]
  ------------------
 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: 23.5k]
  ------------------
 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: 23.5k]
  ------------------
 1970|      0|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1971|      0|		break;
 1972|  1.03k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|  1.03k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1972:2): [True: 1.03k, False: 22.5k]
  ------------------
 1973|  1.03k|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1974|  1.03k|		break;
 1975|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1975:2): [True: 0, False: 23.5k]
  ------------------
 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: 23.5k]
  ------------------
 1981|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1982|      0|		break;
 1983|      0|	default:
  ------------------
  |  Branch (1983:2): [True: 0, False: 23.5k]
  ------------------
 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|  23.5k|	}
 1987|  23.5k|	if (r) {
  ------------------
  |  Branch (1987:6): [True: 20, False: 23.5k]
  ------------------
 1988|     20|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|     20|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1989|     20|		      sc_strerror(r));
 1990|     20|		if (buf)
  ------------------
  |  Branch (1990:7): [True: 0, False: 20]
  ------------------
 1991|      0|			free(buf);
 1992|     20|		return r;
 1993|     20|	}
 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|  33.6k|no_object:
 2006|  33.6k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  148|  43.9k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  10.2k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2006:6): [True: 10.2k, False: 23.3k]
  |  Branch (2006:17): [True: 10.2k, False: 6]
  |  Branch (2006:52): [True: 10.0k, False: 195]
  ------------------
 2007|       |		/* This happens when we try to encode e.g. the
 2008|       |		 * subClassAttributes, which may be empty */
 2009|  10.0k|		*obj = NULL;
 2010|  10.0k|		*objlen = 0;
 2011|  10.0k|		r = 0;
 2012|  23.5k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  151|    201|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2012:13): [True: 201, False: 23.3k]
  |  Branch (2012:24): [True: 0, False: 201]
  ------------------
 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|  23.5k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  158|  23.7k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  141|      6|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2018:13): [True: 23.3k, False: 201]
  |  Branch (2018:23): [True: 195, False: 6]
  |  Branch (2018:54): [True: 0, False: 6]
  ------------------
 2019|  23.5k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2020|  23.5k|		if (r)
  ------------------
  |  Branch (2020:7): [True: 0, False: 23.5k]
  ------------------
 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|  23.5k|					sc_strerror(r));
 2023|  23.5k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      6|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2023:13): [True: 0, False: 6]
  ------------------
 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|      6|	} else {
 2027|      6|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode empty non-optional ASN.1 object\n");
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2028|      6|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2029|      6|	}
 2030|  33.6k|	if (buf)
  ------------------
  |  Branch (2030:6): [True: 23.3k, False: 10.2k]
  ------------------
 2031|  23.3k|		free(buf);
 2032|  33.6k|	if (r >= 0)
  ------------------
  |  Branch (2032:6): [True: 33.6k, False: 6]
  ------------------
 2033|  33.6k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*slength of encoded item=%zu", depth, depth, "", *objlen);
  ------------------
  |  |   70|  33.6k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2034|  33.6k|	return r;
 2035|  23.5k|}
asn1.c:encode_bit_string:
  647|  1.03k|{
  648|  1.03k|	const u8 *in = inbuf;
  649|  1.03k|	u8 *out;
  650|  1.03k|	size_t bytes, skipped = 0;
  651|       |
  652|  1.03k|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  146|  1.03k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  653|  1.03k|	*outbuf = out = malloc(bytes);
  654|  1.03k|	if (out == NULL)
  ------------------
  |  Branch (654:6): [True: 0, False: 1.03k]
  ------------------
  655|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  656|  1.03k|	*outlen = bytes;
  657|  1.03k|	out += 1;
  658|  68.3k|	while (bits_left) {
  ------------------
  |  Branch (658:9): [True: 67.2k, False: 1.03k]
  ------------------
  659|  67.2k|		size_t i, bits_to_go = 8;
  660|       |
  661|  67.2k|		*out = 0;
  662|  67.2k|		if (bits_left < 8) {
  ------------------
  |  Branch (662:7): [True: 0, False: 67.2k]
  ------------------
  663|      0|			bits_to_go = bits_left;
  664|      0|			skipped = 8 - bits_left;
  665|      0|		}
  666|  67.2k|		if (invert) {
  ------------------
  |  Branch (666:7): [True: 0, False: 67.2k]
  ------------------
  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|  67.2k|		} else {
  670|  67.2k|			*out = *in;
  671|  67.2k|			if (bits_left < 8)
  ------------------
  |  Branch (671:8): [True: 0, False: 67.2k]
  ------------------
  672|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  673|  67.2k|		}
  674|  67.2k|		bits_left -= bits_to_go;
  675|  67.2k|		out++, in++;
  676|  67.2k|	}
  677|  1.03k|	out = *outbuf;
  678|  1.03k|	out[0] = skipped;
  679|  1.03k|	return 0;
  680|  1.03k|}

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

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

sc_get_authentic_driver:
 2149|  15.7k|{
 2150|  15.7k|	return sc_get_driver();
 2151|  15.7k|}
card-authentic.c:sc_get_driver:
 2114|  15.7k|{
 2115|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2116|       |
 2117|  15.7k|	if (!iso_ops)
  ------------------
  |  Branch (2117:6): [True: 1, False: 15.7k]
  ------------------
 2118|      1|		iso_ops = iso_drv->ops;
 2119|       |
 2120|  15.7k|	authentic_ops = *iso_ops;
 2121|       |
 2122|  15.7k|	authentic_ops.match_card = authentic_match_card;
 2123|  15.7k|	authentic_ops.init = authentic_init;
 2124|  15.7k|	authentic_ops.finish = authentic_finish;
 2125|  15.7k|	authentic_ops.read_binary = authentic_read_binary;
 2126|  15.7k|	authentic_ops.write_binary = authentic_write_binary;
 2127|  15.7k|	authentic_ops.update_binary = authentic_update_binary;
 2128|  15.7k|	authentic_ops.erase_binary = authentic_erase_binary;
 2129|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2130|  15.7k|	authentic_ops.select_file = authentic_select_file;
 2131|       |	/* get_response: Untested */
 2132|  15.7k|	authentic_ops.get_challenge = authentic_get_challenge;
 2133|  15.7k|	authentic_ops.set_security_env = authentic_set_security_env;
 2134|       |	/* decipher: Untested */
 2135|  15.7k|	authentic_ops.decipher = authentic_decipher;
 2136|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2137|  15.7k|	authentic_ops.create_file = authentic_create_file;
 2138|  15.7k|	authentic_ops.delete_file = authentic_delete_file;
 2139|  15.7k|	authentic_ops.card_ctl = authentic_card_ctl;
 2140|  15.7k|	authentic_ops.process_fci = authentic_process_fci;
 2141|  15.7k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2142|  15.7k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2143|       |
 2144|  15.7k|	return &authentic_drv;
 2145|  15.7k|}
card-authentic.c:authentic_match_card:
  390|  11.6k|{
  391|  11.6k|	struct sc_context *ctx = card->ctx;
  392|  11.6k|	int i;
  393|       |
  394|  11.6k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  11.6k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  11.6k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|  11.6k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  396|  11.6k|	if (i < 0)   {
  ------------------
  |  Branch (396:6): [True: 11.2k, False: 348]
  ------------------
  397|  11.2k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  11.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  398|  11.2k|		return 0;
  399|  11.2k|	}
  400|       |
  401|    348|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   71|    348|#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|    348|	return 1;
  403|  11.6k|}
card-authentic.c:authentic_init:
  442|    348|{
  443|    348|	struct sc_context *ctx = card->ctx;
  444|    348|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    348|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  445|       |
  446|    348|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    348|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    348|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    348|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    348|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 348]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  447|    348|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (447:11): [True: 348, False: 0]
  ------------------
  448|    348|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (448:7): [True: 348, False: 0]
  ------------------
  449|    348|			card->name = authentic_known_atrs[ii].name;
  450|    348|			card->flags = authentic_known_atrs[ii].flags;
  451|    348|			break;
  452|    348|		}
  453|    348|	}
  454|       |
  455|    348|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (455:6): [True: 0, False: 348]
  ------------------
  456|    348|		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|    348|	card->cla  = 0x00;
  459|    348|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  460|    348|	if (!card->drv_data)
  ------------------
  |  Branch (460:6): [True: 0, False: 348]
  ------------------
  461|    348|		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|    348|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (463:6): [True: 348, False: 0]
  ------------------
  464|    348|		rv = authentic_init_oberthur_authentic_3_2(card);
  465|       |
  466|    348|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    348|#define SC_SUCCESS				0
  ------------------
  |  Branch (466:6): [True: 175, False: 173]
  ------------------
  467|    175|		rv = authentic_get_serialnr(card, NULL);
  468|       |
  469|    348|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    348|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 24, False: 324]
  ------------------
  470|     24|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     24|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  471|       |
  472|       |	/* Free private data on error */
  473|    348|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    348|#define SC_SUCCESS				0
  ------------------
  |  Branch (473:6): [True: 24, False: 324]
  ------------------
  474|     24|		free(card->drv_data);
  475|     24|		card->drv_data = NULL;
  476|     24|	}
  477|    348|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    348|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    348|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    348|	int _ret = r; \
  |  |  |  |  155|    348|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 348, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    348|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 324]
  |  |  |  |  ------------------
  |  |  |  |  157|    348|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    348|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    348|	return _ret; \
  |  |  |  |  163|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|    348|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  408|    348|{
  409|    348|	struct sc_context *ctx = card->ctx;
  410|    348|	unsigned int flags;
  411|    348|	int rv = 0;
  412|       |
  413|    348|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    348|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    348|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    348|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    348|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 348]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|       |
  415|    348|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    348|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    348|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    348|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    348|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    348|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    348|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    348|#define SC_ALGORITHM_RSA_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|    348|#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|    348|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    348|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    348|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    348|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    348|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    348|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    348|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  416|       |
  417|    348|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    348|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  418|    348|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    348|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  419|    348|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    348|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  420|       |
  421|    348|#ifdef ENABLE_SM
  422|    348|	card->sm_ctx.ops.open = authentic_sm_open;
  423|    348|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  424|    348|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  425|    348|#endif
  426|       |
  427|    348|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  428|    348|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  174|    348|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    348|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    348|	int _ret = (r); \
  |  |  |  |  168|    348|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 165, False: 183]
  |  |  |  |  ------------------
  |  |  |  |  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|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 183]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|       |
  430|    183|	rv = authentic_select_mf(card, NULL);
  431|    183|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    183|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    183|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    183|	int _ret = (r); \
  |  |  |  |  168|    183|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  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|    183|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 173]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|    173|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  434|    173|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  435|       |
  436|    173|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    173|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    173|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    173|	int _ret = r; \
  |  |  |  |  155|    173|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 173, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    173|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  157|    173|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    173|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    173|	return _ret; \
  |  |  |  |  163|    173|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    173|}
card-authentic.c:authentic_select_mf:
  544|    183|{
  545|    183|	struct sc_context *ctx = card->ctx;
  546|    183|	struct sc_path mfpath;
  547|    183|	int rv;
  548|       |
  549|    183|	struct sc_apdu apdu;
  550|    183|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  551|       |
  552|    183|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    183|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    183|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    183|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    183|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 183]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  553|       |
  554|    183|	sc_format_path("3F00", &mfpath);
  555|    183|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    183|#define SC_PATH_TYPE_PATH		2
  ------------------
  556|       |
  557|    183|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|    183|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  558|       |
  559|    183|	apdu.resp = rbuf;
  560|    183|	apdu.resplen = sizeof(rbuf);
  561|       |
  562|    183|	rv = sc_transmit_apdu(card, &apdu);
  563|    183|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    183|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    183|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    183|	int _ret = (r); \
  |  |  |  |  168|    183|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  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|    183|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 182]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  564|    182|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  565|    182|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|    182|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    182|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    182|	int _ret = (r); \
  |  |  |  |  168|    182|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 179]
  |  |  |  |  ------------------
  |  |  |  |  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|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 179]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|       |
  567|    179|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  568|    179|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    179|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    179|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    179|	int _ret = (r); \
  |  |  |  |  168|    179|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  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|    179|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 173]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|       |
  570|    173|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    173|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    173|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    173|	int _ret = r; \
  |  |  |  |  155|    173|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 173, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    173|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  157|    173|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    173|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    173|	return _ret; \
  |  |  |  |  163|    173|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|    173|}
card-authentic.c:authentic_set_current_files:
  505|    976|{
  506|    976|	struct sc_context *ctx = card->ctx;
  507|    976|	struct sc_file *file = NULL;
  508|    976|	int rv;
  509|       |
  510|    976|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    976|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    976|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    976|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    976|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 976]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|    976|	if (resplen)   {
  ------------------
  |  Branch (511:6): [True: 355, False: 621]
  ------------------
  512|    355|		switch (resp[0]) {
  513|     35|		case 0x62:
  ------------------
  |  Branch (513:3): [True: 35, False: 320]
  ------------------
  514|    285|		case 0x6F:
  ------------------
  |  Branch (514:3): [True: 250, False: 105]
  ------------------
  515|    285|			file = sc_file_new();
  516|    285|			if (file == NULL)
  ------------------
  |  Branch (516:8): [True: 0, False: 285]
  ------------------
  517|    285|				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|    285|			if (path)
  ------------------
  |  Branch (518:8): [True: 285, False: 0]
  ------------------
  519|    285|				file->path = *path;
  520|       |
  521|    285|			rv = authentic_process_fci(card, file, resp, resplen);
  522|    285|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    285|#define SC_SUCCESS				0
  ------------------
  |  Branch (522:8): [True: 41, False: 244]
  ------------------
  523|     41|				sc_file_free(file);
  524|     41|				LOG_TEST_RET(ctx, rv, "cannot set 'current file': FCI process 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: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     41|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     41|		return _ret; \
  |  |  |  |  172|     41|	} \
  |  |  |  |  173|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|     41|			}
  526|       |
  527|    244|			break;
  528|    244|		default:
  ------------------
  |  Branch (528:3): [True: 70, False: 285]
  ------------------
  529|     70|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     70|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     70|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     70|	int _ret = r; \
  |  |  |  |  155|     70|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     70|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     70|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     70|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     70|	return _ret; \
  |  |  |  |  163|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  530|    355|		}
  531|       |
  532|    244|		if (file_out)
  ------------------
  |  Branch (532:7): [True: 128, False: 116]
  ------------------
  533|    128|			*file_out = file;
  534|    116|		else
  535|    116|			sc_file_free(file);
  536|    244|	}
  537|       |
  538|    865|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    865|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    865|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    865|	int _ret = r; \
  |  |  |  |  155|    865|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 865, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    865|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 865]
  |  |  |  |  ------------------
  |  |  |  |  157|    865|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    865|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    865|	return _ret; \
  |  |  |  |  163|    865|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    865|}
card-authentic.c:authentic_get_serialnr:
 1464|    365|{
 1465|    365|	struct sc_context *ctx = card->ctx;
 1466|    365|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1467|    365|	int rv;
 1468|       |
 1469|    365|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    365|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    365|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    365|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    365|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 365]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1470|    365|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1470:6): [True: 266, False: 99]
  ------------------
 1471|    266|		rv = authentic_get_cplc(card);
 1472|    266|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  174|    266|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    266|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    266|	int _ret = (r); \
  |  |  |  |  168|    266|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 91, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  169|     91|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     91|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     91|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     91|		return _ret; \
  |  |  |  |  172|     91|	} \
  |  |  |  |  173|    266|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 175]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|       |
 1474|    175|		card->serialnr.len = 4;
 1475|    175|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1476|       |
 1477|    175|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   71|    175|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1478|    175|				card->serialnr.value[0], card->serialnr.value[1],
 1479|    175|				card->serialnr.value[2], card->serialnr.value[3]);
 1480|    175|	}
 1481|       |
 1482|    274|	if (serial)
  ------------------
  |  Branch (1482:6): [True: 123, False: 151]
  ------------------
 1483|    123|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1484|       |
 1485|    274|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    274|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    274|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    274|	int _ret = r; \
  |  |  |  |  155|    274|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 274, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    274|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 274]
  |  |  |  |  ------------------
  |  |  |  |  157|    274|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    274|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    274|	return _ret; \
  |  |  |  |  163|    274|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1486|    274|}
card-authentic.c:authentic_get_cplc:
  360|    266|{
  361|    266|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  362|    266|	struct sc_apdu apdu;
  363|    266|	int rv, ii;
  364|    266|	unsigned char p1, p2;
  365|       |
  366|    266|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  345|    266|#define SC_CPLC_TAG		0x9F7F
  ------------------
  367|    266|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  345|    266|#define SC_CPLC_TAG		0x9F7F
  ------------------
  368|    266|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    266|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  369|    269|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (369:12): [True: 268, False: 1]
  ------------------
  370|    268|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    268|#define SC_CPLC_DER_SIZE	45
  ------------------
  371|    268|		apdu.resplen = sizeof(prv_data->cplc.value);
  372|    268|		apdu.resp = prv_data->cplc.value;
  373|       |
  374|    268|		rv = sc_transmit_apdu(card, &apdu);
  375|    268|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    268|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    268|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    268|	int _ret = (r); \
  |  |  |  |  168|    268|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 253]
  |  |  |  |  ------------------
  |  |  |  |  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|    268|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 253]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    253|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  377|    253|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    253|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (377:7): [True: 250, False: 3]
  ------------------
  378|    250|			break;
  379|       |
  380|      3|		apdu.cla = 0x80;
  381|      3|	}
  382|    251|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    251|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    251|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    251|	int _ret = (r); \
  |  |  |  |  168|    251|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 76, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  169|     76|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     76|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     76|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     76|		return _ret; \
  |  |  |  |  172|     76|	} \
  |  |  |  |  173|    251|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 175]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  383|       |
  384|    175|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    175|#define SC_CPLC_DER_SIZE	45
  ------------------
  385|    175|	return SC_SUCCESS;
  ------------------
  |  |   28|    175|#define SC_SUCCESS				0
  ------------------
  386|    251|}
card-authentic.c:authentic_finish:
 1847|    324|{
 1848|    324|	struct sc_context *ctx = card->ctx;
 1849|       |
 1850|    324|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    324|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    324|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    324|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    324|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 324]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|       |
 1852|    324|#ifdef ENABLE_SM
 1853|    324|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1853:6): [True: 0, False: 324]
  ------------------
 1854|      0|		card->sm_ctx.ops.close(card);
 1855|    324|#endif
 1856|       |
 1857|    324|	if (card->drv_data)
  ------------------
  |  Branch (1857:6): [True: 324, False: 0]
  ------------------
 1858|    324|		free(card->drv_data);
 1859|    324|	card->drv_data = NULL;
 1860|    324|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    324|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    324|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    324|	int _ret = r; \
  |  |  |  |  155|    324|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 324, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    324|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 324]
  |  |  |  |  ------------------
  |  |  |  |  157|    324|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    324|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    324|	return _ret; \
  |  |  |  |  163|    324|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1861|    324|}
card-authentic.c:authentic_read_binary:
  643|    345|{
  644|    345|	struct sc_context *ctx = card->ctx;
  645|    345|	struct sc_apdu apdu;
  646|    345|	size_t sz, rest, ret_count = 0;
  647|    345|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    345|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  648|       |
  649|    345|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    345|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    345|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    345|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    345|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 345]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|    345|	sc_log(ctx, "offs:%i,count:%zu,max_recv_size:%zu", idx, count, card->max_recv_size);
  ------------------
  |  |   71|    345|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  651|       |
  652|    345|	rest = count;
  653|  2.27k|	while(rest)   {
  ------------------
  |  Branch (653:8): [True: 1.94k, False: 336]
  ------------------
  654|  1.94k|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (654:8): [True: 1.60k, False: 339]
  ------------------
  655|  1.94k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|  1.94k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  656|  1.94k|		apdu.le = sz;
  657|  1.94k|		apdu.resplen = sz;
  658|  1.94k|		apdu.resp = (buf + ret_count);
  659|       |
  660|  1.94k|		rv = sc_transmit_apdu(card, &apdu);
  661|  1.94k|		if(!rv)
  ------------------
  |  Branch (661:6): [True: 1.93k, False: 9]
  ------------------
  662|  1.93k|			ret_count += apdu.resplen;
  663|      9|		else
  664|      9|			break;
  665|       |
  666|  1.93k|		idx += sz;
  667|  1.93k|		rest -= sz;
  668|  1.93k|	}
  669|       |
  670|    345|	if (rv)   {
  ------------------
  |  Branch (670:6): [True: 9, False: 336]
  ------------------
  671|      9|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "authentic_read_binary() failed");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    336|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  676|    336|	if (!rv)
  ------------------
  |  Branch (676:6): [True: 286, False: 50]
  ------------------
  677|    286|		count = ret_count;
  678|       |
  679|    336|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    336|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    336|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    336|	int _ret = (r); \
  |  |  |  |  168|    336|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 50, False: 286]
  |  |  |  |  ------------------
  |  |  |  |  169|     50|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     50|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     50|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     50|		return _ret; \
  |  |  |  |  172|     50|	} \
  |  |  |  |  173|    336|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 286]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  680|    286|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|    286|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    286|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    286|	int _ret = r; \
  |  |  |  |  155|    286|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 276]
  |  |  |  |  ------------------
  |  |  |  |  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|    276|	} else { \
  |  |  |  |  159|    276|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    276|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    276|	} \
  |  |  |  |  162|    286|	return _ret; \
  |  |  |  |  163|    286|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  681|    286|}
card-authentic.c:authentic_select_file:
  576|  2.11k|{
  577|  2.11k|	struct sc_context *ctx = card->ctx;
  578|  2.11k|	struct sc_apdu apdu;
  579|  2.11k|	struct sc_path lpath;
  580|  2.11k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  581|  2.11k|	size_t pathlen;
  582|  2.11k|	int rv;
  583|       |
  584|  2.11k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.11k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.11k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.11k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.11k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.11k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|  2.11k|	memcpy(&lpath, path, sizeof(struct sc_path));
  587|       |
  588|  2.11k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  4.22k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (588:6): [True: 1.15k, False: 958]
  |  Branch (588:41): [True: 222, False: 931]
  ------------------
  589|    222|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    222|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  590|       |
  591|  2.11k|	pathlen = lpath.len;
  592|  2.11k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  2.11k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  593|       |
  594|  2.11k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (594:6): [True: 0, False: 2.11k]
  ------------------
  595|  2.11k|		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|  2.11k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  2.11k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (597:6): [True: 222, False: 1.88k]
  ------------------
  598|    222|		apdu.p1 = 0x00;
  599|    222|	}
  600|  1.88k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.88k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (600:11): [True: 931, False: 958]
  ------------------
  601|    931|		apdu.p1 = 0x08;
  602|    931|	}
  603|    958|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    958|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (603:11): [True: 0, False: 958]
  ------------------
  604|      0|		apdu.p1 = 0x09;
  605|      0|	}
  606|    958|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    958|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (606:11): [True: 958, False: 0]
  ------------------
  607|    958|		apdu.p1 = 4;
  608|    958|	}
  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|  2.11k|	apdu.lc = pathlen;
  620|  2.11k|	apdu.data = lpath.value;
  621|  2.11k|	apdu.datalen = pathlen;
  622|       |
  623|  2.11k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  4.22k|#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: 2.11k, False: 0]
  |  Branch (623:42): [True: 0, False: 0]
  ------------------
  624|  2.11k|		apdu.resp = rbuf;
  625|  2.11k|		apdu.resplen = sizeof(rbuf);
  626|  2.11k|		apdu.le = 256;
  627|  2.11k|	}
  628|       |
  629|  2.11k|	rv = sc_transmit_apdu(card, &apdu);
  630|  2.11k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  2.11k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.11k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.11k|	int _ret = (r); \
  |  |  |  |  168|  2.11k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 55, False: 2.05k]
  |  |  |  |  ------------------
  |  |  |  |  169|     55|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     55|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     55|		return _ret; \
  |  |  |  |  172|     55|	} \
  |  |  |  |  173|  2.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.05k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|  2.05k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  632|  2.05k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  2.05k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.05k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.05k|	int _ret = (r); \
  |  |  |  |  168|  2.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.25k, False: 797]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.25k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.25k|		return _ret; \
  |  |  |  |  172|  1.25k|	} \
  |  |  |  |  173|  2.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 797]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|       |
  634|    797|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  635|    797|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    797|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    797|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    797|	int _ret = (r); \
  |  |  |  |  168|    797|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 105, False: 692]
  |  |  |  |  ------------------
  |  |  |  |  169|    105|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    105|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    105|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    105|		return _ret; \
  |  |  |  |  172|    105|	} \
  |  |  |  |  173|    797|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 692]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    692|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    692|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    692|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    692|	int _ret = r; \
  |  |  |  |  155|    692|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 692, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    692|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 692]
  |  |  |  |  ------------------
  |  |  |  |  157|    692|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    692|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    692|	return _ret; \
  |  |  |  |  163|    692|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|    692|}
card-authentic.c:authentic_get_challenge:
 1491|    152|{
 1492|       |	/* 'GET CHALLENGE' returns always 24 bytes */
 1493|    152|	unsigned char rbuf[0x18];
 1494|    152|	size_t out_len;
 1495|    152|	int r;
 1496|       |
 1497|    152|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    152|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    152|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    152|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    152|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 152]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1498|       |
 1499|    152|	r = iso_ops->get_challenge(card, rbuf, sizeof rbuf);
 1500|    152|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE cmd failed");
  ------------------
  |  |  174|    152|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    152|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    152|	int _ret = (r); \
  |  |  |  |  168|    152|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 78, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  169|     78|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     78|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     78|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     78|		return _ret; \
  |  |  |  |  172|     78|	} \
  |  |  |  |  173|    152|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 74]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1501|       |
 1502|     74|	if (len < (size_t) r) {
  ------------------
  |  Branch (1502:6): [True: 1, False: 73]
  ------------------
 1503|      1|		out_len = len;
 1504|     73|	} else {
 1505|     73|		out_len = (size_t) r;
 1506|     73|	}
 1507|     74|	memcpy(rnd, rbuf, out_len);
 1508|       |
 1509|     74|	LOG_FUNC_RETURN(card->ctx, (int)out_len);
  ------------------
  |  |  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: 3, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  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|     71|	} else { \
  |  |  |  |  159|     71|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     71|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     71|	} \
  |  |  |  |  162|     74|	return _ret; \
  |  |  |  |  163|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1510|     74|}
card-authentic.c:authentic_set_security_env:
 1765|     12|{
 1766|     12|	struct sc_context *ctx = card->ctx;
 1767|     12|	struct sc_apdu apdu;
 1768|     12|	unsigned char cse_crt_dst[] = {
 1769|     12|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|     12|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1770|     12|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|     12|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1771|     12|	};
 1772|     12|	unsigned char cse_crt_ct[] = {
 1773|     12|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|     12|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1774|     12|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|     12|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1775|     12|	};
 1776|     12|	int rv;
 1777|       |
 1778|     12|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|     12|	sc_log(ctx, "set SE#%i(op:0x%X,algo:0x%lX,algo_ref:0x%lX,flags:0x%lX), key_ref:0x%X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1780|     12|			se_num, env->operation, env->algorithm, env->algorithm_ref, env->algorithm_flags, env->key_ref[0]);
 1781|     12|	switch (env->operation)  {
 1782|      7|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|      7|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1782:2): [True: 7, False: 5]
  ------------------
 1783|      7|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_DST);
  ------------------
  |  |  293|      7|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_DST);
  ------------------
  |  |  109|      7|#define AUTHENTIC_TAG_CRT_DST	0xB6
  ------------------
 1784|      7|		apdu.data = cse_crt_dst;
 1785|      7|		apdu.datalen = sizeof(cse_crt_dst);
 1786|      7|		apdu.lc = sizeof(cse_crt_dst);
 1787|      7|		break;
 1788|      5|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|      5|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1788:2): [True: 5, False: 7]
  ------------------
 1789|      5|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  293|      5|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  110|      5|#define AUTHENTIC_TAG_CRT_CT	0xB8
  ------------------
 1790|      5|		apdu.data = cse_crt_ct;
 1791|      5|		apdu.datalen = sizeof(cse_crt_ct);
 1792|      5|		apdu.lc = sizeof(cse_crt_ct);
 1793|      5|		break;
 1794|      0|	default:
  ------------------
  |  Branch (1794:2): [True: 0, False: 12]
  ------------------
 1795|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1796|     12|	}
 1797|       |
 1798|     12|	rv = sc_transmit_apdu(card, &apdu);
 1799|     12|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1800|     11|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1801|     11|	LOG_TEST_RET(ctx, rv, "MSE restore 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: 2, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1802|       |
 1803|      9|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1804|      9|}
card-authentic.c:authentic_decipher:
 1810|      4|{
 1811|      4|	struct sc_context *ctx = card->ctx;
 1812|      4|	struct sc_apdu apdu;
 1813|      4|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1814|      4|	int rv;
 1815|       |
 1816|      4|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1817|      4|	sc_log(ctx, "crgram_len %zu;  outlen %zu", in_len, out_len);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1818|      4|	if (!out || !out_len || in_len > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|      4|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1818:6): [True: 0, False: 4]
  |  Branch (1818:14): [True: 0, False: 4]
  |  Branch (1818:26): [True: 0, False: 4]
  ------------------
 1819|      4|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1820|       |
 1821|      4|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|      4|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1822|      4|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      4|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1823|      4|	apdu.data = in;
 1824|      4|	apdu.datalen = in_len;
 1825|      4|	apdu.lc = in_len;
 1826|      4|	apdu.resp = resp;
 1827|      4|	apdu.resplen = sizeof(resp);
 1828|      4|	apdu.le = 256;
 1829|       |
 1830|      4|	rv = sc_transmit_apdu(card, &apdu);
 1831|      4|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1832|      3|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1833|      3|	LOG_TEST_RET(ctx, rv, "Card returned 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1834|       |
 1835|      2|	if (out_len > apdu.resplen)
  ------------------
  |  Branch (1835:6): [True: 2, False: 0]
  ------------------
 1836|      2|		out_len = apdu.resplen;
 1837|       |
 1838|      2|	memcpy(out, apdu.resp, out_len);
 1839|      2|	rv = (int)out_len;
 1840|       |
 1841|      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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1842|      2|}
card-authentic.c:authentic_card_ctl:
 1738|    390|{
 1739|    390|	struct sc_context *ctx = card->ctx;
 1740|    390|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1741|       |
 1742|    390|	switch (cmd) {
  ------------------
  |  Branch (1742:10): [True: 190, False: 200]
  ------------------
 1743|    190|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1743:2): [True: 190, False: 200]
  ------------------
 1744|    190|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1745|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1745:2): [True: 0, False: 390]
  ------------------
 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: 390]
  ------------------
 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: 390]
  ------------------
 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: 390]
  ------------------
 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|    390|	}
 1758|    200|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    200|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1759|    390|}
card-authentic.c:authentic_get_tagged_data:
  177|    471|{
  178|    471|	size_t size_len, tag_len, offs, size;
  179|    471|	int rv;
  180|    471|	unsigned tag;
  181|       |
  182|    471|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 471]
  |  Branch (182:14): [True: 0, False: 471]
  ------------------
  183|    471|		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|  3.39k|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 3.28k, False: 110]
  ------------------
  186|  3.28k|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 77, False: 3.20k]
  |  Branch (186:33): [True: 183, False: 3.02k]
  ------------------
  187|    260|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 11, False: 249]
  ------------------
  188|    260|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    249|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|    249|			tag_len = 2;
  191|    249|		}
  192|  3.02k|		else   {
  193|  3.02k|			tag = *(in + offs);
  194|  3.02k|			tag_len = 1;
  195|  3.02k|		}
  196|       |
  197|  3.27k|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 39, False: 3.23k]
  ------------------
  198|  3.27k|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|     39|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     39|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     39|	int _ret = (r); \
  |  |  |  |  168|     39|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     39|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     39|		return _ret; \
  |  |  |  |  172|     39|	} \
  |  |  |  |  173|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|  3.23k|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|  3.23k|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|  3.23k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.23k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.23k|	int _ret = (r); \
  |  |  |  |  168|  3.23k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 3.20k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|  3.20k|		size_len = rv;
  203|       |
  204|  3.20k|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 278, False: 2.92k]
  ------------------
  205|    278|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 16, False: 262]
  ------------------
  206|    278|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|    262|			*out = in + offs + tag_len + size_len;
  209|    262|			*out_len = size;
  210|       |
  211|    262|			return SC_SUCCESS;
  ------------------
  |  |   28|    262|#define SC_SUCCESS				0
  ------------------
  212|    278|		}
  213|       |
  214|  2.92k|		offs += tag_len + size_len + size;
  215|  2.92k|	}
  216|       |
  217|    110|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    110|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    471|}
card-authentic.c:authentic_parse_size:
  149|  3.23k|{
  150|  3.23k|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 3.23k]
  |  Branch (150:13): [True: 0, False: 3.23k]
  |  Branch (150:21): [True: 0, False: 3.23k]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|  3.23k|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 3.03k, False: 200]
  ------------------
  154|  3.03k|		*out = *in;
  155|  3.03k|		return 1;
  156|  3.03k|	}
  157|    200|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 75, False: 125]
  ------------------
  158|     75|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 1, False: 74]
  ------------------
  159|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|     74|		*out = *(in + 1);
  161|     74|		return 2;
  162|     75|	}
  163|    125|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 94, False: 31]
  ------------------
  164|     94|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 1, False: 93]
  ------------------
  165|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|     93|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|     93|		return 3;
  168|     94|	}
  169|       |
  170|     31|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     31|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|  3.23k|}
card-authentic.c:authentic_process_fci:
  769|    285|{
  770|    285|	struct sc_context *ctx = card->ctx;
  771|    285|	size_t taglen;
  772|    285|	int rv;
  773|    285|	unsigned ii;
  774|    285|	const unsigned char *tag = NULL;
  775|    285|	unsigned char ops_DF[8] = {
  776|    285|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    285|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    285|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    285|#define SC_AC_OP_CRYPTO			7
  ------------------
  777|    285|	};
  778|    285|	unsigned char ops_EF[8] = {
  779|    285|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    285|#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|    285|#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|    285|#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|    285|#define SC_AC_OP_RESIZE			25
  ------------------
  780|    285|	};
  781|       |
  782|    285|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    285|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    285|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    285|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    285|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  783|       |
  784|    285|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  785|    285|	if (tag != NULL) {
  ------------------
  |  Branch (785:6): [True: 223, False: 62]
  ------------------
  786|    223|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  787|    223|		buf = tag;
  788|    223|		buflen = taglen;
  789|    223|	}
  790|       |
  791|    285|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  792|    285|	if (tag != NULL) {
  ------------------
  |  Branch (792:6): [True: 31, False: 254]
  ------------------
  793|     31|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|     31|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  794|     31|		buf = tag;
  795|     31|		buflen = taglen;
  796|     31|	}
  797|       |
  798|    285|	rv = iso_ops->process_fci(card, file, buf, buflen);
  799|    285|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    285|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    285|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    285|	int _ret = (r); \
  |  |  |  |  168|    285|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 285]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    285|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  800|       |
  801|    285|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (801:6): [True: 99, False: 186]
  ------------------
  802|     99|		sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
  ------------------
  |  |  129|     99|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     99|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  803|     99|		sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  804|     99|		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  118|    198|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|     55|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (804:7): [True: 44, False: 55]
  |  Branch (804:50): [True: 14, False: 41]
  ------------------
  805|     58|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     58|#define SC_FILE_TYPE_DF			0x04
  ------------------
  806|     58|		}
  807|     41|		else   {
  808|     41|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     41|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     41|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     41|	int _ret = (r); \
  |  |  |  |  168|     41|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     41|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     41|		return _ret; \
  |  |  |  |  172|     41|	} \
  |  |  |  |  173|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|     41|		}
  810|     99|	}
  811|       |
  812|    244|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    244|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    244|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  813|    919|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (813:15): [True: 676, False: 243]
  |  Branch (813:46): [True: 675, False: 1]
  ------------------
  814|    675|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    675|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (814:22): [True: 97, False: 578]
  ------------------
  815|    675|		unsigned char acl = *(file->sec_attr + ii*2);
  816|    675|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  817|    675|		unsigned sc = acl * 0x100 + cred_id;
  818|       |
  819|    675|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    675|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  820|    675|		if (op == 0xFF)
  ------------------
  |  Branch (820:7): [True: 184, False: 491]
  ------------------
  821|    184|			;
  822|    491|		else if (!acl && !cred_id)
  ------------------
  |  Branch (822:12): [True: 207, False: 284]
  |  Branch (822:20): [True: 101, False: 106]
  ------------------
  823|    101|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|    101|#define SC_AC_NONE			0x00000000
  ------------------
  824|    390|		else if (acl == 0xFF)
  ------------------
  |  Branch (824:12): [True: 61, False: 329]
  ------------------
  825|     61|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     61|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  826|    329|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    329|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (826:12): [True: 160, False: 169]
  ------------------
  827|    160|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|    160|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  828|    169|		else if (cred_id)
  ------------------
  |  Branch (828:12): [True: 147, False: 22]
  ------------------
  829|    147|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|    147|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  830|     22|		else
  831|     22|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     22|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    675|	}
  833|       |
  834|    244|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    244|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    244|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    244|	int _ret = r; \
  |  |  |  |  155|    244|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 244, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    244|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 244]
  |  |  |  |  ------------------
  |  |  |  |  157|    244|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    244|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    244|	return _ret; \
  |  |  |  |  163|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|    244|}
card-authentic.c:authentic_pin_cmd:
 1432|    285|{
 1433|    285|	struct sc_context *ctx = card->ctx;
 1434|    285|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    285|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1435|       |
 1436|    285|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    285|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    285|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    285|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    285|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|    285|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1438|    285|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1439|    285|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1440|       |
 1441|    285|	switch (data->cmd)   {
 1442|     26|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     26|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1442:2): [True: 26, False: 259]
  ------------------
 1443|     26|		rv = authentic_pin_verify(card, data);
 1444|     26|		break;
 1445|     28|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     28|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1445:2): [True: 28, False: 257]
  ------------------
 1446|     28|		rv = authentic_pin_change(card, data);
 1447|     28|		break;
 1448|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1448:2): [True: 0, False: 285]
  ------------------
 1449|      0|		rv = authentic_pin_reset(card, data);
 1450|      0|		break;
 1451|    231|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    231|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1451:2): [True: 231, False: 54]
  ------------------
 1452|    231|		rv = authentic_pin_get_policy(card, data, NULL);
 1453|    231|		break;
 1454|      0|	default:
  ------------------
  |  Branch (1454:2): [True: 0, False: 285]
  ------------------
 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|    285|	}
 1457|       |
 1458|    285|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    285|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    285|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    285|	int _ret = r; \
  |  |  |  |  155|    285|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 285, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    285|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    233|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 233, False: 52]
  |  |  |  |  ------------------
  |  |  |  |  157|    285|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    285|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    285|	return _ret; \
  |  |  |  |  163|    285|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1459|    285|}
card-authentic.c:authentic_pin_verify:
 1097|     26|{
 1098|     26|	struct sc_context *ctx = card->ctx;
 1099|     26|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1100|     26|	unsigned char pin_sha1[SHA_DIGEST_LENGTH];
 1101|     26|	int rv;
 1102|       |
 1103|     26|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     26|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     26|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     26|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     26|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|     26|	sc_log(ctx, "PIN(type:%X,reference:%X,data:%p,length:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1105|     26|			pin_cmd->pin_type, pin_cmd->pin_reference, pin_cmd->pin1.data, pin_cmd->pin1.len);
 1106|       |
 1107|     26|	if (pin_cmd->pin_reference < 0 || pin_cmd->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|     26|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1107:6): [True: 0, False: 26]
  |  Branch (1107:36): [True: 0, False: 26]
  ------------------
 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|     26|	if (pin_cmd->pin1.data && !pin_cmd->pin1.len)   {
  ------------------
  |  Branch (1111:6): [True: 26, False: 0]
  |  Branch (1111:28): [True: 0, False: 26]
  ------------------
 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|     26|	if (pin_cmd->pin1.data)
  ------------------
  |  Branch (1117:6): [True: 26, False: 0]
  ------------------
 1118|     26|		SHA1(pin_cmd->pin1.data, pin_cmd->pin1.len, pin_sha1);
 1119|      0|	else
 1120|      0|		SHA1((unsigned char *)"", 0, pin_sha1);
 1121|       |
 1122|     26|	if (!memcmp(pin_sha1, prv_data->pins_sha1[pin_cmd->pin_reference], SHA_DIGEST_LENGTH))   {
  ------------------
  |  Branch (1122:6): [True: 0, False: 26]
  ------------------
 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|     26|	memset(prv_data->pins_sha1[pin_cmd->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1128|       |
 1129|     26|	rv = authentic_pin_get_policy(card, pin_cmd, NULL);
 1130|     26|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' 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: 18, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|       |
 1132|      8|	if (pin_cmd->pin1.len > pin_cmd->pin1.max_length)
  ------------------
  |  Branch (1132:6): [True: 0, False: 8]
  ------------------
 1133|      8|		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|      8|	pin_cmd->pin1.tries_left = -1;
 1136|      8|	rv = authentic_chv_verify(card, pin_cmd);
 1137|      8|	LOG_TEST_RET(ctx, rv, "PIN CHV verification error");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1138|       |
 1139|      2|	memcpy(prv_data->pins_sha1[pin_cmd->pin_reference], pin_sha1, SHA_DIGEST_LENGTH);
 1140|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|      2|}
card-authentic.c:authentic_chv_verify:
 1014|      8|{
 1015|      8|	struct sc_context *ctx = card->ctx;
 1016|      8|	struct sc_apdu apdu;
 1017|      8|	struct sc_pin_cmd_pin *pin1 = &pin_cmd->pin1;
 1018|      8|	unsigned char pin_buff[SC_MAX_APDU_BUFFER_SIZE];
 1019|      8|	size_t pin_len;
 1020|      8|	int rv;
 1021|       |
 1022|      8|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      8|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      8|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1023|      8|	sc_log(ctx, "CHV PIN reference %i, pin1(%p,len:%zu)", pin_cmd->pin_reference, pin1->data, pin1->len);
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1024|       |
 1025|      8|	if (pin1->data && !pin1->len)   {
  ------------------
  |  Branch (1025:6): [True: 8, False: 0]
  |  Branch (1025:20): [True: 0, False: 8]
  ------------------
 1026|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1027|      0|	}
 1028|      8|	else if (pin1->data && pin1->len)   {
  ------------------
  |  Branch (1028:11): [True: 8, False: 0]
  |  Branch (1028:25): [True: 8, False: 0]
  ------------------
 1029|      8|		if (pin1->len > sizeof(pin_buff)) {
  ------------------
  |  Branch (1029:7): [True: 0, False: 8]
  ------------------
 1030|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1031|      0|		}
 1032|      8|		memcpy(pin_buff, pin1->data, pin1->len);
 1033|      8|		pin_len = pin1->len;
 1034|       |
 1035|      8|		if (pin1->pad_length && pin_cmd->flags & SC_PIN_CMD_NEED_PADDING)   {
  ------------------
  |  |  422|      8|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1035:7): [True: 8, False: 0]
  |  Branch (1035:27): [True: 8, False: 0]
  ------------------
 1036|      8|			if (pin1->len > pin1->pad_length || pin1->pad_length > sizeof(pin_buff)) {
  ------------------
  |  Branch (1036:8): [True: 0, False: 8]
  |  Branch (1036:40): [True: 0, False: 8]
  ------------------
 1037|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1038|      0|			}
 1039|      8|			if (pin1->len < sizeof(pin_buff)) {
  ------------------
  |  Branch (1039:8): [True: 8, False: 0]
  ------------------
 1040|      8|				memset(pin_buff + pin1->len, pin1->pad_char,
 1041|      8|						pin1->pad_length - pin1->len);
 1042|      8|			}
 1043|      8|			pin_len = pin1->pad_length;
 1044|      8|		}
 1045|       |
 1046|      8|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  293|      8|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1047|      8|		apdu.data = pin_buff;
 1048|      8|		apdu.datalen = pin_len;
 1049|      8|		apdu.lc = pin_len;
 1050|      8|	}
 1051|      0|	else if ((card->reader->capabilities & SC_READER_CAP_PIN_PAD) && !pin1->data && !pin1->len)   {
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1051:11): [True: 0, False: 0]
  |  Branch (1051:67): [True: 0, False: 0]
  |  Branch (1051:82): [True: 0, False: 0]
  ------------------
 1052|      0|		rv = authentic_chv_verify_pinpad(card, pin_cmd);
 1053|      0|		sc_log(ctx, "authentic_chv_verify() authentic_chv_verify_pinpad returned %i", rv);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1054|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1055|      0|	}
 1056|      0|	else   {
 1057|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1058|      0|	}
 1059|       |
 1060|      8|	rv = sc_transmit_apdu(card, &apdu);
 1061|      8|	LOG_TEST_RET(ctx, rv, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1062|       |
 1063|      7|	if (apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)   {
  ------------------
  |  Branch (1063:6): [True: 2, False: 5]
  |  Branch (1063:26): [True: 1, False: 1]
  ------------------
 1064|      1|		pin1->tries_left = apdu.sw2 & 0x0F;
 1065|      1|	}
 1066|       |
 1067|      7|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1068|       |
 1069|      7|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1070|      7|}
card-authentic.c:authentic_pin_change:
 1192|     28|{
 1193|     28|	struct sc_context *ctx = card->ctx;
 1194|     28|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1195|     28|	struct sc_apdu apdu;
 1196|     28|	unsigned char pin_data[SC_MAX_APDU_BUFFER_SIZE];
 1197|     28|	size_t offs;
 1198|     28|	int rv;
 1199|       |
 1200|     28|	rv = authentic_pin_get_policy(card, data, NULL);
 1201|     28|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' 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: 22, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1202|       |
 1203|      6|	if (data->pin_reference < 0 || data->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|      6|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1203:6): [True: 0, False: 6]
  |  Branch (1203:33): [True: 0, False: 6]
  ------------------
 1204|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1205|      0|	}
 1206|       |
 1207|      6|	memset(prv_data->pins_sha1[data->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1208|       |
 1209|      6|	if (!data->pin1.data && !data->pin1.len && !data->pin2.data && !data->pin2.len)   {
  ------------------
  |  Branch (1209:6): [True: 0, False: 6]
  |  Branch (1209:26): [True: 0, False: 0]
  |  Branch (1209:45): [True: 0, False: 0]
  |  Branch (1209:65): [True: 0, False: 0]
  ------------------
 1210|      0|		if (!(card->reader->capabilities & SC_READER_CAP_PIN_PAD))
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1210:7): [True: 0, False: 0]
  ------------------
 1211|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "PIN pad not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1212|      0|		rv = authentic_pin_change_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1213|      0|		sc_log(ctx, "authentic_pin_cmd(SC_PIN_CMD_CHANGE) chv_change_pinpad returned %i", rv);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1214|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1215|      0|	}
 1216|       |
 1217|      6|	if (card->max_send_size && (data->pin1.len + data->pin2.len > card->max_send_size))
  ------------------
  |  Branch (1217:6): [True: 6, False: 0]
  |  Branch (1217:29): [True: 0, False: 6]
  ------------------
 1218|      6|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_LENGTH, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1219|       |
 1220|      6|	memset(pin_data, data->pin1.pad_char, sizeof(pin_data));
 1221|      6|	offs = 0;
 1222|      6|	if (data->pin1.data && data->pin1.len)   {
  ------------------
  |  Branch (1222:6): [True: 6, False: 0]
  |  Branch (1222:25): [True: 6, False: 0]
  ------------------
 1223|      6|		if (data->pin1.pad_length > sizeof(pin_data) || data->pin1.len > sizeof(pin_data)) {
  ------------------
  |  Branch (1223:7): [True: 0, False: 6]
  |  Branch (1223:51): [True: 0, False: 6]
  ------------------
 1224|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "PIN length exceeds buffer");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1225|      0|		}
 1226|      6|		memcpy(pin_data, data->pin1.data, data->pin1.len);
 1227|      6|		offs += data->pin1.pad_length;
 1228|      6|	}
 1229|      6|	if (data->pin2.data && data->pin2.len) {
  ------------------
  |  Branch (1229:6): [True: 6, False: 0]
  |  Branch (1229:25): [True: 6, False: 0]
  ------------------
 1230|      6|		if (data->pin2.len + offs > sizeof(pin_data)) {
  ------------------
  |  Branch (1230:7): [True: 0, False: 6]
  ------------------
 1231|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "PIN2 length exceeds buffer");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1232|      0|		}
 1233|      6|		memcpy(pin_data + offs, data->pin2.data, data->pin2.len);
 1234|      6|	}
 1235|       |
 1236|      6|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, offs ? 0x00 : 0x01, data->pin_reference);
  ------------------
  |  |  293|      6|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1236:58): [True: 6, False: 0]
  ------------------
 1237|      6|	apdu.data = pin_data;
 1238|      6|	apdu.datalen = offs + data->pin1.pad_length;
 1239|      6|	apdu.lc = offs + data->pin1.pad_length;
 1240|       |
 1241|      6|	rv = sc_transmit_apdu(card, &apdu);
 1242|      6|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1243|      5|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1244|       |
 1245|      5|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1246|      5|}
card-authentic.c:authentic_pin_get_policy:
 1293|    285|{
 1294|    285|	struct sc_context *ctx = card->ctx;
 1295|    285|	struct sc_apdu apdu;
 1296|    285|	unsigned char rbuf[0x100];
 1297|    285|	int ii, rv;
 1298|       |
 1299|    285|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    285|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    285|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    285|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    285|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1300|    285|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1301|       |
 1302|    285|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|    285|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1303|    288|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1303:12): [True: 287, False: 1]
  ------------------
 1304|    287|		apdu.le = sizeof(rbuf);
 1305|    287|		apdu.resp = rbuf;
 1306|    287|		apdu.resplen = sizeof(rbuf);
 1307|       |
 1308|    287|		rv = sc_transmit_apdu(card, &apdu);
 1309|    287|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    287|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    287|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    287|	int _ret = (r); \
  |  |  |  |  168|    287|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 275]
  |  |  |  |  ------------------
  |  |  |  |  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|    287|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 275]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1310|    275|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1311|       |
 1312|    275|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    275|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1312:7): [True: 272, False: 3]
  ------------------
 1313|    272|			break;
 1314|       |
 1315|      3|		apdu.cla = 0x80;
 1316|      3|	}
 1317|    273|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  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: 53, False: 220]
  |  |  |  |  ------------------
  |  |  |  |  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|    273|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 220]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1318|       |
 1319|    220|	data->pin1.tries_left = -1;
 1320|       |
 1321|    220|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1322|    220|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  174|    220|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    220|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    220|	int _ret = (r); \
  |  |  |  |  168|    220|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 156, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  169|    156|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    156|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    156|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    156|		return _ret; \
  |  |  |  |  172|    156|	} \
  |  |  |  |  173|    220|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1323|       |
 1324|     64|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     64|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1325|     64|	data->pin1.offset = 5;
 1326|     64|	data->pin1.pad_char = 0xFF;
 1327|     64|	data->pin1.pad_length = data->pin1.max_length;
 1328|     64|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|     64|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1329|       |
 1330|     64|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     64|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1331|       |
 1332|     64|	sc_log(ctx, "PIN policy: size max/min/pad %zu/%zu/%zu, tries max/left %i/%i",
  ------------------
  |  |   71|     64|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1333|     64|			data->pin1.max_length, data->pin1.min_length, data->pin1.pad_length,
 1334|     64|			data->pin1.max_tries, data->pin1.tries_left);
 1335|       |
 1336|     64|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     64|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     64|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     64|	int _ret = r; \
  |  |  |  |  155|     64|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  157|     64|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     64|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1337|     64|}
card-authentic.c:authentic_parse_credential_data:
  286|    220|{
  287|    220|	unsigned char *data;
  288|    220|	size_t data_len;
  289|    220|	int rv, ii;
  290|    220|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|    220|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|    220|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|    220|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  174|    220|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    220|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    220|	int _ret = (r); \
  |  |  |  |  168|    220|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 123, False: 97]
  |  |  |  |  ------------------
  |  |  |  |  169|    123|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    123|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    123|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    123|		return _ret; \
  |  |  |  |  172|    123|	} \
  |  |  |  |  173|    220|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|     97|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|     97|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|     97|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  174|     97|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     97|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     97|	int _ret = (r); \
  |  |  |  |  168|     97|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  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|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|     88|	pin_cmd->pin1.max_tries = *data;
  298|       |
  299|     88|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|     88|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  300|     88|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 76]
  |  |  |  |  ------------------
  |  |  |  |  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|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|     76|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (301:6): [True: 73, False: 3]
  |  Branch (301:22): [True: 7, False: 66]
  ------------------
  302|      7|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      7|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  303|     69|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (303:11): [True: 66, False: 3]
  |  Branch (303:27): [True: 65, False: 1]
  |  Branch (303:41): [True: 58, False: 7]
  ------------------
  304|     58|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|     58|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  305|     11|	else
  306|     11|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Parse optional ACLs when requested */
  309|     65|	if (acls) {
  ------------------
  |  Branch (309:6): [True: 0, False: 65]
  ------------------
  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|     65|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|     65|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  341|     65|	if (!rv)   {
  ------------------
  |  Branch (341:6): [True: 1, False: 64]
  ------------------
  342|      1|		blob = data;
  343|      1|		blob_len = data_len;
  344|       |
  345|      1|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH, &data, &data_len);
  ------------------
  |  |   97|      1|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH	0x83
  ------------------
  346|      1|		LOG_TEST_RET(ctx, rv, "failed to get PIN max.length value");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|      0|		pin_cmd->pin1.max_length = *data;
  348|       |
  349|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH, &data, &data_len);
  ------------------
  |  |   98|      0|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH	0x84
  ------------------
  350|      0|		LOG_TEST_RET(ctx, rv, "failed to get PIN min.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|		pin_cmd->pin1.min_length = *data;
  352|      0|	}
  353|       |
  354|     64|	return SC_SUCCESS;
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  355|     65|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1865|  1.84k|{
 1866|  1.84k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.84k|#define SC_SUCCESS				0
  ------------------
 1867|       |
 1868|  1.84k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.84k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.84k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.84k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.84k]
  |  |  ------------------
  ------------------
 1869|       |
 1870|  1.84k|	if (was_reset > 0
  ------------------
  |  Branch (1870:6): [True: 0, False: 1.84k]
  ------------------
 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|  1.84k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.84k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.84k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.84k|	int _ret = r; \
  |  |  |  |  155|  1.84k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.84k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.84k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.84k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.84k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.84k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.84k|	return _ret; \
  |  |  |  |  163|  1.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1876|  1.84k|}

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

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

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

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

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

sc_get_cedulauy_driver:
  292|  15.7k|{
  293|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  294|       |
  295|  15.7k|	if (iso_ops == NULL)
  ------------------
  |  Branch (295:6): [True: 1, False: 15.7k]
  ------------------
  296|      1|		iso_ops = iso_drv->ops;
  297|       |
  298|  15.7k|	cedulauy_ops = *iso_ops;
  299|  15.7k|	cedulauy_ops.match_card = cedulauy_match_card;
  300|  15.7k|	cedulauy_ops.init = cedulauy_init;
  301|  15.7k|	cedulauy_ops.select_file = cedulauy_select_file;
  302|  15.7k|	cedulauy_ops.set_security_env = cedulauy_set_security_env;
  303|  15.7k|	cedulauy_ops.compute_signature = cedulauy_compute_signature;
  304|  15.7k|	cedulauy_ops.decipher = NULL; /* the signing key is sign-only */
  305|  15.7k|	cedulauy_ops.get_challenge = cedulauy_get_challenge;
  306|  15.7k|	cedulauy_ops.logout = cedulauy_logout;
  307|  15.7k|	cedulauy_ops.card_reader_lock_obtained = cedulauy_card_reader_lock_obtained;
  308|       |
  309|  15.7k|	return &cedulauy_drv;
  310|  15.7k|}
card-cedulauy.c:cedulauy_match_card:
  112|  8.09k|{
  113|  8.09k|	int i = _sc_match_atr(card, cedulauy_atrs, &card->type);
  114|       |
  115|  8.09k|	if (i < 0)
  ------------------
  |  Branch (115:6): [True: 8.02k, False: 68]
  ------------------
  116|  8.02k|		return 0;
  117|     68|	card->name = cedulauy_atrs[i].name;
  118|     68|	return 1;
  119|  8.09k|}
card-cedulauy.c:cedulauy_init:
  123|     68|{
  124|     68|	unsigned long flags;
  125|     68|	int r;
  126|       |
  127|     68|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     68|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     68|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     68|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     68|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|       |
  129|     68|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     68|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  130|       |
  131|     68|	r = cedulauy_select_app(card);
  132|     68|	LOG_TEST_RET(card->ctx, r, "Cannot select the eID application");
  ------------------
  |  |  174|     68|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     68|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     68|	int _ret = (r); \
  |  |  |  |  168|     68|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  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|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 54]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     54|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  111|     54|#define SC_ALGORITHM_RSA_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|     54|#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|     54|#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|     54|#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|     54|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  138|     54|	r = _sc_card_add_rsa_alg(card, 2048, flags, 0);
  139|       |
  140|     54|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     54|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     54|	int _ret = r; \
  |  |  |  |  155|     54|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|     54|}
card-cedulauy.c:cedulauy_select_app:
   97|     68|{
   98|     68|	struct sc_apdu apdu;
   99|     68|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  100|       |
  101|     68|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     68|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     68|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     68|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     68|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  102|       |
  103|     68|	sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x04, 0x00,
  104|     68|			cedulauy_aid, sizeof cedulauy_aid, resp, sizeof resp);
  105|     68|	SC_TRANSMIT_TEST_RET(card, apdu, "Cannot select the eID application");
  ------------------
  |  |   90|     68|	do { \
  |  |   91|     68|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|     68|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     68|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     68|	int _ret = (r); \
  |  |  |  |  |  |  168|     68|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 6, False: 62]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     68|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 62]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|     68|		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: 8, False: 54]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  |  |  172|      8|	} \
  |  |  |  |  |  |  173|     62|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 54]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|     62|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 54]
  |  |  ------------------
  ------------------
  106|       |
  107|     54|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     54|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     54|	int _ret = r; \
  |  |  |  |  155|     54|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  108|     54|}
card-cedulauy.c:cedulauy_select_file:
  170|    174|{
  171|    174|	struct sc_path path = *in_path;
  172|       |
  173|    174|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    174|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    174|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    174|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    174|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 174]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|    174|	if (path.aid.len == sizeof cedulauy_aid && 0 == memcmp(path.aid.value, cedulauy_aid, sizeof cedulauy_aid)) {
  ------------------
  |  Branch (175:6): [True: 120, False: 54]
  |  Branch (175:45): [True: 120, False: 0]
  ------------------
  176|       |		/* swallow cedula AID, it is always selected via init() */
  177|    120|		path.aid.len = 0;
  178|    120|	}
  179|    174|	if (path.type == SC_PATH_TYPE_PATH && path.len >= 2 && path.value[0] == 0x3F && path.value[1] == 0x00) {
  ------------------
  |  |  119|    348|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (179:6): [True: 54, False: 120]
  |  Branch (179:40): [True: 54, False: 0]
  |  Branch (179:57): [True: 54, False: 0]
  |  Branch (179:82): [True: 54, False: 0]
  ------------------
  180|       |		/* swallow MF, everything resides within the Application DF */
  181|     54|		memmove(path.value, path.value + 2, path.len - 2);
  182|     54|		path.len -= 2;
  183|     54|	}
  184|    174|	if (path.type == SC_PATH_TYPE_PATH && path.len == 0) {
  ------------------
  |  |  119|    348|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:6): [True: 54, False: 120]
  |  Branch (184:40): [True: 0, False: 54]
  ------------------
  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|    174|	LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, &path, file_out));
  ------------------
  |  |  164|    174|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    174|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    174|	int _ret = r; \
  |  |  |  |  155|    174|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 174, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    174|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    161|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 161, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|    174|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    174|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    174|	return _ret; \
  |  |  |  |  163|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  191|    174|}
card-cedulauy.c:cedulauy_set_security_env:
  196|     13|{
  197|     13|	struct sc_apdu apdu;
  198|       |	/* MSE SET, Digital Signature Template: key reference and algorithm */
  199|     13|	unsigned char mse_data[] = {0x84, 0x01, 0xFF, 0x80, 0x01, CEDULAUY_ALGO_RSA_PKCS1};
  ------------------
  |  |   61|     13|#define CEDULAUY_ALGO_RSA_PKCS1	       (CEDULAUY_ALGO_HASH_NONE | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   57|     13|#define CEDULAUY_ALGO_HASH_NONE	  0x00 /* DigestInfo built in software */
  |  |  ------------------
  |  |               #define CEDULAUY_ALGO_RSA_PKCS1	       (CEDULAUY_ALGO_HASH_NONE | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   59|     13|#define CEDULAUY_ALGO_PAD_PKCS1	  0x02 /* PKCS#1 v1.5 */
  |  |  ------------------
  ------------------
  200|       |
  201|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|       |
  203|     13|	if (env == NULL)
  ------------------
  |  Branch (203:6): [True: 0, False: 13]
  ------------------
  204|     13|		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|     13|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   48|     13|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (205:6): [True: 0, False: 13]
  ------------------
  206|     13|		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|     13|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT) && env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   60|     13|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
              	if ((env->flags & SC_SEC_ENV_ALG_PRESENT) && env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|     13|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (207:6): [True: 13, False: 0]
  |  Branch (207:47): [True: 0, False: 13]
  ------------------
  208|     13|		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|     13|	if (env->key_ref_len != 1)
  ------------------
  |  Branch (209:6): [True: 0, False: 13]
  ------------------
  210|     13|		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|     13|	mse_data[2] = env->key_ref[0];
  213|     13|	if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256)
  ------------------
  |  |  138|     13|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (213:6): [True: 4, False: 9]
  ------------------
  214|      4|		mse_data[5] = CEDULAUY_ALGO_RSA_PKCS1_SHA256;
  ------------------
  |  |   62|      4|#define CEDULAUY_ALGO_RSA_PKCS1_SHA256 (CEDULAUY_ALGO_HASH_SHA256 | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   58|      4|#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|      4|#define CEDULAUY_ALGO_PAD_PKCS1	  0x02 /* PKCS#1 v1.5 */
  |  |  ------------------
  ------------------
  215|       |
  216|     13|	sc_format_apdu_ex(&apdu, card->cla, 0x22, 0x41, 0xB6,
  217|     13|			mse_data, sizeof mse_data, NULL, 0);
  218|     13|	SC_TRANSMIT_TEST_RET(card, apdu, "MSE SET DST 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: 3, False: 9]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  |  |  172|      3|	} \
  |  |  |  |  |  |  173|     12|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|     12|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 9]
  |  |  ------------------
  ------------------
  219|       |
  220|      9|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  221|      9|}
card-cedulauy.c:cedulauy_compute_signature:
  226|      9|{
  227|      9|	struct sc_apdu apdu;
  228|      9|	unsigned char sbuf[64];
  229|      9|	unsigned char rbuf[256]; /* RSA 2048 */
  230|      9|	size_t offs = 0;
  231|       |
  232|      9|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      9|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      9|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|       |
  234|      9|	if (data == NULL || out == NULL)
  ------------------
  |  Branch (234:6): [True: 0, False: 9]
  |  Branch (234:22): [True: 0, False: 9]
  ------------------
  235|      9|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|      9|	if (datalen == 0 || datalen > sizeof(sbuf) - 2)
  ------------------
  |  Branch (241:6): [True: 0, False: 9]
  |  Branch (241:22): [True: 0, False: 9]
  ------------------
  242|      9|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|      9|				"Unsupported hash/DigestInfo length");
  244|       |
  245|       |	/* PSO HASH: load the digest */
  246|      9|	sbuf[offs++] = 0x90;
  247|      9|	sbuf[offs++] = (unsigned char)datalen;
  248|      9|	memcpy(sbuf + offs, data, datalen);
  249|      9|	offs += datalen;
  250|      9|	sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x90, 0xA0, sbuf, offs, NULL, 0);
  251|      9|	SC_TRANSMIT_TEST_RET(card, apdu, "PSO HASH failed");
  ------------------
  |  |   90|      9|	do { \
  |  |   91|      9|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "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]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|      9|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  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: 2, False: 6]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|      8|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|      8|	} 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_get_challenge:
  266|    245|{
  267|       |	/* As on other IAS/ECC cards, GET CHALLENGE only handles a length of 8 */
  268|    245|	unsigned char rbuf[8];
  269|    245|	int r;
  270|       |
  271|    245|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    245|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    245|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    245|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    245|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 245]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|       |
  273|    245|	r = iso_ops->get_challenge(card, rbuf, sizeof rbuf);
  274|    245|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE failed");
  ------------------
  |  |  174|    245|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    245|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    245|	int _ret = (r); \
  |  |  |  |  168|    245|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 219]
  |  |  |  |  ------------------
  |  |  |  |  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|    245|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 219]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  275|       |
  276|    219|	if (len < (size_t)r)
  ------------------
  |  Branch (276:6): [True: 1, False: 218]
  ------------------
  277|      1|		r = (int)len;
  278|    219|	memcpy(rnd, rbuf, (size_t)r);
  279|       |
  280|    219|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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: 1, False: 218]
  |  |  |  |  ------------------
  |  |  |  |  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|    218|	} else { \
  |  |  |  |  159|    218|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    218|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    218|	} \
  |  |  |  |  162|    219|	return _ret; \
  |  |  |  |  163|    219|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|    219|}
card-cedulauy.c:cedulauy_card_reader_lock_obtained:
  145|    316|{
  146|    316|	if (was_reset)
  ------------------
  |  Branch (146:6): [True: 0, False: 316]
  ------------------
  147|    316|		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|    316|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    316|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    316|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    316|	int _ret = r; \
  |  |  |  |  155|    316|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 316, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    316|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 316]
  |  |  |  |  ------------------
  |  |  |  |  157|    316|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    316|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    316|	return _ret; \
  |  |  |  |  163|    316|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  149|    316|}

coolkey_get_attribute_data:
  602|  1.02k|{
  603|       |	/* handle the V0 objects first */
  604|  1.02k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  1.02k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (604:6): [True: 184, False: 839]
  ------------------
  605|    184|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  606|    184|	}
  607|       |
  608|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  609|    839|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|    839|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (609:6): [True: 0, False: 839]
  ------------------
  610|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  611|      0|	}
  612|       |
  613|    839|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  614|       |
  615|    839|}
coolkey_compare_id:
  757|   141k|{
  758|   141k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (758:6): [True: 0, False: 141k]
  |  Branch (758:19): [True: 0, False: 141k]
  ------------------
  759|      0|		return 1;
  760|   141k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  761|   141k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  762|   141k|}
coolkey_list_meter:
  765|  5.90k|size_t coolkey_list_meter(const void *el) {
  766|  5.90k|	return sizeof(sc_cardctl_coolkey_object_t);
  767|  5.90k|}
coolkey_fill_object:
 1364|  27.6k|{
 1365|  27.6k|	int r;
 1366|  27.6k|	size_t buf_len = obj->length;
 1367|  27.6k|	u8 *new_obj_data = NULL;
 1368|  27.6k|	sc_cardctl_coolkey_object_t *obj_entry;
 1369|  27.6k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  27.6k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1370|       |
 1371|  27.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  27.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  27.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  27.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  27.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 27.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1372|       |
 1373|  27.6k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1373:6): [True: 0, False: 27.6k]
  ------------------
 1374|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1375|      0|	}
 1376|  27.6k|	new_obj_data = malloc(buf_len);
 1377|  27.6k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1377:6): [True: 0, False: 27.6k]
  ------------------
 1378|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1379|      0|	}
 1380|  27.6k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1381|  27.6k|				priv->nonce, sizeof(priv->nonce));
 1382|  27.6k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1382:6): [True: 24.8k, False: 2.72k]
  ------------------
 1383|  24.8k|		free(new_obj_data);
 1384|  24.8k|		if (r < 0) {
  ------------------
  |  Branch (1384:7): [True: 24.8k, False: 0]
  ------------------
 1385|  24.8k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  24.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  24.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  24.8k|	int _ret = r; \
  |  |  |  |  155|  24.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  24.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  24.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 24.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  24.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  24.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  24.8k|	return _ret; \
  |  |  |  |  163|  24.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1386|  24.8k|		}
 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|  2.72k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1390|  2.72k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1390:6): [True: 0, False: 2.72k]
  ------------------
 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|  2.72k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1394:6): [True: 0, False: 2.72k]
  ------------------
 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|  2.72k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1400:6): [True: 0, False: 2.72k]
  ------------------
 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|  2.72k|	obj_entry->data = new_obj_data;
 1405|  2.72k|	obj->data = new_obj_data;
 1406|  2.72k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.72k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.72k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.72k|	int _ret = r; \
  |  |  |  |  155|  2.72k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.72k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.72k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.72k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.72k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.72k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.72k|	return _ret; \
  |  |  |  |  163|  2.72k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1407|  2.72k|}
coolkey_find_object_by_template:
 1496|  1.82k|{
 1497|  1.82k|	list_t *list;
 1498|  1.82k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1499|  1.82k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.82k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1500|  1.82k|	int i, r;
 1501|  1.82k|	unsigned int tmp_pos = (unsigned int) -1;
 1502|       |
 1503|  1.82k|	list = &priv->objects_list;
 1504|  1.82k|	if (list->iter_active) {
  ------------------
  |  Branch (1504:6): [True: 1.82k, False: 0]
  ------------------
 1505|       |		/* workaround missing functionality of second iterator */
 1506|  1.82k|		tmp_pos = list->iter_pos;
 1507|  1.82k|		list_iterator_stop(list);
 1508|  1.82k|	}
 1509|       |
 1510|  1.82k|	list_iterator_start(list);
 1511|  30.5k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1511:9): [True: 29.4k, False: 1.16k]
  ------------------
 1512|  29.4k|		sc_cardctl_coolkey_attribute_t attribute;
 1513|  29.4k|		current = list_iterator_next(list);
 1514|  29.4k|		attribute.object = current;
 1515|       |
 1516|  32.4k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1516:13): [True: 31.7k, False: 667]
  ------------------
 1517|  31.7k|			attribute.attribute_type = template[i].attribute_type;
 1518|  31.7k|			r = coolkey_find_attribute(card, &attribute);
 1519|  31.7k|			if (r < 0) {
  ------------------
  |  Branch (1519:8): [True: 16.8k, False: 14.8k]
  ------------------
 1520|  16.8k|				break;
 1521|  16.8k|			}
 1522|  14.8k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1522:8): [True: 251, False: 14.6k]
  ------------------
 1523|    251|				break;
 1524|    251|			}
 1525|  14.6k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1525:8): [True: 0, False: 14.6k]
  ------------------
 1526|      0|				break;
 1527|      0|			}
 1528|  14.6k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1528:8): [True: 11.6k, False: 2.99k]
  ------------------
 1529|  14.6k|							attribute.attribute_length) != 0) {
 1530|  11.6k|				break;
 1531|  11.6k|			}
 1532|  14.6k|		}
 1533|       |		/* just return the first one */
 1534|  29.4k|		if (i == count) {
  ------------------
  |  Branch (1534:7): [True: 667, False: 28.7k]
  ------------------
 1535|    667|			rv = current;
 1536|    667|			break;
 1537|    667|		}
 1538|  29.4k|	}
 1539|       |
 1540|  1.82k|	list_iterator_stop(list);
 1541|  1.82k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1541:6): [True: 1.82k, False: 0]
  ------------------
 1542|       |		/* workaround missing functionality of second iterator */
 1543|  1.82k|		list_iterator_start(list);
 1544|  22.7k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1544:10): [True: 22.5k, False: 190]
  |  Branch (1544:41): [True: 20.9k, False: 1.63k]
  ------------------
 1545|  20.9k|			(void) list_iterator_next(list);
 1546|  1.82k|	}
 1547|  1.82k|	return rv;
 1548|  1.82k|}
sc_get_coolkey_driver:
 2467|  15.7k|{
 2468|  15.7k|	return sc_get_driver();
 2469|  15.7k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  517|    184|{
  518|       |	/* we need to manually detect types CK_ULONG */
  519|    184|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|    184|#define COOLKEY_V0_OBJECT 0
  ------------------
  520|    184|	int r;
  521|    184|	size_t len;
  522|       |
  523|    184|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1049|    184|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  524|    184|	attr_out->attribute_length = 0;
  525|    184|	attr_out->attribute_value = NULL;
  526|       |
  527|    184|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  528|    184|	if (r < 0) {
  ------------------
  |  Branch (528:6): [True: 0, False: 184]
  ------------------
  529|      0|		return r;
  530|      0|	}
  531|    184|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (531:6): [True: 48, False: 136]
  ------------------
  532|     48|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     48|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  533|     48|	}
  534|    136|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|    136|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     24|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (534:6): [True: 112, False: 24]
  |  Branch (534:34): [True: 0, False: 24]
  ------------------
  535|    115|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     24|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (535:14): [True: 3, False: 21]
  ------------------
  536|    115|		if (len != 4) {
  ------------------
  |  Branch (536:7): [True: 81, False: 34]
  ------------------
  537|     81|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     81|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  538|     81|		}
  539|     34|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1050|     34|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  540|     34|	}
  541|       |	/* return the length and the data */
  542|     55|	attr_out->attribute_length = len;
  543|     55|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  544|     55|	return SC_SUCCESS;
  ------------------
  |  |   28|     55|#define SC_SUCCESS				0
  ------------------
  545|    136|}
card-coolkey.c:coolkey_get_attribute_type:
  410|  12.0k|{
  411|  12.0k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  412|       |
  413|  12.0k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  414|  12.0k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  350|  6.19k|{
  351|  6.19k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  352|       |	/* don't reference beyond our buffer */
  353|  6.19k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (353:6): [True: 303, False: 5.88k]
  ------------------
  354|    303|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    303|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  355|    303|	}
  356|  5.88k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  357|  5.88k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.88k|#define SC_SUCCESS				0
  ------------------
  358|  6.19k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  552|    839|{
  553|    839|	int r;
  554|    839|	size_t len;
  555|    839|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  556|       |
  557|    839|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (557:6): [True: 12, False: 827]
  ------------------
  558|     12|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     12|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  559|     12|	}
  560|       |
  561|       |	/* we must have type V1. Process according to data type */
  562|    827|	switch (attribute_head->attribute_data_type) {
  563|       |	/* ULONG has implied length of 4 */
  564|    106|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|    106|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (564:2): [True: 106, False: 721]
  ------------------
  565|    106|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (565:7): [True: 10, False: 96]
  ------------------
  566|     10|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     10|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  567|     10|		}
  568|     96|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1050|     96|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  569|     96|		attr_out->attribute_length = 4;
  570|     96|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  571|     96|		return SC_SUCCESS;
  ------------------
  |  |   28|     96|#define SC_SUCCESS				0
  ------------------
  572|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  573|       |	/* return type STRING for BOOLS */
  574|    154|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|    154|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (574:2): [True: 154, False: 673]
  ------------------
  575|    154|		attr_out->attribute_length = 1;
  576|    154|		attr_out->attribute_value =  &coolkey_static_false;
  577|    154|		return SC_SUCCESS;
  ------------------
  |  |   28|    154|#define SC_SUCCESS				0
  ------------------
  578|     37|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|     37|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (578:2): [True: 37, False: 790]
  ------------------
  579|     37|		attr_out->attribute_length = 1;
  580|     37|		attr_out->attribute_value =  &coolkey_static_true;
  581|     37|		return SC_SUCCESS;
  ------------------
  |  |   28|     37|#define SC_SUCCESS				0
  ------------------
  582|       |	/* string type has encoded length */
  583|    263|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|    263|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (583:2): [True: 263, False: 564]
  ------------------
  584|    263|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  585|    263|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|    263|#define SC_SUCCESS				0
  ------------------
  |  Branch (585:7): [True: 10, False: 253]
  ------------------
  586|     10|			return r;
  587|     10|		}
  588|    253|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (588:7): [True: 77, False: 176]
  ------------------
  589|     77|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     77|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  590|     77|		}
  591|    176|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  592|    176|		attr_out->attribute_length = len;
  593|    176|		return SC_SUCCESS;
  ------------------
  |  |   28|    176|#define SC_SUCCESS				0
  ------------------
  594|    267|	default:
  ------------------
  |  Branch (594:2): [True: 267, False: 560]
  ------------------
  595|    267|		break;
  596|    827|	}
  597|    267|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    267|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  598|    827|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  313|   131k|{
  314|   131k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  315|       |
  316|   131k|	*len = 0;
  317|       |	/* don't reference beyond our buffer */
  318|   131k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (318:6): [True: 122k, False: 8.96k]
  ------------------
  319|   122k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   122k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  320|   122k|	}
  321|  8.96k|	switch (attribute_head->attribute_data_type) {
  322|  2.75k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  2.75k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (322:2): [True: 2.75k, False: 6.20k]
  ------------------
  323|  2.75k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (323:7): [True: 70, False: 2.68k]
  ------------------
  324|     70|			break;
  325|     70|		}
  326|  2.68k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  327|  2.68k|		if (encoded_len) {
  ------------------
  |  Branch (327:7): [True: 2.42k, False: 253]
  ------------------
  328|  2.42k|			*len += 2;
  329|  2.42k|		}
  330|  2.68k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.68k|#define SC_SUCCESS				0
  ------------------
  331|    657|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|    657|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (331:2): [True: 657, False: 8.30k]
  ------------------
  332|  1.10k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|  1.10k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (332:2): [True: 450, False: 8.51k]
  ------------------
  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.10k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (335:10): [True: 1.10k, False: 0]
  ------------------
  336|  1.10k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.10k|#define SC_SUCCESS				0
  ------------------
  337|      0|		break;
  338|  4.43k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|  4.43k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (338:2): [True: 4.43k, False: 4.52k]
  ------------------
  339|  4.43k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  340|  4.43k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.43k|#define SC_SUCCESS				0
  ------------------
  341|    665|	default:
  ------------------
  |  Branch (341:2): [True: 665, False: 8.29k]
  ------------------
  342|    665|		break;
  343|  8.96k|	}
  344|    735|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    735|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  345|  8.96k|}
card-coolkey.c:coolkey_read_object:
 1096|  27.6k|{
 1097|  27.6k|	coolkey_read_object_param_t params;
 1098|  27.6k|	u8 *out_ptr;
 1099|  27.6k|	size_t left = 0;
 1100|  27.6k|	size_t len;
 1101|  27.6k|	int r;
 1102|       |
 1103|  27.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  27.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  27.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  27.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 27.6k]
  |  |  ------------------
  ------------------
 1104|       |
 1105|  27.6k|	ulong2bebytes(&params.object_id[0], object_id);
 1106|       |
 1107|  27.6k|	out_ptr = out_buf;
 1108|  27.6k|	left = out_len;
 1109|  30.1k|	do {
 1110|  30.1k|		ulong2bebytes(&params.offset[0], offset);
 1111|  30.1k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   70|  30.1k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 23.1k, False: 7.02k]
  |  |  ------------------
  ------------------
 1112|  30.1k|		len = left;
 1113|  30.1k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   72|  30.1k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   88|  30.1k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1114|  30.1k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1115|  30.1k|		if (r < 0) {
  ------------------
  |  Branch (1115:7): [True: 24.3k, False: 5.79k]
  ------------------
 1116|  24.3k|			goto fail;
 1117|  24.3k|		}
 1118|       |		/* sanity check to make sure we don't overflow left */
 1119|  5.79k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1119:7): [True: 149, False: 5.64k]
  |  Branch (1119:23): [True: 386, False: 5.26k]
  ------------------
 1120|    535|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    535|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1121|    535|			goto fail;
 1122|    535|		}
 1123|  5.26k|		out_ptr += len;
 1124|  5.26k|		offset += len;
 1125|  5.26k|		left -= len;
 1126|  5.26k|	} while (left != 0);
  ------------------
  |  Branch (1126:11): [True: 2.50k, False: 2.76k]
  ------------------
 1127|       |
 1128|  2.76k|	return (int)out_len;
 1129|       |
 1130|  24.9k|fail:
 1131|  24.9k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  24.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  24.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  24.9k|	int _ret = r; \
  |  |  |  |  155|  24.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  24.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|  24.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 24.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  24.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  24.9k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  24.9k|	return _ret; \
  |  |  |  |  163|  24.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1132|  24.9k|}
card-coolkey.c:coolkey_apdu_io:
  912|  53.6k|{
  913|  53.6k|	int r;
  914|  53.6k|	sc_apdu_t apdu;
  915|  53.6k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  916|  53.6k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  917|  53.6k|	u8 *rbuf;
  918|  53.6k|	size_t rbuflen;
  919|  53.6k|	int cse = 0;
  920|       |
  921|       |
  922|  53.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  53.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  53.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  53.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 53.6k]
  |  |  ------------------
  ------------------
  923|       |
  924|  53.6k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  53.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__
  |  |  ------------------
  ------------------
  925|  53.6k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  926|       |
  927|  53.6k|	rbuf = rbufinitbuf;
  928|  53.6k|	rbuflen = sizeof(rbufinitbuf);
  929|       |
  930|       |	/* if caller provided a buffer and length */
  931|  53.6k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (931:6): [True: 42.9k, False: 10.7k]
  |  Branch (931:17): [True: 42.9k, False: 0]
  |  Branch (931:29): [True: 42.9k, False: 0]
  |  Branch (931:43): [True: 42.0k, False: 892]
  ------------------
  932|  42.0k|		rbuf = *recvbuf;
  933|  42.0k|		rbuflen = *recvbuflen;
  934|  42.0k|	}
  935|       |
  936|  53.6k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (936:6): [True: 40.9k, False: 12.7k]
  |  Branch (936:17): [True: 0, False: 12.7k]
  ------------------
  937|  40.9k|		if (recvbuf) {
  ------------------
  |  Branch (937:7): [True: 30.1k, False: 10.7k]
  ------------------
  938|  30.1k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  30.1k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  939|  30.1k|		} else {
  940|  10.7k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  10.7k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  941|  10.7k|		}
  942|  40.9k|	} else {
  943|  12.7k|		if (recvbuf) {
  ------------------
  |  Branch (943:7): [True: 12.7k, False: 0]
  ------------------
  944|  12.7k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  12.7k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  945|  12.7k|		} else {
  946|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  947|      0|		}
  948|  12.7k|	}
  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|  53.6k|	if (nonce) {
  ------------------
  |  Branch (955:6): [True: 30.1k, False: 23.4k]
  ------------------
  956|  30.1k|		u8 *buf = rsendbuf;
  957|  30.1k|		if (sendbuf) {
  ------------------
  |  Branch (957:7): [True: 30.1k, False: 0]
  ------------------
  958|  30.1k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   70|  30.1k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 30.1k, False: 0]
  |  |  ------------------
  ------------------
  959|  30.1k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  960|  30.1k|			buf += sendbuflen;
  961|  30.1k|		}
  962|  30.1k|		memcpy(buf, nonce, nonce_len);
  963|  30.1k|		sendbuflen += nonce_len;
  964|  30.1k|		sendbuf =rsendbuf;
  965|  30.1k|	}
  966|       |
  967|  53.6k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  968|       |
  969|  53.6k|	apdu.lc = sendbuflen;
  970|  53.6k|	apdu.datalen = sendbuflen;
  971|  53.6k|	apdu.data = sendbuf;
  972|       |
  973|       |
  974|       |	/* coolkey uses non-standard classes */
  975|  53.6k|	apdu.cla = cla;
  976|       |
  977|  53.6k|	if (recvbuf) {
  ------------------
  |  Branch (977:6): [True: 42.9k, False: 10.7k]
  ------------------
  978|  42.9k|		apdu.resp = rbuf;
  979|  42.9k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (979:13): [True: 6.17k, False: 36.7k]
  ------------------
  980|  42.9k|		apdu.resplen = rbuflen;
  981|  42.9k|	} else {
  982|  10.7k|		 apdu.resp =  rbuf;
  983|  10.7k|		 apdu.le = 0;
  984|  10.7k|		 apdu.resplen = 0;
  985|  10.7k|	}
  986|       |
  987|  53.6k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  53.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__
  |  |  ------------------
  ------------------
  988|  53.6k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  989|       |
  990|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  991|  53.6k|	r = sc_transmit_apdu(card, &apdu);
  992|       |
  993|  53.6k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  53.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__
  |  |  ------------------
  ------------------
  994|  53.6k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  995|       |
  996|  53.6k|	if (r < 0) {
  ------------------
  |  Branch (996:6): [True: 1.04k, False: 52.6k]
  ------------------
  997|  1.04k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  1.04k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  998|  1.04k|		goto err;
  999|  1.04k|	}
 1000|  52.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1001|  52.6k|	if (r < 0) {
  ------------------
  |  Branch (1001:6): [True: 32.6k, False: 19.9k]
  ------------------
 1002|  32.6k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  32.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__
  |  |  ------------------
  ------------------
 1003|  32.6k|		goto err;
 1004|  32.6k|	}
 1005|       |
 1006|  19.9k|	if (recvbuflen) {
  ------------------
  |  Branch (1006:6): [True: 17.3k, False: 2.65k]
  ------------------
 1007|  17.3k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1007:7): [True: 17.3k, False: 0]
  |  Branch (1007:18): [True: 0, False: 17.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|  17.3k|		*recvbuflen =  apdu.resplen;
 1016|  17.3k|		r = (int)*recvbuflen;
 1017|  17.3k|	}
 1018|       |
 1019|  53.6k|err:
 1020|  53.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  53.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  53.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  53.6k|	int _ret = r; \
  |  |  |  |  155|  53.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36.7k, False: 16.9k]
  |  |  |  |  ------------------
  |  |  |  |  156|  36.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|  33.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33.6k, False: 3.05k]
  |  |  |  |  ------------------
  |  |  |  |  157|  36.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  36.7k|	} else { \
  |  |  |  |  159|  16.9k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.9k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.9k|	} \
  |  |  |  |  162|  53.6k|	return _ret; \
  |  |  |  |  163|  53.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1021|  53.6k|}
card-coolkey.c:coolkey_find_object_by_id:
  825|  14.0k|{
  826|  14.0k|	int pos;
  827|  14.0k|	static sc_cardctl_coolkey_object_t cmp = {{
  828|  14.0k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  14.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  829|  14.0k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  14.0k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  14.0k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  830|  14.0k|	}, 0, 0, NULL};
  831|       |
  832|  14.0k|	cmp.id = object_id;
  833|  14.0k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (833:6): [True: 6.72k, False: 7.36k]
  ------------------
  834|  6.72k|		return NULL;
  835|       |
  836|  7.36k|	return list_get_at(list, pos);
  837|  14.0k|}
card-coolkey.c:coolkey_find_attribute:
 1416|  79.6k|{
 1417|  79.6k|	u8 object_record_type;
 1418|  79.6k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1419|  79.6k|	const u8 *obj = attribute->object->data;
 1420|  79.6k|	const u8 *attr = NULL;
 1421|  79.6k|	size_t buf_len = attribute->object->length;
 1422|  79.6k|	coolkey_object_header_t *object_head;
 1423|  79.6k|	int attribute_count,i;
 1424|  79.6k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1049|  79.6k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1425|  79.6k|	attribute->attribute_length = 0;
 1426|  79.6k|	attribute->attribute_value = NULL;
 1427|       |
 1428|  79.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  79.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  79.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  79.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  79.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 79.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1429|       |
 1430|  79.6k|	if (obj == NULL) {
  ------------------
  |  Branch (1430:6): [True: 27.5k, False: 52.1k]
  ------------------
 1431|       |		/* cast away const so we can cache the data value */
 1432|  27.5k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1433|  27.5k|		if (r < 0) {
  ------------------
  |  Branch (1433:7): [True: 24.8k, False: 2.70k]
  ------------------
 1434|  24.8k|			return r;
 1435|  24.8k|		}
 1436|  2.70k|		obj = attribute->object->data;
 1437|  2.70k|		if (obj == NULL) {
  ------------------
  |  Branch (1437:7): [True: 0, False: 2.70k]
  ------------------
 1438|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1439|      0|		}
 1440|  2.70k|	}
 1441|       |
 1442|       |	/* should be a static assert so we catch this at compile time */
 1443|  79.6k|	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|  54.8k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1445:6): [True: 123, False: 54.6k]
  ------------------
 1446|    123|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    123|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1447|    123|	}
 1448|  54.6k|	object_head = (coolkey_object_header_t *)obj;
 1449|  54.6k|	object_record_type = object_head->record_type;
 1450|       |	/* make sure it's a type we recognize */
 1451|  54.6k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  54.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  5.45k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1451:6): [True: 5.45k, False: 49.2k]
  |  Branch (1451:51): [True: 3.23k, False: 2.21k]
  ------------------
 1452|  3.23k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  3.23k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1453|  3.23k|	}
 1454|       |
 1455|       |	/*
 1456|       |	 * now loop through all the attributes in the list. first find the start of the list
 1457|       |	 */
 1458|  51.4k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1459|  51.4k|	if (attr == NULL) {
  ------------------
  |  Branch (1459:6): [True: 75, False: 51.3k]
  ------------------
 1460|     75|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     75|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1461|     75|	}
 1462|  51.3k|	buf_len -= (attr-obj);
 1463|       |
 1464|       |	/* now get the count */
 1465|  51.3k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1466|  62.2k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1466:12): [True: 12.5k, False: 49.6k]
  ------------------
 1467|  12.5k|		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.5k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1469:7): [True: 0, False: 12.5k]
  |  Branch (1469:31): [True: 676, False: 11.8k]
  ------------------
 1470|    676|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    676|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1471|    676|		}
 1472|       |		/* does the attribute match the one we are looking for */
 1473|  11.8k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1473:7): [True: 1.02k, False: 10.8k]
  ------------------
 1474|       |			/* yup, return it */
 1475|  1.02k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1476|  1.02k|		}
 1477|       |		/* go to the next attribute on the list */
 1478|  10.8k|		buf_len -= record_len;
 1479|  10.8k|		attr += record_len;
 1480|  10.8k|	}
 1481|       |	/* not find in attribute list, check the fixed attribute record */
 1482|  49.6k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  49.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1482:6): [True: 47.6k, False: 2.03k]
  ------------------
 1483|  47.6k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1484|       |
 1485|  47.6k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1486|  47.6k|	}
 1487|  2.03k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  2.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.03k|	int _ret = r; \
  |  |  |  |  155|  2.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.03k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.03k|	return _ret; \
  |  |  |  |  163|  2.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1488|  2.03k|}
card-coolkey.c:coolkey_attribute_start:
  421|  52.7k|{
  422|  52.7k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  229|  52.7k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (422:18): [True: 49.2k, False: 3.46k]
  ------------------
  423|  52.7k|			sizeof(coolkey_v0_object_header_t);
  424|       |
  425|  52.7k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  52.7k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  3.46k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (425:6): [True: 3.46k, False: 49.2k]
  |  Branch (425:51): [True: 0, False: 3.46k]
  ------------------
  426|      0|		return NULL;
  427|      0|	}
  428|  52.7k|	if (offset > buf_len) {
  ------------------
  |  Branch (428:6): [True: 75, False: 52.6k]
  ------------------
  429|     75|		return NULL;
  430|     75|	}
  431|  52.6k|	return obj + offset;
  432|  52.7k|}
card-coolkey.c:coolkey_get_attribute_count:
  502|  51.3k|{
  503|  51.3k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  51.3k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (503:6): [True: 2.21k, False: 49.1k]
  ------------------
  504|  2.21k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  505|  2.21k|	}
  506|  49.1k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  49.1k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (506:6): [True: 0, False: 49.1k]
  ------------------
  507|      0|		return 0;
  508|      0|	}
  509|  49.1k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  510|  49.1k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  440|  2.21k|{
  441|  2.21k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  442|  2.21k|	const u8 *attr;
  443|  2.21k|	int count = 0;
  444|  2.21k|	size_t attribute_data_len;
  445|       |
  446|       |	/* make sure we have enough of the object to read the record_type */
  447|  2.21k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (447:6): [True: 972, False: 1.24k]
  ------------------
  448|    972|		return 0;
  449|    972|	}
  450|       |	/*
  451|       |	 * now loop through all the attributes in the list. first find the start of the list
  452|       |	 */
  453|  1.24k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|  1.24k|#define COOLKEY_V0_OBJECT 0
  ------------------
  454|  1.24k|	if (attr == NULL) {
  ------------------
  |  Branch (454:6): [True: 0, False: 1.24k]
  ------------------
  455|      0|		return 0;
  456|      0|	}
  457|       |
  458|  1.24k|	buf_len -= (attr-obj);
  459|  1.24k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  460|  1.24k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (460:6): [True: 150, False: 1.09k]
  ------------------
  461|    150|		return 0;
  462|    150|	}
  463|       |
  464|  4.18k|	while (attribute_data_len) {
  ------------------
  |  Branch (464:9): [True: 3.35k, False: 836]
  ------------------
  465|  3.35k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  466|       |
  467|  3.35k|		if (len == 0) {
  ------------------
  |  Branch (467:7): [True: 0, False: 3.35k]
  ------------------
  468|      0|			break;
  469|      0|		}
  470|       |		/*  This is an error in the token data, don't parse the last attribute */
  471|  3.35k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (471:7): [True: 260, False: 3.09k]
  ------------------
  472|    260|			break;
  473|    260|		}
  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|  3.09k|		if (len > buf_len)
  ------------------
  |  Branch (479:7): [True: 0, False: 3.09k]
  ------------------
  480|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  481|  3.09k|		count++;
  482|  3.09k|		attr += len;
  483|  3.09k|		buf_len -= len;
  484|  3.09k|		attribute_data_len -= len;
  485|  3.09k|	}
  486|  1.09k|	return count;
  487|  1.09k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  380|  6.00k|{
  381|  6.00k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  382|  6.00k|	size_t len;
  383|  6.00k|	int r;
  384|       |
  385|  6.00k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  386|  6.00k|	if (r < 0) {
  ------------------
  |  Branch (386:6): [True: 303, False: 5.70k]
  ------------------
  387|    303|		return buf_len; /* skip to the end, ignore the rest of the record */
  388|    303|	}
  389|  5.70k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  5.70k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 608, False: 5.09k]
  |  |  ------------------
  ------------------
  390|  6.00k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  491|  49.1k|{
  492|  49.1k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  493|       |
  494|  49.1k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (494:6): [True: 42.3k, False: 6.82k]
  ------------------
  495|  42.3k|		return 0;
  496|  42.3k|	}
  497|  6.82k|	return bebytes2ushort(object_head->attribute_count);
  498|  49.1k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  394|  12.5k|{
  395|  12.5k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  12.5k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (395:6): [True: 2.65k, False: 9.86k]
  ------------------
  396|  2.65k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  397|  2.65k|	}
  398|  9.86k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  9.86k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (398:6): [True: 0, False: 9.86k]
  ------------------
  399|      0|		return buf_len; /* skip to the end */
  400|      0|	}
  401|  9.86k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  402|  9.86k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  364|   131k|{
  365|   131k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  366|   131k|	size_t len = 0;
  367|   131k|	int r;
  368|       |
  369|   131k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  370|   131k|	if (r < 0) {
  ------------------
  |  Branch (370:6): [True: 123k, False: 7.97k]
  ------------------
  371|   123k|		return buf_len; /* skip to the end, ignore the rest of the record */
  372|   123k|	}
  373|       |
  374|  7.97k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  7.97k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 552, False: 7.42k]
  |  |  ------------------
  ------------------
  375|   131k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  674|  47.6k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  675|  47.6k|	unsigned long cka_id = fixed_attributes & 0xf;
  676|  47.6k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  677|  47.6k|	unsigned long mask, bit;
  678|       |
  679|  47.6k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  47.6k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (679:6): [True: 5.91k, False: 41.7k]
  ------------------
  680|  5.91k|		attr_out->attribute_length = 1;
  681|  5.91k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  682|  5.91k|		return SC_SUCCESS;
  ------------------
  |  |   28|  5.91k|#define SC_SUCCESS				0
  ------------------
  683|  5.91k|	}
  684|  41.7k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  41.7k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (684:6): [True: 14.1k, False: 27.6k]
  ------------------
  685|  14.1k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1050|  14.1k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  686|  14.1k|		attr_out->attribute_length = 4;
  687|  14.1k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  688|  14.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  14.1k|#define SC_SUCCESS				0
  ------------------
  689|  14.1k|	}
  690|       |	/* If it matched, it must be one of the booleans */
  691|  27.6k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  692|  27.6k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  693|       |	/* attribute isn't in the list */
  694|  27.6k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (694:6): [True: 10.5k, False: 17.0k]
  ------------------
  695|  10.5k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  10.5k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  696|  10.5k|	}
  697|  17.0k|	attr_out->attribute_length = 1;
  698|  17.0k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (698:30): [True: 3.84k, False: 13.1k]
  ------------------
  699|  17.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  17.0k|#define SC_SUCCESS				0
  ------------------
  700|  27.6k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  620|  27.6k|{
  621|  27.6k|	switch(type) {
  622|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (622:2): [True: 0, False: 27.6k]
  ------------------
  623|  1.98k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  1.98k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (623:2): [True: 1.98k, False: 25.6k]
  ------------------
  624|  2.09k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  2.09k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (624:2): [True: 2.09k, False: 25.5k]
  ------------------
  625|  1.31k|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|  1.31k|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (625:2): [True: 1.31k, False: 26.2k]
  ------------------
  626|  1.31k|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|  1.31k|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (626:2): [True: 1.31k, False: 26.2k]
  ------------------
  627|  1.31k|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|  1.31k|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (627:2): [True: 1.31k, False: 26.2k]
  ------------------
  628|  1.31k|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|  1.31k|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (628:2): [True: 1.31k, False: 26.2k]
  ------------------
  629|  1.31k|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|  1.31k|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (629:2): [True: 1.31k, False: 26.2k]
  ------------------
  630|  1.31k|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|  1.31k|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (630:2): [True: 1.31k, False: 26.2k]
  ------------------
  631|  1.31k|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|  1.31k|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (631:2): [True: 1.31k, False: 26.2k]
  ------------------
  632|  1.31k|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|  1.31k|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (632:2): [True: 1.31k, False: 26.2k]
  ------------------
  633|  1.31k|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|  1.31k|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (633:2): [True: 1.31k, False: 26.2k]
  ------------------
  634|  1.31k|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|  1.31k|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (634:2): [True: 1.31k, False: 26.2k]
  ------------------
  635|  1.31k|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|  1.31k|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (635:2): [True: 1.31k, False: 26.2k]
  ------------------
  636|  1.31k|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|  1.31k|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (636:2): [True: 1.31k, False: 26.2k]
  ------------------
  637|  1.31k|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|  1.31k|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (637:2): [True: 1.31k, False: 26.2k]
  ------------------
  638|  1.31k|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|  1.31k|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (638:2): [True: 1.31k, False: 26.2k]
  ------------------
  639|  5.12k|	default: break;
  ------------------
  |  Branch (639:2): [True: 5.12k, False: 22.4k]
  ------------------
  640|  27.6k|	}
  641|  5.12k|	return 0; /* return no bits */
  642|  27.6k|}
card-coolkey.c:sc_get_driver:
 2440|  15.7k|{
 2441|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2442|       |
 2443|  15.7k|	coolkey_ops = *iso_drv->ops;
 2444|  15.7k|	coolkey_ops.match_card = coolkey_match_card;
 2445|  15.7k|	coolkey_ops.init = coolkey_init;
 2446|  15.7k|	coolkey_ops.finish = coolkey_finish;
 2447|       |
 2448|  15.7k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2449|  15.7k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2450|  15.7k|	coolkey_ops.read_binary = coolkey_read_binary;
 2451|  15.7k|	coolkey_ops.write_binary = coolkey_write_binary;
 2452|  15.7k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2453|  15.7k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2454|  15.7k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2455|  15.7k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2456|  15.7k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2457|  15.7k|	coolkey_ops.check_sw = coolkey_check_sw;
 2458|  15.7k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2459|  15.7k|	coolkey_ops.logout = coolkey_logout;
 2460|  15.7k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2461|       |
 2462|  15.7k|	return &coolkey_drv;
 2463|  15.7k|}
card-coolkey.c:coolkey_match_card:
 2279|  7.72k|{
 2280|  7.72k|	int r;
 2281|       |
 2282|  7.72k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.72k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.72k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.72k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.72k]
  |  |  ------------------
  ------------------
 2283|       |
 2284|  7.72k|	r = coolkey_select_applet(card);
 2285|  7.72k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  7.72k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2285:6): [True: 1.04k, False: 6.67k]
  ------------------
 2286|  1.04k|		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.04k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.04k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   79|  1.04k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2293|  1.04k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   72|  1.04k|#define COOLKEY_CLASS           0xb0
  ------------------
 2294|  1.04k|		apdu.le = 0x00;
 2295|  1.04k|		apdu.resplen = 0;
 2296|  1.04k|		apdu.resp = NULL;
 2297|  1.04k|		r = sc_transmit_apdu(card, &apdu);
 2298|  1.04k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.09k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2298:7): [True: 1.04k, False: 1]
  |  Branch (2298:26): [True: 1.00k, False: 41]
  |  Branch (2298:46): [True: 1.00k, False: 4]
  ------------------
 2299|  1.00k|			return 1;
 2300|  1.00k|		}
 2301|     46|		return 0;
 2302|  1.04k|	}
 2303|  6.67k|	return 0;
 2304|  7.72k|}
card-coolkey.c:coolkey_select_applet:
 1070|  10.7k|{
 1071|  10.7k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1072|  10.7k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   71|  10.7k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   75|  10.7k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1073|  10.7k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1074|  10.7k|}
card-coolkey.c:coolkey_init:
 2308|  1.00k|{
 2309|  1.00k|	int r;
 2310|  1.00k|	unsigned long flags;
 2311|  1.00k|	unsigned long ext_flags;
 2312|  1.00k|	coolkey_private_data_t * priv;
 2313|       |
 2314|  1.00k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.00k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.00k]
  |  |  ------------------
  ------------------
 2315|       |
 2316|  1.00k|	r = coolkey_initialize(card);
 2317|  1.00k|	if (r < 0) {
  ------------------
  |  Branch (2317:6): [True: 312, False: 689]
  ------------------
 2318|    312|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    312|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    312|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    312|	int _ret = r; \
  |  |  |  |  155|    312|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 312, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    312|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    312|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 312, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2319|    312|	}
 2320|       |
 2321|    689|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2322|       |
 2323|       |	/* set Token Major/minor version */
 2324|    689|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    689|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2325|       |
 2326|    689|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2327|    689|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2328|    689|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2329|       |
 2330|    689|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    689|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    689|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    689|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    689|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2331|    689|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    689|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    689|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2332|       |
 2333|    689|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2334|    689|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2335|    689|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2336|       |
 2337|       |
 2338|    689|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    689|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2339|    689|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2339:6): [True: 120, False: 569]
  ------------------
 2340|    120|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    120|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2341|    120|	}
 2342|       |
 2343|    689|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    689|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    689|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    689|	int _ret = r; \
  |  |  |  |  155|    689|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 689, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    689|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 689]
  |  |  |  |  ------------------
  |  |  |  |  157|    689|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    689|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    689|	return _ret; \
  |  |  |  |  163|    689|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2344|    689|}
card-coolkey.c:coolkey_initialize:
 2148|  1.00k|{
 2149|  1.00k|	int r;
 2150|  1.00k|	coolkey_private_data_t *priv = NULL;
 2151|  1.00k|	coolkey_life_cycle_t life_cycle;
 2152|  1.00k|	coolkey_object_info_t object_info;
 2153|  1.00k|	int combined_processed = 0;
 2154|       |
 2155|       |	/* already found? */
 2156|  1.00k|	if (card->drv_data) {
  ------------------
  |  Branch (2156:6): [True: 0, False: 1.00k]
  ------------------
 2157|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2158|      0|	}
 2159|  1.00k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.00k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2160|       |
 2161|  1.00k|	priv = coolkey_new_private_data();
 2162|  1.00k|	if (priv == NULL) {
  ------------------
  |  Branch (2162:6): [True: 0, False: 1.00k]
  ------------------
 2163|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2164|      0|		goto cleanup;
 2165|      0|	}
 2166|  1.00k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2167|  1.00k|	if (r < 0) {
  ------------------
  |  Branch (2167:6): [True: 61, False: 940]
  ------------------
 2168|     61|		goto cleanup;
 2169|     61|	}
 2170|       |
 2171|       |	/* Select a coolkey read the coolkey objects out */
 2172|    940|	r = coolkey_select_applet(card);
 2173|    940|	if (r < 0) {
  ------------------
  |  Branch (2173:6): [True: 13, False: 927]
  ------------------
 2174|     13|		goto cleanup;
 2175|     13|	}
 2176|       |
 2177|    927|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2178|    927|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2179|    927|	priv->pin_count = life_cycle.pin_count;
 2180|    927|	priv->life_cycle = life_cycle.life_cycle;
 2181|       |
 2182|       |	/* walk down the list of objects and read them off the token */
 2183|    927|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  104|    927|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2184|  10.9k|	while (r >= 0) {
  ------------------
  |  Branch (2184:9): [True: 10.0k, False: 854]
  ------------------
 2185|  10.0k|		unsigned long object_id;
 2186|  10.0k|		unsigned long object_len;
 2187|       |
 2188|       |		/* The card did not return what we expected: Lets try other objects */
 2189|  10.0k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2189:7): [True: 11, False: 10.0k]
  ------------------
 2190|     11|			break;
 2191|       |
 2192|       |		/* TODO also look at the ACL... */
 2193|       |
 2194|  10.0k|		object_id = bebytes2ulong(object_info.object_id);
 2195|  10.0k|		object_len = bebytes2ulong(object_info.object_length);
 2196|       |		/* Avoid insanely large data */
 2197|  10.0k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  10.0k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2197:7): [True: 16, False: 10.0k]
  ------------------
 2198|     16|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     16|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2199|     16|			goto cleanup;
 2200|     16|		}
 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|  10.0k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  109|  10.0k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2208:7): [True: 47, False: 9.97k]
  ------------------
 2209|     47|			u8 *object = malloc(object_len);
 2210|     47|			if (object == NULL) {
  ------------------
  |  Branch (2210:8): [True: 0, False: 47]
  ------------------
 2211|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2212|      0|				break;
 2213|      0|			}
 2214|     47|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  109|     47|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2215|     47|				priv->nonce, sizeof(priv->nonce));
 2216|     47|			if (r < 0) {
  ------------------
  |  Branch (2216:8): [True: 16, False: 31]
  ------------------
 2217|     16|				free(object);
 2218|     16|				break;
 2219|     16|			}
 2220|     31|			r = coolkey_process_combined_object(card, priv, object, r);
 2221|     31|			free(object);
 2222|     31|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     31|#define SC_SUCCESS				0
  ------------------
  |  Branch (2222:8): [True: 30, False: 1]
  ------------------
 2223|     30|				break;
 2224|     30|			}
 2225|      1|			combined_processed = 1;
 2226|  9.97k|		} else {
 2227|  9.97k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  9.97k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2228|  9.97k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2229|  9.97k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  9.97k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2229:8): [True: 4.08k, False: 5.89k]
  ------------------
 2230|  4.08k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 2231|  9.97k|		}
 2232|       |
 2233|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2234|  9.97k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  105|  9.97k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2235|  9.97k|	}
 2236|    911|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    911|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2236:6): [True: 199, False: 712]
  ------------------
 2237|       |		/* This means the card does not cooperate at all: bail out */
 2238|    199|		if (r >= 0) {
  ------------------
  |  Branch (2238:7): [True: 11, False: 188]
  ------------------
 2239|     11|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     11|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2240|     11|		}
 2241|    199|		goto cleanup;
 2242|    199|	}
 2243|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2244|    712|	if (!combined_processed) {
  ------------------
  |  Branch (2244:6): [True: 712, False: 0]
  ------------------
 2245|    712|		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|    712|		r = gp_select_card_manager(card);
 2250|    712|		if (r < 0) {
  ------------------
  |  Branch (2250:7): [True: 9, False: 703]
  ------------------
 2251|      9|			goto cleanup;
 2252|      9|		}
 2253|       |
 2254|    703|		r = gp_get_cplc_data(card, &cplc_data);
 2255|    703|		if (r < 0) {
  ------------------
  |  Branch (2255:7): [True: 14, False: 689]
  ------------------
 2256|     14|			goto cleanup;
 2257|     14|		}
 2258|    689|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2259|    689|		priv->token_name = (u8 *)strdup("COOLKEY");
 2260|    689|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2260:7): [True: 0, False: 689]
  ------------------
 2261|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2262|      0|			goto cleanup;
 2263|      0|		}
 2264|    689|		priv->token_name_length = sizeof("COOLKEY")-1;
 2265|    689|	}
 2266|    689|	card->drv_data = priv;
 2267|    689|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    689|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    689|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    689|	int _ret = r; \
  |  |  |  |  155|    689|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 689, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    689|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 689]
  |  |  |  |  ------------------
  |  |  |  |  157|    689|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    689|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    689|	return _ret; \
  |  |  |  |  163|    689|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2268|       |
 2269|    312|cleanup:
 2270|    312|	if (priv) {
  ------------------
  |  Branch (2270:6): [True: 312, False: 0]
  ------------------
 2271|    312|		coolkey_free_private_data(priv);
 2272|    312|	}
 2273|    312|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    312|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    312|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    312|	int _ret = r; \
  |  |  |  |  155|    312|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 312, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    312|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    312|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 312, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2274|    312|}
card-coolkey.c:coolkey_new_private_data:
  772|  1.00k|{
  773|  1.00k|	coolkey_private_data_t *priv;
  774|       |
  775|       |	/* allocate priv and zero all the fields */
  776|  1.00k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  777|  1.00k|	if (!priv)
  ------------------
  |  Branch (777:6): [True: 0, False: 1.00k]
  ------------------
  778|      0|		return NULL;
  779|       |
  780|       |	/* set other fields as appropriate */
  781|  1.00k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|  1.00k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  782|  1.00k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (782:6): [True: 0, False: 1.00k]
  ------------------
  783|  1.00k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.00k]
  ------------------
  784|  1.00k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (784:6): [True: 0, False: 1.00k]
  ------------------
  785|      0|		coolkey_free_private_data(priv);
  786|      0|		return NULL;
  787|      0|	}
  788|       |
  789|  1.00k|	return priv;
  790|  1.00k|}
card-coolkey.c:coolkey_get_life_cycle:
 1028|  1.00k|{
 1029|  1.00k|	coolkey_status_t status;
 1030|  1.00k|	u8 *receive_buf;
 1031|  1.00k|	size_t receive_len;
 1032|  1.00k|	int len;
 1033|       |
 1034|  1.00k|	receive_len = sizeof(*life_cycle);
 1035|  1.00k|	receive_buf = (u8 *)life_cycle;
 1036|  1.00k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|  1.00k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|  1.00k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1037|  1.00k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1038|  1.00k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1038:6): [True: 933, False: 68]
  ------------------
 1039|    933|		return SC_SUCCESS;
  ------------------
  |  |   28|    933|#define SC_SUCCESS				0
  ------------------
 1040|    933|	}
 1041|       |
 1042|     68|	receive_len = 1;
 1043|     68|	receive_buf = &life_cycle->life_cycle;
 1044|     68|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|     68|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|     68|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1045|     68|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1046|     68|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1046:6): [True: 44, False: 24]
  ------------------
 1047|     44|		return len;
 1048|     44|	}
 1049|     24|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1049:6): [True: 2, False: 22]
  ------------------
 1050|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1051|      2|	}
 1052|     22|	receive_len = sizeof(status);
 1053|     22|	receive_buf = (u8 *)&status;
 1054|     22|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   72|     22|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   79|     22|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1055|     22|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1056|     22|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1056:6): [True: 7, False: 15]
  ------------------
 1057|      7|		return len;
 1058|      7|	}
 1059|     15|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1059:6): [True: 8, False: 7]
  ------------------
 1060|      8|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      8|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1061|      8|	}
 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|     15|}
card-coolkey.c:coolkey_list_object:
 2135|  10.9k|{
 2136|  10.9k|	u8 *rbuf = (u8 *) object_info;
 2137|  10.9k|	size_t rbuflen = sizeof(*object_info);
 2138|       |
 2139|  10.9k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   72|  10.9k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   81|  10.9k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2140|  10.9k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2141|       |
 2142|  10.9k|}
card-coolkey.c:coolkey_process_combined_object:
 2000|     31|{
 2001|     31|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2002|     31|	unsigned short compressed_offset;
 2003|     31|	unsigned short compressed_length;
 2004|     31|	unsigned short compressed_type;
 2005|     31|	size_t object_offset;
 2006|     31|	unsigned short object_count;
 2007|     31|	coolkey_decompressed_header_t *decompressed_header;
 2008|     31|	u8 *decompressed_object = NULL;
 2009|     31|	size_t decompressed_object_len = 0;
 2010|     31|	int free_decompressed = 0;
 2011|     31|	int i, r;
 2012|       |
 2013|     31|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2013:6): [True: 1, False: 30]
  ------------------
 2014|      1|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2015|      1|	}
 2016|     30|	compressed_offset = bebytes2ushort(header->compression_offset);
 2017|     30|	compressed_length = bebytes2ushort(header->compression_length);
 2018|     30|	compressed_type   = bebytes2ushort(header->compression_type);
 2019|       |
 2020|     30|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2020:6): [True: 4, False: 26]
  ------------------
 2021|      4|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      4|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2022|      4|	}
 2023|       |
 2024|       |	/* store the CUID */
 2025|     26|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2026|       |
 2027|     26|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  180|     26|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2027:6): [True: 1, False: 25]
  ------------------
 2028|      1|#ifdef ENABLE_ZLIB
 2029|      1|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|      1|#define COMPRESSION_AUTO	0
  ------------------
 2030|      1|		if (r)
  ------------------
  |  Branch (2030:7): [True: 1, False: 0]
  ------------------
 2031|      1|			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|     25|	}  else {
 2038|     25|		decompressed_object =&object[compressed_offset];
 2039|     25|		decompressed_object_len = (size_t) compressed_length;
 2040|     25|	}
 2041|       |
 2042|     25|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2043|       |
 2044|     25|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2044:6): [True: 4, False: 21]
  ------------------
 2045|      4|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      4|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2046|      4|		goto done;
 2047|      4|	}
 2048|     21|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2049|     21|	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|     21|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2057:6): [True: 0, False: 21]
  ------------------
 2058|     21|		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|     21|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2063:6): [True: 2, False: 19]
  ------------------
 2064|     21|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2065|      2|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      2|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2066|      2|		goto done;
 2067|      2|	}
 2068|       |
 2069|       |	/* store the token name in the priv structure so the emulator can set it */
 2070|     19|	free(priv->token_name);
 2071|     19|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2072|     19|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2072:6): [True: 0, False: 19]
  ------------------
 2073|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2074|      0|		goto done;
 2075|      0|	}
 2076|     19|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2077|     19|							decompressed_header->token_name_length);
 2078|     19|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2079|     19|	priv->token_name_length = decompressed_header->token_name_length;
 2080|       |
 2081|     19|	if (object_count > decompressed_object_len / sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2081:6): [True: 9, False: 10]
  ------------------
 2082|      9|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      9|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2083|      9|		goto done;
 2084|      9|	}
 2085|       |
 2086|     28|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2086:12): [True: 27, False: 1]
  ------------------
 2087|     27|		u8 *current_object = NULL;
 2088|     27|		coolkey_combined_object_header_t *object_header = NULL;
 2089|     27|		unsigned long object_id;
 2090|     27|		int current_object_len;
 2091|       |
 2092|       |		/* Can we read the object header at all? */
 2093|     27|		if ((object_offset + sizeof(coolkey_combined_object_header_t)) > decompressed_object_len) {
  ------------------
  |  Branch (2093:7): [True: 7, False: 20]
  ------------------
 2094|      7|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      7|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2095|      7|			goto done;
 2096|      7|		}
 2097|       |
 2098|     20|		current_object = &decompressed_object[object_offset];
 2099|     20|		object_header = (coolkey_combined_object_header_t *)current_object;
 2100|       |
 2101|       |		/* Parse object ID */
 2102|     20|		object_id = bebytes2ulong(object_header->object_id);
 2103|       |
 2104|       |		/* figure out how big it is */
 2105|     20|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2106|     20|		if (r < 0) {
  ------------------
  |  Branch (2106:7): [True: 0, False: 20]
  ------------------
 2107|      0|			goto done;
 2108|      0|		}
 2109|     20|		if ((size_t)r + object_offset > decompressed_object_len) {
  ------------------
  |  Branch (2109:7): [True: 0, False: 20]
  ------------------
 2110|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2111|      0|			goto done;
 2112|      0|		}
 2113|     20|		current_object_len = r;
 2114|     20|		object_offset += current_object_len;
 2115|       |
 2116|       |		/* record this object */
 2117|     20|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2118|     20|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2119|     20|		if (r) {
  ------------------
  |  Branch (2119:7): [True: 2, False: 18]
  ------------------
 2120|      2|			goto done;
 2121|      2|		}
 2122|       |
 2123|     20|	}
 2124|      1|	r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2125|       |
 2126|     26|done:
 2127|     26|	if (free_decompressed) {
  ------------------
  |  Branch (2127:6): [True: 0, False: 26]
  ------------------
 2128|      0|		free(decompressed_object);
 2129|      0|	}
 2130|     26|	return r;
 2131|      1|}
card-coolkey.c:coolkey_v1_get_object_length:
  706|     20|{
  707|     20|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  708|     20|	int attribute_count;
  709|     20|	u8 *current_attribute;
  710|     20|	int j;
  711|     20|	size_t len;
  712|       |
  713|     20|	len = sizeof(coolkey_combined_object_header_t);
  714|     20|	if (buf_len <= len) {
  ------------------
  |  Branch (714:6): [True: 0, False: 20]
  ------------------
  715|      0|		return (int)buf_len;
  716|      0|	}
  717|     20|	attribute_count = bebytes2ushort(object_head->attribute_count);
  718|     20|	buf_len -= len;
  719|       |
  720|   121k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (720:45): [True: 121k, False: 20]
  ------------------
  721|   121k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  722|       |
  723|   121k|		len += attribute_len;
  724|   121k|		current_attribute += attribute_len;
  725|   121k|		buf_len -= attribute_len;
  726|   121k|	}
  727|     20|	return (int)len;
  728|     20|}
card-coolkey.c:coolkey_add_object:
 1959|  9.99k|{
 1960|  9.99k|	sc_cardctl_coolkey_object_t new_object;
 1961|  9.99k|	int r;
 1962|       |
 1963|  9.99k|	memset(&new_object, 0, sizeof(new_object));
 1964|  9.99k|	new_object.path = coolkey_template_path;
 1965|  9.99k|	new_object.path.len = 4;
 1966|  9.99k|	ulong2bebytes(new_object.path.value, object_id);
 1967|  9.99k|	new_object.id = object_id;
 1968|  9.99k|	new_object.length = object_length;
 1969|       |
 1970|       |	/* The object ID needs to be unique */
 1971|  9.99k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1971:6): [True: 4.08k, False: 5.90k]
  ------------------
 1972|  4.08k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  4.08k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1973|  4.08k|	}
 1974|       |
 1975|  5.90k|	if (object_data) {
  ------------------
  |  Branch (1975:6): [True: 18, False: 5.89k]
  ------------------
 1976|     18|		new_object.data = malloc(object_length + add_v1_record);
 1977|     18|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1977:7): [True: 0, False: 18]
  ------------------
 1978|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1979|      0|		}
 1980|     18|		if (add_v1_record) {
  ------------------
  |  Branch (1980:7): [True: 18, False: 0]
  ------------------
 1981|     18|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  229|     18|#define COOLKEY_V1_OBJECT 1
  ------------------
 1982|     18|			new_object.length++;
 1983|     18|		}
 1984|     18|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1985|     18|	}
 1986|       |
 1987|  5.90k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 1988|  5.90k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  5.90k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1988:6): [True: 0, False: 5.90k]
  ------------------
 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|  5.90k|	return r;
 1995|  5.90k|}
card-coolkey.c:coolkey_add_object_to_list:
  816|  5.90k|{
  817|  5.90k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (817:6): [True: 0, False: 5.90k]
  ------------------
  818|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  819|  5.90k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.90k|#define SC_SUCCESS				0
  ------------------
  820|  5.90k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1078|    689|{
 1079|    689|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1080|    689|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1081|    689|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1082|    689|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1083|    689|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1084|    689|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1085|    689|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1086|    689|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1087|    689|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1088|    689|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1089|    689|}
card-coolkey.c:coolkey_free_private_data:
  793|  1.00k|{
  794|  1.00k|	list_t *l = &priv->objects_list;
  795|  1.00k|	sc_cardctl_coolkey_object_t *o;
  796|       |
  797|       |	/* Clean up the allocated memory in the items */
  798|  1.00k|	list_iterator_start(l);
  799|  6.91k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (799:9): [True: 5.90k, False: 1.00k]
  ------------------
  800|  5.90k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  801|  5.90k|		free(o->data);
  802|  5.90k|		o->data = NULL;
  803|  5.90k|	}
  804|  1.00k|	list_iterator_stop(l);
  805|       |
  806|  1.00k|	list_destroy(&priv->objects_list);
  807|  1.00k|	free(priv->token_name);
  808|  1.00k|	free(priv);
  809|  1.00k|	return;
  810|  1.00k|}
card-coolkey.c:coolkey_finish:
 1947|    689|{
 1948|    689|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    689|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1949|       |
 1950|    689|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    689|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    689|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    689|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 689]
  |  |  ------------------
  ------------------
 1951|    689|	if (priv) {
  ------------------
  |  Branch (1951:6): [True: 689, False: 0]
  ------------------
 1952|    689|		coolkey_free_private_data(priv);
 1953|    689|	}
 1954|    689|	return SC_SUCCESS;
  ------------------
  |  |   28|    689|#define SC_SUCCESS				0
  ------------------
 1955|    689|}
card-coolkey.c:coolkey_select_file:
 1900|  2.06k|{
 1901|  2.06k|	int r;
 1902|  2.06k|	struct sc_file *file = NULL;
 1903|  2.06k|	coolkey_private_data_t *priv;
 1904|  2.06k|	unsigned long object_id;
 1905|       |
 1906|  2.06k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1906:6): [True: 0, False: 2.06k]
  |  Branch (1906:22): [True: 0, False: 2.06k]
  ------------------
 1907|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1908|       |
 1909|  2.06k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.06k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.06k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.06k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.06k]
  |  |  ------------------
  ------------------
 1910|       |
 1911|  2.06k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  2.06k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1912|       |
 1913|  2.06k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1913:6): [True: 1, False: 2.06k]
  ------------------
 1914|      1|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      1|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1915|      1|	}
 1916|  2.06k|	r = coolkey_select_applet(card);
 1917|  2.06k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.06k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1917:6): [True: 1.38k, False: 680]
  ------------------
 1918|  1.38k|		return r;
 1919|  1.38k|	}
 1920|    680|	object_id = bebytes2ulong(in_path->value);
 1921|    680|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1922|    680|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1922:6): [True: 666, False: 14]
  ------------------
 1923|    666|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    666|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1924|    666|	}
 1925|       |
 1926|     14|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|     14|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1927|     14|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  111|     14|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1927:6): [True: 0, False: 14]
  ------------------
 1928|      0|		priv->key_id = coolkey_get_key_id(object_id);
 1929|      0|	}
 1930|     14|	if (file_out) {
  ------------------
  |  Branch (1930:6): [True: 13, False: 1]
  ------------------
 1931|     13|		file = sc_file_new();
 1932|     13|		if (file == NULL)
  ------------------
  |  Branch (1932:7): [True: 0, False: 13]
  ------------------
 1933|     13|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1934|     13|		file->path = *in_path;
 1935|       |		/* this could be like the FCI */
 1936|     13|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     13|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1937|     13|		file->shareable = 0;
 1938|     13|		file->ef_structure = 0;
 1939|     13|		file->size = priv->obj->length;
 1940|     13|		*file_out = file;
 1941|     13|	}
 1942|       |
 1943|     14|	return SC_SUCCESS;
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
 1944|     14|}
card-coolkey.c:coolkey_class:
 1873|     14|static u8 coolkey_class(unsigned long object_id) {
 1874|     14|	return (object_id >> 24) & 0xff;
 1875|     14|}
card-coolkey.c:coolkey_get_challenge:
 1611|    758|{
 1612|    758|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    758|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    758|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    758|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    758|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 758]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1613|       |
 1614|    758|	if (len > COOLKEY_MAX_CHUNK_SIZE)
  ------------------
  |  |   68|    758|#define COOLKEY_MAX_CHUNK_SIZE 240 /* must be less than 255-8 */
  ------------------
  |  Branch (1614:6): [True: 44, False: 714]
  ------------------
 1615|     44|		len = COOLKEY_MAX_CHUNK_SIZE;
  ------------------
  |  |   68|     44|#define COOLKEY_MAX_CHUNK_SIZE 240 /* must be less than 255-8 */
  ------------------
 1616|       |
 1617|    758|	LOG_TEST_RET(card->ctx,
  ------------------
  |  |  174|    758|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    758|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    758|	int _ret = (r); \
  |  |  |  |  168|    758|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 262, False: 496]
  |  |  |  |  ------------------
  |  |  |  |  169|    262|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    262|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    262|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    262|		return _ret; \
  |  |  |  |  172|    262|	} \
  |  |  |  |  173|    758|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 496]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1618|    496|			coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_RANDOM, 0, 0,
 1619|    496|				NULL, 0, &rnd, &len,  NULL, 0),
 1620|    496|			"Could not get challenge");
 1621|       |
 1622|    496|	LOG_FUNC_RETURN(card->ctx, (int) len);
  ------------------
  |  |  164|    496|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    496|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    496|	int _ret = r; \
  |  |  |  |  155|    496|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 495]
  |  |  |  |  ------------------
  |  |  |  |  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|    495|	} else { \
  |  |  |  |  159|    495|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    495|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    495|	} \
  |  |  |  |  162|    496|	return _ret; \
  |  |  |  |  163|    496|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1623|    496|}
card-coolkey.c:coolkey_read_binary:
 1180|     37|{
 1181|     37|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     37|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1182|     37|	int r = 0;
 1183|     37|	size_t len;
 1184|     37|	u8 *data = NULL;
 1185|       |
 1186|     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]
  |  |  ------------------
  ------------------
 1187|     37|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1187:6): [True: 0, False: 37]
  ------------------
 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|     37|	if (priv->obj->data) {
  ------------------
  |  Branch (1192:6): [True: 25, False: 12]
  ------------------
 1193|     25|		sc_log(card->ctx, "returning cached value idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1194|     25|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     25|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 19, False: 6]
  |  |  ------------------
  ------------------
 1195|     25|		memcpy(buf, &priv->obj->data[idx], len);
 1196|     25|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|     25|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     25|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     25|	int _ret = r; \
  |  |  |  |  155|     25|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     25|	} else { \
  |  |  |  |  159|     25|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     25|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     25|	} \
  |  |  |  |  162|     25|	return _ret; \
  |  |  |  |  163|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1197|     25|	}
 1198|       |
 1199|     12|	sc_log(card->ctx, "clearing cache idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1200|       |
 1201|     12|	data = malloc(priv->obj->length);
 1202|     12|	if (data == NULL) {
  ------------------
  |  Branch (1202:6): [True: 0, False: 12]
  ------------------
 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|     12|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1209|     12|		priv->nonce, sizeof(priv->nonce));
 1210|     12|	if (r < 0)
  ------------------
  |  Branch (1210:6): [True: 5, False: 7]
  ------------------
 1211|      5|		goto done;
 1212|       |
 1213|      7|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1213:6): [True: 0, False: 7]
  ------------------
 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|      7|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|      7|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 6, False: 1]
  |  |  ------------------
  ------------------
 1220|      7|	memcpy(buf, &data[idx], len);
 1221|      7|	r = (int)len;
 1222|       |	/* cache the data in the object */
 1223|      7|	priv->obj->data=data;
 1224|      7|	data = NULL;
 1225|       |
 1226|     12|done:
 1227|     12|	if (data)
  ------------------
  |  Branch (1227:6): [True: 5, False: 7]
  ------------------
 1228|      5|		free(data);
 1229|     12|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|      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|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1230|     12|}
card-coolkey.c:coolkey_card_ctl:
 1581|  58.6k|{
 1582|  58.6k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  58.6k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1583|       |
 1584|  58.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  58.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  58.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  58.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  58.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 58.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1585|  58.6k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  58.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__
  |  |  ------------------
  ------------------
 1586|       |
 1587|  58.6k|	if (priv == NULL) {
  ------------------
  |  Branch (1587:6): [True: 0, False: 58.6k]
  ------------------
 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|  58.6k|	switch(cmd) {
  ------------------
  |  Branch (1590:9): [True: 57.9k, False: 698]
  ------------------
 1591|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1591:3): [True: 0, False: 58.6k]
  ------------------
 1592|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1593|    689|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1593:3): [True: 689, False: 57.9k]
  ------------------
 1594|    689|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1595|  2.51k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1595:3): [True: 2.51k, False: 56.1k]
  ------------------
 1596|  2.51k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1597|    689|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1597:3): [True: 689, False: 57.9k]
  ------------------
 1598|    689|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1599|  5.45k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1599:3): [True: 5.45k, False: 53.2k]
  ------------------
 1600|  5.45k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1601|    689|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1601:3): [True: 689, False: 57.9k]
  ------------------
 1602|    689|			return coolkey_final_iterator(&priv->objects_list);
 1603|  47.9k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1603:3): [True: 47.9k, False: 10.7k]
  ------------------
 1604|  47.9k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1605|  58.6k|	}
 1606|       |
 1607|    698|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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|    698|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 698, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1608|    698|}
card-coolkey.c:coolkey_get_token_info:
 1326|    689|{
 1327|    689|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    689|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1328|    689|	char *label = NULL;
 1329|    689|	char *manufacturer_id = NULL;
 1330|    689|	char *serial_number = NULL;
 1331|       |
 1332|    689|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    689|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    689|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    689|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    689|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 689]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1333|    689|	label = strdup((char *)priv->token_name);
 1334|    689|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1335|    689|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1336|       |
 1337|    689|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1337:6): [True: 689, False: 0]
  |  Branch (1337:15): [True: 689, False: 0]
  |  Branch (1337:34): [True: 689, False: 0]
  ------------------
 1338|    689|		free(token_info->label);
 1339|    689|		token_info->label = label;
 1340|    689|		free(token_info->manufacturer_id);
 1341|    689|		token_info->manufacturer_id = manufacturer_id;
 1342|    689|		free(token_info->serial_number);
 1343|    689|		token_info->serial_number = serial_number;
 1344|    689|		return SC_SUCCESS;
  ------------------
  |  |   28|    689|#define SC_SUCCESS				0
  ------------------
 1345|    689|	}
 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|    689|}
card-coolkey.c:coolkey_get_manufacturer:
 1297|    689|{
 1298|    689|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1299|    689|	int i;
 1300|    689|	char *buf;
 1301|    689|	const char *manufacturer_string = "%04x Unknown";
 1302|    689|	size_t len;
 1303|    689|	int r;
 1304|       |
 1305|  4.12k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1305:12): [True: 3.44k, False: 687]
  ------------------
 1306|  3.44k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1306:7): [True: 2, False: 3.43k]
  ------------------
 1307|      2|			manufacturer_string = manufacturer_list[i].string;
 1308|      2|			break;
 1309|      2|		}
 1310|  3.44k|	}
 1311|    689|	len = strlen(manufacturer_string)+1;
 1312|    689|	buf= malloc(len);
 1313|    689|	if (buf == NULL) {
  ------------------
  |  Branch (1313:6): [True: 0, False: 689]
  ------------------
 1314|      0|		return NULL;
 1315|      0|	}
 1316|    689|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1317|    689|	if (r < 0) {
  ------------------
  |  Branch (1317:6): [True: 0, False: 689]
  ------------------
 1318|      0|		free(buf);
 1319|      0|		return NULL;
 1320|      0|	}
 1321|    689|	return buf;
 1322|    689|}
card-coolkey.c:coolkey_cuid_to_string:
 1272|    689|{
 1273|    689|	char *buf;
 1274|    689|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1275|    689|	buf = malloc(len);
 1276|    689|	if (buf == NULL) {
  ------------------
  |  Branch (1276:6): [True: 0, False: 689]
  ------------------
 1277|      0|		return NULL;
 1278|      0|	}
 1279|    689|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1280|    689|	return buf;
 1281|    689|}
card-coolkey.c:coolkey_find_object:
 1552|  2.51k|{
 1553|  2.51k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1554|  2.51k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  2.51k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1555|  2.51k|	int r;
 1556|       |
 1557|  2.51k|	switch (fobj->type) {
 1558|    690|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1060|    690|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1558:2): [True: 690, False: 1.82k]
  ------------------
 1559|    690|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1560|    690|		break;
 1561|  1.82k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1061|  1.82k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1561:2): [True: 1.82k, False: 690]
  ------------------
 1562|  1.82k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1563|  1.82k|		break;
 1564|      0|	default:
  ------------------
  |  Branch (1564:2): [True: 0, False: 2.51k]
  ------------------
 1565|      0|		break;
 1566|  2.51k|	}
 1567|  2.51k|	if (obj == NULL) {
  ------------------
  |  Branch (1567:6): [True: 1.30k, False: 1.21k]
  ------------------
 1568|  1.30k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  1.30k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1569|  1.30k|	}
 1570|  1.21k|	if (obj->data == NULL) {
  ------------------
  |  Branch (1570:6): [True: 42, False: 1.17k]
  ------------------
 1571|     42|		r = coolkey_fill_object(card, obj);
 1572|     42|		if (r < 0) {
  ------------------
  |  Branch (1572:7): [True: 24, False: 18]
  ------------------
 1573|     24|			return r;
 1574|     24|		}
 1575|     42|	}
 1576|  1.18k|	fobj->obj = obj;
 1577|  1.18k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.18k|#define SC_SUCCESS				0
  ------------------
 1578|  1.21k|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1245|    689|{
 1246|    689|	*countp = list_size(list);
 1247|    689|	list_iterator_start(list);
 1248|    689|	return SC_SUCCESS;
  ------------------
  |  |   28|    689|#define SC_SUCCESS				0
  ------------------
 1249|    689|}
card-coolkey.c:coolkey_fetch_object:
 1253|  5.45k|{
 1254|  5.45k|	sc_cardctl_coolkey_object_t *ptr;
 1255|  5.45k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1255:6): [True: 0, False: 5.45k]
  ------------------
 1256|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1257|      0|	}
 1258|       |
 1259|  5.45k|	ptr = list_iterator_next(list);
 1260|  5.45k|	*coolkey_obj = *ptr;
 1261|  5.45k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.45k|#define SC_SUCCESS				0
  ------------------
 1262|  5.45k|}
card-coolkey.c:coolkey_final_iterator:
 1266|    689|{
 1267|    689|	list_iterator_stop(list);
 1268|    689|	return SC_SUCCESS;
  ------------------
  |  |   28|    689|#define SC_SUCCESS				0
  ------------------
 1269|    689|}
card-coolkey.c:coolkey_check_sw:
  876|  55.0k|{
  877|  55.0k|	sc_log(card->ctx,
  ------------------
  |  |   71|  55.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  878|  55.0k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  879|       |
  880|  55.0k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (880:6): [True: 22.5k, False: 32.4k]
  |  Branch (880:21): [True: 21.4k, False: 1.10k]
  ------------------
  881|  21.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  21.4k|#define SC_SUCCESS				0
  ------------------
  882|       |
  883|  33.5k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (883:6): [True: 79, False: 33.5k]
  ------------------
  884|     79|		if (sw2 == 0xff) {
  ------------------
  |  Branch (884:7): [True: 13, False: 66]
  ------------------
  885|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  886|     13|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     13|#define SC_ERROR_INTERNAL			-1400
  ------------------
  887|     13|		}
  888|     66|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (888:7): [True: 29, False: 37]
  ------------------
  889|     29|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     29|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  890|     29|		}
  891|     37|		return coolkey_error_codes[sw2].sc_error;
  892|     66|	}
  893|       |
  894|       |	/* iso error */
  895|  33.5k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  896|  33.5k|}
card-coolkey.c:coolkey_pin_cmd:
 2349|    190|{
 2350|    190|	int r;
 2351|    190|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    190|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2352|    190|	size_t rbuflen;
 2353|    190|	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|    190|	switch (data->cmd) {
 2361|    181|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    181|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2361:2): [True: 181, False: 9]
  ------------------
 2362|    181|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2362:7): [True: 0, False: 181]
  ------------------
 2363|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2364|    181|		} else {
 2365|    181|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|    181|#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|    181|			data->pin1.tries_left = 0xf;
 2370|    181|		}
 2371|    181|		r = SC_SUCCESS;
  ------------------
  |  |   28|    181|#define SC_SUCCESS				0
  ------------------
 2372|    181|		break;
 2373|       |
 2374|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2374:2): [True: 0, False: 190]
  ------------------
 2375|      1|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      1|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2375:2): [True: 1, False: 189]
  ------------------
 2376|       |		/* these 2 commands are currently reserved for TPS */
 2377|      1|	default:
  ------------------
  |  Branch (2377:2): [True: 0, False: 190]
  ------------------
 2378|      1|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2379|      1|		break;
 2380|      8|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      8|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2380:2): [True: 8, False: 182]
  ------------------
 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|      8|		rbuflen = sizeof(priv->nonce);
 2386|      8|		rbuf = &priv->nonce[0];
 2387|      8|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   72|      8|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   80|      8|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2388|      8|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2389|      8|			&rbuf, &rbuflen, NULL, 0);
 2390|      8|		if (r < 0) {
  ------------------
  |  Branch (2390:7): [True: 7, False: 1]
  ------------------
 2391|      7|			break;
 2392|      7|		}
 2393|      1|		priv->nonce_valid = 1;
 2394|      1|		r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2395|    190|	}
 2396|    190|	return r;
 2397|    190|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2418|  25.0k|{
 2419|  25.0k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  25.0k|#define SC_SUCCESS				0
  ------------------
 2420|       |
 2421|  25.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  25.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  25.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  25.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 25.0k]
  |  |  ------------------
  ------------------
 2422|       |
 2423|  25.0k|	if (was_reset > 0) {
  ------------------
  |  Branch (2423:6): [True: 0, False: 25.0k]
  ------------------
 2424|      0|		r = coolkey_select_applet(card);
 2425|      0|	}
 2426|       |
 2427|  25.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  25.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  25.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  25.0k|	int _ret = r; \
  |  |  |  |  155|  25.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  25.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 25.0k]
  |  |  |  |  ------------------
  |  |  |  |  157|  25.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  25.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|  25.0k|	return _ret; \
  |  |  |  |  163|  25.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2428|  25.0k|}

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

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

sc_get_dtrust_driver:
 1056|  15.7k|{
 1057|  15.7k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1057:6): [True: 1, False: 15.7k]
  ------------------
 1058|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1059|       |
 1060|  15.7k|	dtrust_ops = *iso_ops;
 1061|  15.7k|	dtrust_ops.match_card = dtrust_match_card;
 1062|  15.7k|	dtrust_ops.init = dtrust_init;
 1063|  15.7k|	dtrust_ops.finish = dtrust_finish;
 1064|  15.7k|	dtrust_ops.pin_cmd = dtrust_pin_cmd;
 1065|  15.7k|	dtrust_ops.set_security_env = dtrust_set_security_env;
 1066|  15.7k|	dtrust_ops.compute_signature = dtrust_compute_signature;
 1067|  15.7k|	dtrust_ops.decipher = dtrust_decipher;
 1068|  15.7k|	dtrust_ops.logout = dtrust_logout;
 1069|       |
 1070|  15.7k|	return &dtrust_drv;
 1071|  15.7k|}
card-dtrust.c:dtrust_match_card:
  234|  15.2k|{
  235|  15.2k|	if (_sc_match_atr(card, dtrust_atrs, &card->type) < 0)
  ------------------
  |  Branch (235:6): [True: 15.1k, False: 62]
  ------------------
  236|  15.1k|		return 0;
  237|       |
  238|     62|	if (_dtrust_match_cardos(card) != SC_SUCCESS)
  ------------------
  |  |   28|     62|#define SC_SUCCESS				0
  ------------------
  |  Branch (238:6): [True: 62, False: 0]
  ------------------
  239|     62|		return 0;
  240|       |
  241|      0|	if (_dtrust_match_profile(card) != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (241:6): [True: 0, False: 0]
  ------------------
  242|      0|		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|      0|}
card-dtrust.c:_dtrust_match_cardos:
  114|     62|{
  115|     62|	int r;
  116|     62|	size_t prodlen;
  117|     62|	u8 buf[32];
  118|       |
  119|       |	/* check OS version */
  120|     62|	r = sc_get_data(card, 0x0182, buf, 32);
  121|     62|	LOG_TEST_RET(card->ctx, r, "OS version check failed");
  ------------------
  |  |  174|     62|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     62|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     62|	int _ret = (r); \
  |  |  |  |  168|     62|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 43, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     19|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (123:6): [True: 10, False: 9]
  ------------------
  124|     10|		if (r != 2 || buf[0] != 0xc9 || buf[1] != 0x04)
  ------------------
  |  Branch (124:7): [True: 3, False: 7]
  |  Branch (124:17): [True: 3, False: 4]
  |  Branch (124:35): [True: 3, False: 1]
  ------------------
  125|      9|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      9|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  126|     10|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (126:13): [True: 9, False: 0]
  ------------------
  127|      9|		if (r != 2 || buf[0] != 0xcb || buf[1] != 0x01)
  ------------------
  |  Branch (127:7): [True: 4, False: 5]
  |  Branch (127:17): [True: 3, False: 2]
  |  Branch (127:35): [True: 1, False: 1]
  ------------------
  128|      8|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      8|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  129|      9|	}
  130|       |
  131|       |	/* check product name */
  132|      2|	r = sc_get_data(card, 0x0180, buf, 32);
  133|      2|	LOG_TEST_RET(card->ctx, r, "Product name check 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|       |
  135|      0|	prodlen = (size_t)r;
  136|      0|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (136:6): [True: 0, False: 0]
  ------------------
  137|      0|		if (prodlen != strlen("CardOS V5.4     2019") + 1 || memcmp(buf, "CardOS V5.4     2019", prodlen))
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  |  Branch (137:56): [True: 0, False: 0]
  ------------------
  138|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  139|      0|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (139:13): [True: 0, False: 0]
  ------------------
  140|      0|		if (prodlen != strlen("CardOS V6.0 2021") + 1 || memcmp(buf, "CardOS V6.0 2021", prodlen))
  ------------------
  |  Branch (140:7): [True: 0, False: 0]
  |  Branch (140:52): [True: 0, False: 0]
  ------------------
  141|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  142|      0|	}
  143|       |
  144|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  145|      0|}

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

sc_get_entersafe_driver:
 1579|  15.7k|{
 1580|  15.7k|	return sc_get_driver();
 1581|  15.7k|}
card-entersafe.c:sc_get_driver:
 1553|  15.7k|{
 1554|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1555|       |
 1556|  15.7k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1556:6): [True: 1, False: 15.7k]
  ------------------
 1557|      1|		iso_ops = iso_drv->ops;
 1558|       |
 1559|  15.7k|	entersafe_ops = *iso_drv->ops;
 1560|  15.7k|	entersafe_ops.match_card = entersafe_match_card;
 1561|  15.7k|	entersafe_ops.init = entersafe_init;
 1562|  15.7k|	entersafe_ops.read_binary = entersafe_read_binary;
 1563|  15.7k|	entersafe_ops.write_binary = NULL;
 1564|  15.7k|	entersafe_ops.update_binary = entersafe_update_binary;
 1565|  15.7k|	entersafe_ops.select_file = entersafe_select_file;
 1566|  15.7k|	entersafe_ops.restore_security_env = entersafe_restore_security_env;
 1567|  15.7k|	entersafe_ops.set_security_env = entersafe_set_security_env;
 1568|  15.7k|	entersafe_ops.decipher = entersafe_decipher;
 1569|  15.7k|	entersafe_ops.compute_signature = entersafe_compute_signature;
 1570|  15.7k|	entersafe_ops.create_file = entersafe_create_file;
 1571|       |	entersafe_ops.delete_file = NULL;
 1572|  15.7k|	entersafe_ops.pin_cmd = entersafe_pin_cmd;
 1573|  15.7k|	entersafe_ops.card_ctl = entersafe_card_ctl_2048;
 1574|  15.7k|	entersafe_ops.process_fci = entersafe_process_fci;
 1575|  15.7k|	return &entersafe_drv;
 1576|  15.7k|}
card-entersafe.c:entersafe_match_card:
  135|  10.4k|{
  136|  10.4k|	int i;
  137|  10.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.4k]
  |  |  ------------------
  ------------------
  138|       |
  139|  10.4k|	i = _sc_match_atr(card, entersafe_atrs, &card->type);
  140|  10.4k|	if (i < 0)
  ------------------
  |  Branch (140:6): [True: 10.2k, False: 149]
  ------------------
  141|  10.2k|		return 0;
  142|       |
  143|    149|	return 1;
  144|  10.4k|}
card-entersafe.c:entersafe_init:
  147|    149|{
  148|    149|	unsigned int flags;
  149|       |
  150|    149|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    149|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    149|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    149|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 149]
  |  |  ------------------
  ------------------
  151|       |
  152|    149|	card->name = "entersafe";
  153|    149|	card->cla  = 0x00;
  154|    149|	card->drv_data = NULL;
  155|       |
  156|    149|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |   93|    149|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    149|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    149|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  157|       |
  158|    149|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  159|    149|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  160|    149|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  161|    149|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  162|       |
  163|    149|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    149|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  164|       |
  165|       |	/* we need read_binary&friends with max 224 bytes per read */
  166|    149|	card->max_send_size = 224;
  167|    149|	card->max_recv_size = 224;
  168|    149|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  169|    149|}
card-entersafe.c:entersafe_read_binary:
  427|  1.32k|{
  428|  1.32k|	sc_apdu_t apdu;
  429|  1.32k|	u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  430|  1.32k|	int r;
  431|       |
  432|  1.32k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.32k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.32k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.32k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.32k]
  |  |  ------------------
  ------------------
  433|       |
  434|  1.32k|	if (count > card->max_recv_size)
  ------------------
  |  Branch (434:6): [True: 0, False: 1.32k]
  ------------------
  435|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  436|  1.32k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0xFF, idx & 0xFF);
  ------------------
  |  |  292|  1.32k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  437|       |
  438|  1.32k|	apdu.cla = idx > 0x7fff ? 0x80 : 0x00;
  ------------------
  |  Branch (438:13): [True: 1, False: 1.32k]
  ------------------
  439|  1.32k|	apdu.le = count;
  440|  1.32k|	apdu.resplen = count;
  441|  1.32k|	apdu.resp = recvbuf;
  442|       |
  443|  1.32k|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
  444|  1.32k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.32k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.32k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.32k|	int _ret = (r); \
  |  |  |  |  168|  1.32k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 1.31k]
  |  |  |  |  ------------------
  |  |  |  |  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.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.31k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  445|  1.31k|	if (apdu.resplen == 0)
  ------------------
  |  Branch (445:6): [True: 97, False: 1.21k]
  ------------------
  446|     97|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     97|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     97|	int _ret = r; \
  |  |  155|     97|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 97, False: 0]
  |  |  ------------------
  |  |  156|     97|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     86|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 86, False: 11]
  |  |  ------------------
  |  |  157|     97|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     97|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     97|	return _ret; \
  |  |  163|     97|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  447|  1.21k|	memcpy(buf, recvbuf, apdu.resplen);
  448|       |
  449|  1.21k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)apdu.resplen);
  ------------------
  |  |  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: 0, False: 1.21k]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define 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.21k|	} else { \
  |  |  159|  1.21k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  1.21k|			"returning with: %d\n", _ret); \
  |  |  161|  1.21k|	} \
  |  |  162|  1.21k|	return _ret; \
  |  |  163|  1.21k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  450|  1.21k|}
card-entersafe.c:entersafe_transmit_apdu:
  370|  1.58k|{
  371|  1.58k|	u8 *cipher_data = NULL, *mac_data = NULL;
  372|  1.58k|	size_t cipher_data_size, mac_data_size, blocks;
  373|  1.58k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.58k|#define SC_SUCCESS				0
  ------------------
  374|  1.58k|	u8 *sbuf = NULL;
  375|  1.58k|	size_t ssize = 0;
  376|       |
  377|  1.58k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (377:6): [True: 0, False: 1.58k]
  |  Branch (377:22): [True: 0, False: 1.58k]
  ------------------
  378|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  379|       |
  380|  1.58k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.58k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.58k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.58k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  381|       |
  382|  1.58k|	if ((cipher || mac) && (!key || (keylen != 8 && keylen != 16)))
  ------------------
  |  Branch (382:7): [True: 0, False: 1.58k]
  |  Branch (382:17): [True: 0, False: 1.58k]
  |  Branch (382:26): [True: 0, False: 0]
  |  Branch (382:35): [True: 0, False: 0]
  |  Branch (382:50): [True: 0, False: 0]
  ------------------
  383|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  384|       |
  385|  1.58k|	r = sc_apdu_get_octets(card->ctx, apdu, &sbuf, &ssize, SC_PROTO_RAW);
  ------------------
  |  |  354|  1.58k|#define SC_PROTO_RAW		0x00001000
  ------------------
  386|  1.58k|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|  1.58k|#define SC_SUCCESS				0
  ------------------
  |  Branch (386:6): [True: 1.58k, False: 0]
  ------------------
  387|  1.58k|		sc_apdu_log(card->ctx, sbuf, ssize, 1);
  ------------------
  |  |  292|  1.58k|	sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, is_outgoing != 0 ? "Outgoing APDU" : "Incoming APDU", data, len)
  |  |  ------------------
  |  |  |  |  127|  3.16k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (127:65): [True: 1.58k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|  1.58k|	if (sbuf)
  ------------------
  |  Branch (388:6): [True: 1.58k, False: 0]
  ------------------
  389|  1.58k|		free(sbuf);
  390|       |
  391|  1.58k|	if (cipher) {
  ------------------
  |  Branch (391:6): [True: 0, False: 1.58k]
  ------------------
  392|      0|		blocks = (apdu->lc + 2) / 8 + 1;
  393|      0|		cipher_data_size = blocks * 8;
  394|      0|		cipher_data = malloc(cipher_data_size);
  395|      0|		if (!cipher_data) {
  ------------------
  |  Branch (395:7): [True: 0, False: 0]
  ------------------
  396|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  397|      0|			goto out;
  398|      0|		}
  399|       |
  400|      0|		if ((r = entersafe_cipher_apdu(card, apdu, key, keylen, cipher_data, cipher_data_size)) < 0)
  ------------------
  |  Branch (400:7): [True: 0, False: 0]
  ------------------
  401|      0|			goto out;
  402|      0|	}
  403|  1.58k|	if (mac) {
  ------------------
  |  Branch (403:6): [True: 0, False: 1.58k]
  ------------------
  404|      0|		mac_data_size = apdu->lc + 4;
  405|      0|		mac_data = malloc(mac_data_size);
  406|      0|		if (!mac_data) {
  ------------------
  |  Branch (406:7): [True: 0, False: 0]
  ------------------
  407|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  408|      0|			goto out;
  409|      0|		}
  410|      0|		r = entersafe_mac_apdu(card, apdu, key, keylen, mac_data, mac_data_size);
  411|      0|		if (r < 0)
  ------------------
  |  Branch (411:7): [True: 0, False: 0]
  ------------------
  412|      0|			goto out;
  413|      0|	}
  414|       |
  415|  1.58k|	r = sc_transmit_apdu(card, apdu);
  416|       |
  417|  1.58k|out:
  418|  1.58k|	free(cipher_data);
  419|  1.58k|	free(mac_data);
  420|       |
  421|  1.58k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 30, False: 1.55k]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  422|  1.58k|}
card-entersafe.c:entersafe_select_file:
  590|    765|{
  591|    765|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (591:6): [True: 0, False: 765]
  |  Branch (591:22): [True: 0, False: 765]
  ------------------
  592|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  593|    765|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  594|       |
  595|    765|	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: 765]
  ------------------
  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|    269|		case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    269|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (600:3): [True: 269, False: 496]
  ------------------
  601|    269|			return entersafe_select_aid(card, in_path, file_out);
  602|    496|		case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    496|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (602:3): [True: 496, False: 269]
  ------------------
  603|    496|			return entersafe_select_path(card, in_path->value, in_path->len, file_out);
  604|      0|		default:
  ------------------
  |  Branch (604:3): [True: 0, False: 765]
  ------------------
  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|    765|	}
  607|    765|}
card-entersafe.c:entersafe_select_fid:
  503|    691|{
  504|    691|	int r;
  505|    691|	sc_file_t *file = NULL;
  506|    691|	sc_path_t path;
  507|       |
  508|    691|	memset(&path, 0, sizeof(sc_path_t));
  509|       |
  510|    691|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    691|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  511|    691|	path.value[0] = id_hi;
  512|    691|	path.value[1] = id_lo;
  513|    691|	path.len = 2;
  514|       |
  515|    691|	r = iso_ops->select_file(card, &path, &file);
  516|    691|	if (r < 0)
  ------------------
  |  Branch (516:6): [True: 290, False: 401]
  ------------------
  517|    290|		sc_file_free(file);
  518|    691|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    691|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    691|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    691|	int _ret = (r); \
  |  |  |  |  168|    691|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 290, False: 401]
  |  |  |  |  ------------------
  |  |  |  |  169|    290|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    290|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    290|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    290|		return _ret; \
  |  |  |  |  172|    290|	} \
  |  |  |  |  173|    691|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 401]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|       |
  520|    401|	if (file_out)
  ------------------
  |  Branch (520:6): [True: 146, False: 255]
  ------------------
  521|    146|		*file_out = file;
  522|    255|	else
  523|    255|		sc_file_free(file);
  524|       |
  525|    401|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    401|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    401|	int _ret = r; \
  |  |  155|    401|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 401, False: 0]
  |  |  ------------------
  |  |  156|    401|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 401]
  |  |  ------------------
  |  |  157|    401|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    401|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    401|	return _ret; \
  |  |  163|    401|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  526|    401|}
card-entersafe.c:entersafe_select_aid:
  531|    269|{
  532|    269|	int r;
  533|       |
  534|    269|	r = iso_ops->select_file(card, in_path, file_out);
  535|    269|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 202, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  169|    202|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    202|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    202|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    202|		return _ret; \
  |  |  |  |  172|    202|	} \
  |  |  |  |  173|    269|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|       |
  537|     67|	if (file_out) {
  ------------------
  |  Branch (537:6): [True: 0, False: 67]
  ------------------
  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|     67|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     67|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     67|	int _ret = r; \
  |  |  155|     67|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 67, False: 0]
  |  |  ------------------
  |  |  156|     67|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 67]
  |  |  ------------------
  |  |  157|     67|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     67|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     67|	return _ret; \
  |  |  163|     67|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  552|     67|}
card-entersafe.c:entersafe_select_path:
  557|    496|{
  558|    496|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
  559|    496|	const u8 *path = pathbuf;
  560|    496|	size_t pathlen = len;
  561|    496|	unsigned int i;
  562|    496|	int r;
  563|       |
  564|    496|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (564:6): [True: 0, False: 496]
  |  Branch (564:26): [True: 10, False: 486]
  |  Branch (564:41): [True: 0, False: 486]
  ------------------
  565|     10|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  566|       |
  567|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  568|    486|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (568:6): [True: 70, False: 416]
  |  Branch (568:23): [True: 12, False: 58]
  |  Branch (568:42): [True: 10, False: 48]
  ------------------
  569|     22|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  570|       |
  571|       |	/* unify path (the first FID should be MF) */
  572|    464|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (572:6): [True: 62, False: 402]
  |  Branch (572:25): [True: 10, False: 392]
  ------------------
  573|     72|		n_pathbuf[0] = 0x3f;
  574|     72|		n_pathbuf[1] = 0x00;
  575|     72|		memcpy(n_pathbuf + 2, path, pathlen);
  576|     72|		path = n_pathbuf;
  577|     72|		pathlen += 2;
  578|     72|	}
  579|       |
  580|    691|	for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (580:14): [True: 494, False: 197]
  ------------------
  581|    494|		r = entersafe_select_fid(card, path[i], path[i + 1], NULL);
  582|    494|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|    494|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    494|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    494|	int _ret = (r); \
  |  |  |  |  168|    494|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 267, False: 227]
  |  |  |  |  ------------------
  |  |  |  |  169|    267|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    267|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    267|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    267|		return _ret; \
  |  |  |  |  172|    267|	} \
  |  |  |  |  173|    494|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 227]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|    494|	}
  584|    197|	return entersafe_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
  585|    464|}
card-entersafe.c:entersafe_pin_cmd:
  880|     10|{
  881|     10|	int r;
  882|     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]
  |  |  ------------------
  ------------------
  883|     10|	entersafe_init_pin_info(&data->pin1, 0);
  884|     10|	entersafe_init_pin_info(&data->pin2, 1);
  885|     10|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     10|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  886|       |
  887|     10|	if (data->cmd != SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|     10|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (887:6): [True: 10, False: 0]
  ------------------
  888|     10|		r = iso_ops->pin_cmd(card, data);
  889|     10|		sc_log(card->ctx, "Verify rv:%i", 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__
  |  |  ------------------
  ------------------
  890|     10|	} 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|     10|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  929|     10|}
card-entersafe.c:entersafe_init_pin_info:
  870|     20|{
  871|     20|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     20|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  872|     20|	pin->min_length = 4;
  873|     20|	pin->max_length = 16;
  874|     20|	pin->pad_length = 16;
  875|     20|	pin->offset     = 5 + num * 16;
  876|     20|	pin->pad_char   = 0x00;
  877|     20|}
card-entersafe.c:entersafe_card_ctl_2048:
 1522|    277|{
 1523|    277|	sc_entersafe_create_data *tmp = (sc_entersafe_create_data *)ptr;
 1524|       |
 1525|    277|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1526|       |
 1527|    277|	switch (cmd) {
 1528|      0|		case SC_CARDCTL_ENTERSAFE_CREATE_FILE:
  ------------------
  |  Branch (1528:3): [True: 0, False: 277]
  ------------------
 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: 277]
  ------------------
 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: 277]
  ------------------
 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: 277]
  ------------------
 1542|      0|			return entersafe_erase_card(card);
 1543|    257|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1543:3): [True: 257, False: 20]
  ------------------
 1544|    257|			return entersafe_get_serialnr(card, (sc_serial_number_t *)ptr);
 1545|      0|		case SC_CARDCTL_ENTERSAFE_PREINSTALL_KEYS:
  ------------------
  |  Branch (1545:3): [True: 0, False: 277]
  ------------------
 1546|      0|			return entersafe_preinstall_keys(card, entersafe_preinstall_rsa_2048);
 1547|     20|		default:
  ------------------
  |  Branch (1547:3): [True: 20, False: 257]
  ------------------
 1548|     20|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     20|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1549|    277|	}
 1550|    277|}
card-entersafe.c:entersafe_get_serialnr:
 1347|    257|{
 1348|    257|	int	r;
 1349|    257|	sc_apdu_t apdu;
 1350|    257|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1351|       |
 1352|    257|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    257|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  ------------------
  ------------------
 1353|    257|	if (serial == NULL)
  ------------------
  |  Branch (1353:6): [True: 0, False: 257]
  ------------------
 1354|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1355|       |
 1356|    257|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xEA, 0x00, 0x00);
  ------------------
  |  |  292|    257|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1357|    257|	apdu.cla = 0x80;
 1358|    257|	apdu.resp = rbuf;
 1359|    257|	apdu.resplen = sizeof(rbuf);
 1360|    257|	apdu.le = 0x08;
 1361|       |
 1362|    257|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
 1363|    257|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    257|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    257|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    257|	int _ret = (r); \
  |  |  |  |  168|    257|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 240]
  |  |  |  |  ------------------
  |  |  |  |  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|    257|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 240]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1364|    240|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "EnterSafe get SN failed");
  ------------------
  |  |  174|    240|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    240|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    240|	int _ret = (r); \
  |  |  |  |  168|    240|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 199, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  169|    199|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    199|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    199|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    199|		return _ret; \
  |  |  |  |  172|    199|	} \
  |  |  |  |  173|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 41]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1365|     41|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1365:6): [True: 29, False: 12]
  ------------------
 1366|     41|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of SN");
  ------------------
  |  |  174|     29|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     29|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     29|	int _ret = (r); \
  |  |  |  |  168|     29|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     29|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     29|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     29|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     29|		return _ret; \
  |  |  |  |  172|     29|	} \
  |  |  |  |  173|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1367|       |
 1368|     12|	card->serialnr.len = serial->len = 8;
 1369|     12|	memcpy(card->serialnr.value, rbuf, 8);
 1370|     12|	memcpy(serial->value, rbuf, 8);
 1371|       |
 1372|     12|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     12|	int _ret = r; \
  |  |  155|     12|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  ------------------
  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 12]
  |  |  ------------------
  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     12|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     12|	return _ret; \
  |  |  163|     12|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1373|     12|}
card-entersafe.c:entersafe_process_fci:
  479|    279|{
  480|    279|	int r;
  481|       |
  482|    279|	if (file == NULL)
  ------------------
  |  Branch (482:6): [True: 0, False: 279]
  ------------------
  483|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  484|    279|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    279|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    279|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    279|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 279]
  |  |  ------------------
  ------------------
  485|       |
  486|    279|	r = iso_ops->process_fci(card, file, buf, buflen);
  487|    279|	LOG_TEST_RET(card->ctx, r, "Process fci failed");
  ------------------
  |  |  174|    279|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    279|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    279|	int _ret = (r); \
  |  |  |  |  168|    279|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 279]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    279|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 279]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  488|       |
  489|    279|	if (file->namelen) {
  ------------------
  |  Branch (489:6): [True: 10, False: 269]
  ------------------
  490|     10|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     10|#define SC_FILE_TYPE_DF			0x04
  ------------------
  491|     10|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     10|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  492|    269|	} else {
  493|    269|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    269|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  494|    269|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    269|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  495|    269|	}
  496|       |
  497|    279|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    279|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    279|	int _ret = r; \
  |  |  155|    279|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 279, False: 0]
  |  |  ------------------
  |  |  156|    279|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 279]
  |  |  ------------------
  |  |  157|    279|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    279|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    279|	return _ret; \
  |  |  163|    279|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  498|    279|}

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

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

sc_get_esteid2018_driver:
  303|  15.7k|struct sc_card_driver *sc_get_esteid2018_driver(void) {
  304|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  305|       |
  306|  15.7k|	if (iso_ops == NULL)
  ------------------
  |  Branch (306:6): [True: 1, False: 15.7k]
  ------------------
  307|      1|		iso_ops = iso_drv->ops;
  308|       |
  309|  15.7k|	esteid_ops = *iso_drv->ops;
  310|  15.7k|	esteid_ops.match_card = esteid_match_card;
  311|  15.7k|	esteid_ops.init = esteid_init;
  312|  15.7k|	esteid_ops.finish = esteid_finish;
  313|       |
  314|  15.7k|	esteid_ops.select_file = esteid_select_file;
  315|       |
  316|  15.7k|	esteid_ops.set_security_env = esteid_set_security_env;
  317|  15.7k|	esteid_ops.compute_signature = esteid_compute_signature;
  318|  15.7k|	esteid_ops.pin_cmd = esteid_pin_cmd;
  319|  15.7k|	esteid_ops.logout = esteid_logout;
  320|       |
  321|  15.7k|	return &esteid2018_driver;
  322|  15.7k|}
card-esteid2018.c:esteid_match_card:
   83|  8.02k|static int esteid_match_card(sc_card_t *card) {
   84|  8.02k|	int i = _sc_match_atr(card, esteid_atrs, &card->type);
   85|       |
   86|  8.02k|	if (i >= 0 && gp_select_aid(card, &IASECC_AID) == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (86:6): [True: 0, False: 8.02k]
  |  Branch (86:16): [True: 0, False: 0]
  ------------------
   87|      0|		card->name = esteid_atrs[i].name;
   88|      0|		return 1;
   89|      0|	}
   90|  8.02k|	return 0;
   91|  8.02k|}

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

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

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

sc_get_gids_driver:
 2185|  15.7k|{
 2186|  15.7k|	return sc_get_driver();
 2187|  15.7k|}
card-gids.c:sc_get_driver:
 2140|  15.7k|{
 2141|       |
 2142|  15.7k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2142:6): [True: 1, False: 15.7k]
  ------------------
 2143|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2144|       |
 2145|  15.7k|	gids_ops.match_card = gids_match_card;
 2146|  15.7k|	gids_ops.init = gids_init;
 2147|  15.7k|	gids_ops.finish = gids_finish;
 2148|  15.7k|	gids_ops.read_binary = gids_read_binary;
 2149|  15.7k|	gids_ops.write_binary = NULL;
 2150|  15.7k|	gids_ops.update_binary = NULL;
 2151|  15.7k|	gids_ops.erase_binary = NULL;
 2152|  15.7k|	gids_ops.read_record = NULL;
 2153|  15.7k|	gids_ops.write_record = NULL;
 2154|  15.7k|	gids_ops.append_record = NULL;
 2155|  15.7k|	gids_ops.update_record = NULL;
 2156|  15.7k|	gids_ops.select_file = gids_select_file;
 2157|  15.7k|	gids_ops.get_response = iso_ops->get_response;
 2158|  15.7k|	gids_ops.get_challenge = NULL;
 2159|  15.7k|	gids_ops.verify = NULL; // see pin_cmd
 2160|  15.7k|	gids_ops.logout = gids_logout;
 2161|  15.7k|	gids_ops.restore_security_env = NULL;
 2162|  15.7k|	gids_ops.set_security_env = gids_set_security_env;
 2163|  15.7k|	gids_ops.decipher = gids_decipher;
 2164|  15.7k|	gids_ops.compute_signature = iso_ops->compute_signature;
 2165|  15.7k|	gids_ops.change_reference_data = NULL; // see pin_cmd
 2166|  15.7k|	gids_ops.reset_retry_counter = NULL; // see pin_cmd
 2167|  15.7k|	gids_ops.create_file = iso_ops->create_file;
 2168|  15.7k|	gids_ops.delete_file = NULL;
 2169|  15.7k|	gids_ops.list_files = NULL;
 2170|  15.7k|	gids_ops.check_sw = iso_ops->check_sw;
 2171|  15.7k|	gids_ops.card_ctl = gids_card_ctl;
 2172|  15.7k|	gids_ops.process_fci = iso_ops->process_fci;
 2173|  15.7k|	gids_ops.construct_fci = iso_ops->construct_fci;
 2174|  15.7k|	gids_ops.pin_cmd = gids_pin_cmd;
 2175|  15.7k|	gids_ops.get_data = NULL;
 2176|  15.7k|	gids_ops.put_data = NULL;
 2177|  15.7k|	gids_ops.delete_record = NULL;
 2178|  15.7k|	gids_ops.read_public_key = gids_read_public_key;
 2179|  15.7k|	gids_ops.card_reader_lock_obtained = gids_card_reader_lock_obtained;
 2180|       |
 2181|  15.7k|	return &gids_drv;
 2182|  15.7k|}
card-gids.c:gids_match_card:
  563|  3.44k|{
  564|  3.44k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  565|  3.44k|	int r,i;
  566|  3.44k|	size_t resplen = sizeof(rbuf);
  567|  3.44k|	const u8 *tag;
  568|  3.44k|	size_t taglen;
  569|  3.44k|	const u8 *aid;
  570|  3.44k|	size_t aidlen;
  571|       |
  572|  3.44k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.44k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.44k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.44k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.44k]
  |  |  ------------------
  ------------------
  573|       |
  574|       |	/* Detect by selecting applet */
  575|  3.44k|	r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
  576|  3.44k|	if (r<0) return 0;
  ------------------
  |  Branch (576:6): [True: 3.35k, False: 90]
  ------------------
  577|       |
  578|     90|	card->type = SC_CARD_TYPE_GIDS_GENERIC;
  579|     90|	if (resplen > 2) {
  ------------------
  |  Branch (579:6): [True: 10, False: 80]
  ------------------
  580|     10|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, GIDS_APPLICATION_TEMPLATE_TAG, &taglen);
  ------------------
  |  |  105|     10|#define GIDS_APPLICATION_TEMPLATE_TAG 0x61
  ------------------
  581|     10|		if (tag != NULL) {
  ------------------
  |  Branch (581:7): [True: 6, False: 4]
  ------------------
  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|     10|	}
  595|       |
  596|     90|	return 1;
  597|  3.44k|}
card-gids.c:gids_select_aid:
  280|  3.44k|{
  281|  3.44k|	sc_apdu_t apdu;
  282|  3.44k|	int r;
  283|       |
  284|  3.44k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.44k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.44k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.44k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.44k]
  |  |  ------------------
  ------------------
  285|  3.44k|	sc_log(card->ctx, "Got args: aid=%p, aidlen=%zu, response=%p, responselen=%zu",
  ------------------
  |  |   71|  6.88k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.44k, False: 0]
  |  |  ------------------
  ------------------
  286|  3.44k|			aid, aidlen, response, responselen ? *responselen : 0);
  287|       |
  288|  3.44k|	sc_format_apdu(card, &apdu,
  289|  3.44k|		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.44k|#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.44k|#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.44k|#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.44k|#define P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00
  ------------------
  |  Branch (289:3): [True: 0, False: 3.44k]
  ------------------
  290|  3.44k|	apdu.lc = aidlen;
  291|  3.44k|	apdu.data = aid;
  292|  3.44k|	apdu.datalen = aidlen;
  293|  3.44k|	apdu.resp = response;
  294|  3.44k|	apdu.resplen = responselen ? *responselen : 0;
  ------------------
  |  Branch (294:17): [True: 3.44k, False: 0]
  ------------------
  295|  3.44k|	apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
  ------------------
  |  Branch (295:12): [True: 0, False: 3.44k]
  ------------------
  296|       |
  297|  3.44k|	r = sc_transmit_apdu(card, &apdu);
  298|  3.44k|	if (responselen)
  ------------------
  |  Branch (298:6): [True: 3.44k, False: 0]
  ------------------
  299|  3.44k|		*responselen = apdu.resplen;
  300|  3.44k|	LOG_TEST_RET(card->ctx, r, "gids select failed");
  ------------------
  |  |  174|  3.44k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.44k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.44k|	int _ret = (r); \
  |  |  |  |  168|  3.44k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 3.43k]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|  3.44k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.43k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|  3.43k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|  3.34k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.34k, False: 90]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  302|  3.43k|}
card-gids.c:gids_init:
  631|     90|{
  632|     90|	unsigned long flags;
  633|     90|	struct gids_private_data *data;
  634|     90|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     90|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     90|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     90|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 90]
  |  |  ------------------
  ------------------
  635|       |
  636|       |	// cache some data in memory
  637|     90|	data = (struct gids_private_data*) calloc(1, sizeof(struct gids_private_data));
  638|     90|	if (!data) {
  ------------------
  |  Branch (638:6): [True: 0, False: 90]
  ------------------
  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|     90|	memset(data, 0, sizeof(struct gids_private_data));
  642|     90|	card->drv_data = data;
  643|       |	// invalidate the master file and cmap file cache
  644|     90|	data->cmapfilesize = sizeof(data->cmapfile);
  645|     90|	data->masterfilesize = sizeof(data->masterfile);
  646|       |
  647|       |	/* supported RSA keys and how padding is done */
  648|     90|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|     90|#define SC_ALGORITHM_RSA_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|     90|#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|     90|#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|     90|#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|     90|#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|     90|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  652|     90|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  653|     90|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  654|     90|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  655|       |
  656|     90|	return SC_SUCCESS;
  ------------------
  |  |   28|     90|#define SC_SUCCESS				0
  ------------------
  657|     90|}
card-gids.c:gids_finish:
  661|     90|{
  662|     90|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     90|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     90|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     90|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 90]
  |  |  ------------------
  ------------------
  663|       |	/* free the private data */
  664|     90|	if (card->drv_data) {
  ------------------
  |  Branch (664:6): [True: 90, False: 0]
  ------------------
  665|     90|		free(card->drv_data);
  666|       |		card->drv_data = NULL;
  667|     90|	}
  668|     90|	return 0;
  669|     90|}
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|     95|static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdentifier, u8* response, size_t *responselen) {
  211|     95|	sc_apdu_t apdu;
  212|     95|	int r;
  213|     95|	u8 data[4] = {0x5C, 0x02, (dataObjectIdentifier&0xFF00)>>8, (dataObjectIdentifier&0xFF)};
  214|     95|	size_t datasize = 0;
  215|     95|	const u8* p;
  216|     95|	u8 buffer[MAX_GIDS_FILE_SIZE];
  217|     95|	size_t buffer_len = sizeof(buffer);
  218|       |
  219|     95|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     95|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     95|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     95|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 95]
  |  |  ------------------
  ------------------
  220|     95|	sc_log(card->ctx, "Got args: fileIdentifier=%x, dataObjectIdentifier=%x, response=%p, responselen=%zu",
  ------------------
  |  |   71|    190|#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: 95, False: 0]
  |  |  ------------------
  ------------------
  221|     95|			fileIdentifier, dataObjectIdentifier, response, responselen ? *responselen : 0);
  222|       |
  223|     95|	sc_format_apdu(card, &apdu,
  224|     95|		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|     95|#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|     95|#define INS_GET_DATA 0xCB
  ------------------
  |  Branch (224:3): [True: 0, False: 95]
  ------------------
  225|     95|	apdu.lc = 04;
  226|     95|	apdu.data = data;
  227|     95|	apdu.datalen = 04;
  228|     95|	apdu.resp = buffer;
  229|     95|	apdu.resplen = buffer_len;
  230|     95|	apdu.le = 256;
  231|       |
  232|     95|	r = sc_transmit_apdu(card, &apdu);
  233|     95|	LOG_TEST_RET(card->ctx, r, "gids get data failed");
  ------------------
  |  |  174|     95|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     95|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     95|	int _ret = (r); \
  |  |  |  |  168|     95|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 90]
  |  |  |  |  ------------------
  |  |  |  |  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|     95|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     90|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
  ------------------
  |  |  174|     90|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     90|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     90|	int _ret = (r); \
  |  |  |  |  168|     90|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  169|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     25|		return _ret; \
  |  |  |  |  172|     25|	} \
  |  |  |  |  173|     90|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|     65|	buffer_len = apdu.resplen;
  236|       |
  237|     65|	p = sc_asn1_find_tag(card->ctx, buffer, buffer_len, dataObjectIdentifier, &datasize);
  238|     65|	if (!p) {
  ------------------
  |  Branch (238:6): [True: 5, False: 60]
  ------------------
  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|     60|	if (response && responselen) {
  ------------------
  |  Branch (241:6): [True: 60, False: 0]
  |  Branch (241:18): [True: 60, False: 0]
  ------------------
  242|     60|		if (datasize > *responselen) {
  ------------------
  |  Branch (242:7): [True: 0, False: 60]
  ------------------
  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|     60|		memcpy(response, p, datasize);
  246|     60|		*responselen = datasize;
  247|     60|	}
  248|     60|	return SC_SUCCESS;
  ------------------
  |  |   28|     60|#define SC_SUCCESS				0
  ------------------
  249|     60|}
card-gids.c:gids_select_file:
  964|    465|			   struct sc_file **file_out) {
  965|    465|	struct sc_file *file = NULL;
  966|    465|	struct sc_context *ctx = card->ctx;
  967|    465|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
  968|       |
  969|    465|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    465|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    465|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    465|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    465|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 465]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|       |
  971|    465|	data->state = GIDS_STATE_NONE;
  ------------------
  |  |   57|    465|#define GIDS_STATE_NONE 0
  ------------------
  972|    465|	data->currentDO = 0;
  973|    465|	data->currentEFID = 0;
  974|    465|	if (in_path->len == 4 && in_path->value[0] == 0xA0) {
  ------------------
  |  Branch (974:6): [True: 257, False: 208]
  |  Branch (974:27): [True: 0, False: 257]
  ------------------
  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|    465|	} 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: 257, False: 208]
  |  Branch (991:34): [True: 257, False: 0]
  |  Branch (991:63): [True: 0, False: 257]
  |  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|    465|	} else {
 1002|    465|		return iso_ops->select_file(card, in_path, file_out);
 1003|    465|	}
 1004|    465|}
card-gids.c:gids_card_ctl:
 2089|    115|{
 2090|    115|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    115|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    115|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    115|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    115|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 115]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2091|    115|	switch (cmd) {
 2092|      9|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2092:3): [True: 9, False: 106]
  ------------------
 2093|      9|			return gids_get_serialnr(card, (sc_serial_number_t *) ptr);
 2094|     88|		case SC_CARDCTL_GIDS_GET_ALL_CONTAINERS:
  ------------------
  |  Branch (2094:3): [True: 88, False: 27]
  ------------------
 2095|     88|			return gids_get_all_containers(card, (size_t*) ptr);
 2096|      0|		case SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL:
  ------------------
  |  Branch (2096:3): [True: 0, False: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 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: 115]
  ------------------
 2116|      0|			return gids_set_administrator_key(card, (u8*) ptr);
 2117|      0|		case SC_CARDCTL_GIDS_AUTHENTICATE_ADMIN:
  ------------------
  |  Branch (2117:3): [True: 0, False: 115]
  ------------------
 2118|      0|			return gids_authenticate_admin(card, (u8*) ptr);
 2119|     18|		default:
  ------------------
  |  Branch (2119:3): [True: 18, False: 97]
  ------------------
 2120|     18|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     18|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2121|    115|	}
 2122|    115|}
card-gids.c:gids_get_serialnr:
  602|      9|{
  603|      9|	int r;
  604|      9|	u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  605|      9|	size_t buffersize;
  606|       |
  607|      9|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      9|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  ------------------
  ------------------
  608|       |
  609|      9|	buffersize = sizeof(buffer);
  610|      9|	r = gids_read_gidsfile(card, "", "cardid", buffer, &buffersize);
  611|      9|	LOG_TEST_RET(card->ctx, r, "unable to read cardid");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     67|static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename, u8* response, size_t *responselen) {
  386|     67|	struct gids_private_data* privatedata = (struct gids_private_data*) card->drv_data;
  387|     67|	int r;
  388|     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]
  |  |  ------------------
  ------------------
  389|     67|	if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
  ------------------
  |  Branch (389:6): [True: 6, False: 61]
  ------------------
  390|      6|		r = gids_read_masterfile(card);
  391|      6|		LOG_TEST_RET(card->ctx, r, "unable to get the masterfile");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|      6|	}
  393|     61|	r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
  394|     61|		directory, filename, response, responselen);
  395|     61|	LOG_TEST_RET(card->ctx, r, "unable to read the file");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     61|		return _ret; \
  |  |  |  |  172|     61|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     94|static int gids_read_masterfile(sc_card_t* card) {
  341|     94|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  342|     94|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     94|#define SC_SUCCESS				0
  ------------------
  343|       |
  344|     94|	data->masterfilesize = sizeof(data->masterfile);
  345|     94|	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   66|     94|#define MF_FI UserCreateDeleteDirAc_FI
  |  |  ------------------
  |  |  |  |   63|     94|#define UserCreateDeleteDirAc_FI 0xA000
  |  |  ------------------
  ------------------
              	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   67|     94|#define MF_DO 0xDF1F
  ------------------
  346|     94|	if (r<0) {
  ------------------
  |  Branch (346:6): [True: 34, False: 60]
  ------------------
  347|     34|		data->masterfilesize = sizeof(data->masterfile);
  348|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|     34|	}
  350|     60|	if (data->masterfilesize < 1 || data->masterfile[0] != 1) {
  ------------------
  |  Branch (350:6): [True: 1, False: 59]
  |  Branch (350:34): [True: 1, False: 58]
  ------------------
  351|      2|		data->masterfilesize = sizeof(data->masterfile);
  352|      2|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      2|	}
  354|     58|	return r;
  355|     60|}
card-gids.c:gids_read_gidsfile_without_cache:
  308|     61|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|     61|	int r;
  310|     61|	int fileIdentifier;
  311|     61|	int dataObjectIdentifier;
  312|       |
  313|     61|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  314|     61|	r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
  315|     61|	LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
  ------------------
  |  |  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: 60, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     60|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     60|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     60|		return _ret; \
  |  |  |  |  172|     60|	} \
  |  |  |  |  173|     61|} 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|     61|static int gids_get_identifiers(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, int *fileIdentifier, int *dataObjectIdentifier) {
  164|     61|	gids_mf_record_t *records = (gids_mf_record_t *) (masterfile+1);
  165|     61|	size_t recordcount = ((masterfilesize-1) / sizeof(gids_mf_record_t));
  166|     61|	size_t i;
  167|     61|	if (masterfilesize < 1)
  ------------------
  |  Branch (167:6): [True: 0, False: 61]
  ------------------
  168|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  169|       |
  170|    143|	for (i = 0; i < recordcount; i++) {
  ------------------
  |  Branch (170:14): [True: 83, False: 60]
  ------------------
  171|     83|		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: 22, False: 61]
  |  Branch (171:86): [True: 1, False: 21]
  ------------------
  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|     83|	}
  179|     60|	sc_log(card->ctx, "file %s %s not found\n", directory, filename);
  ------------------
  |  |   71|     60|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  180|     60|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     60|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  181|     61|}
card-gids.c:gids_get_all_containers:
 1074|     88|gids_get_all_containers(sc_card_t* card, size_t *recordsnum) {
 1075|     88|	int r;
 1076|     88|	struct gids_private_data *privatedata = (struct gids_private_data *) card->drv_data;
 1077|     88|	r = gids_read_masterfile(card);
 1078|     88|	LOG_TEST_RET(card->ctx, r, "unable to read the masterfile");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 30, False: 58]
  |  |  |  |  ------------------
  |  |  |  |  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|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 58]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|     58|	r = gids_read_cmapfile(card);
 1080|     58|	LOG_TEST_RET(card->ctx, r, "unable to read the cmapfile");
  ------------------
  |  |  174|     58|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     58|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     58|	int _ret = (r); \
  |  |  |  |  168|     58|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     58|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     58|		return _ret; \
  |  |  |  |  172|     58|	} \
  |  |  |  |  173|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1081|      0|	*recordsnum = (privatedata ->cmapfilesize / sizeof(CONTAINER_MAP_RECORD));
 1082|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1083|     58|}
card-gids.c:gids_read_cmapfile:
  427|     58|static int gids_read_cmapfile(sc_card_t* card) {
  428|     58|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  429|     58|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     58|#define SC_SUCCESS				0
  ------------------
  430|       |
  431|     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]
  |  |  ------------------
  ------------------
  432|     58|	data->cmapfilesize = sizeof(data->cmapfile);
  433|     58|	r = gids_read_gidsfile(card, "mscp", "cmapfile", data->cmapfile, &data->cmapfilesize);
  434|     58|	if (r<0) {
  ------------------
  |  Branch (434:6): [True: 58, False: 0]
  ------------------
  435|     58|		data->cmapfilesize = sizeof(data->cmapfile);
  436|     58|	}
  437|     58|	LOG_TEST_RET(card->ctx, r, "unable to get the cmapfile");
  ------------------
  |  |  174|     58|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     58|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     58|	int _ret = (r); \
  |  |  |  |  168|     58|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     58|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     58|		return _ret; \
  |  |  |  |  172|     58|	} \
  |  |  |  |  173|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|      0|	return r;
  439|     58|}
card-gids.c:gids_pin_cmd:
 1022|      9|gids_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1023|      9|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      9|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1023:6): [True: 9, False: 0]
  ------------------
 1024|      9|		return gids_get_pin_policy(card, data);
 1025|      9|	} else {
 1026|      0|		return iso_ops->pin_cmd(card, data);
 1027|      0|	}
 1028|      9|}
card-gids.c:gids_get_pin_policy:
 1006|      9|static int gids_get_pin_policy(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1007|      9|	int r;
 1008|      9|	if (data->pin_type != SC_AC_CHV) {
  ------------------
  |  |  151|      9|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1008:6): [True: 0, False: 9]
  ------------------
 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|      9|	r = gids_get_pin_status(card, data->pin_reference, &(data->pin1.tries_left), &(data->pin1.max_tries));
 1012|      9|	LOG_TEST_RET(card->ctx, r, "gids_get_pin_status failed");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|      9|}
card-gids.c:gids_get_pin_status:
  516|      9|static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_left, int *max_tries) {
  517|      9|	int dataObjectIdentifier, r;
  518|      9|	u8 buffer[100];
  519|      9|	const u8* p;
  520|      9|	size_t buffersize = sizeof(buffer);
  521|      9|	size_t datasize;
  522|       |
  523|      9|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      9|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  ------------------
  ------------------
  524|      9|	if (tries_left) *tries_left = -1;
  ------------------
  |  Branch (524:6): [True: 9, False: 0]
  ------------------
  525|      9|	if (max_tries) *max_tries = -1;
  ------------------
  |  Branch (525:6): [True: 9, False: 0]
  ------------------
  526|      9|	switch(pinreference) {
  527|      0|	case GIDS_PIN_IDENTIFIER:
  ------------------
  |  |  100|      0|#define GIDS_PIN_IDENTIFIER 0x80
  ------------------
  |  Branch (527:2): [True: 0, False: 9]
  ------------------
  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: 9]
  ------------------
  531|      0|		dataObjectIdentifier = GIDS_PUK_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   81|      0|#define GIDS_PUK_STATUS_OBJECT_IDENTIFIER 0x7F73
  ------------------
  532|      0|		break;
  533|      9|	default:
  ------------------
  |  Branch (533:2): [True: 9, False: 0]
  ------------------
  534|      9|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|      9|	}
  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.63k|{
 2126|  3.63k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.63k|#define SC_SUCCESS				0
  ------------------
 2127|       |
 2128|  3.63k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.63k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.63k]
  |  |  ------------------
  ------------------
 2129|       |
 2130|  3.63k|	if (was_reset > 0) {
  ------------------
  |  Branch (2130:6): [True: 0, False: 3.63k]
  ------------------
 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.63k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.63k|	int _ret = r; \
  |  |  |  |  155|  3.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.63k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.63k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.63k|	return _ret; \
  |  |  |  |  163|  3.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2137|  3.63k|}

sc_invalidate_cache:
  164|  2.71k|{
  165|  2.71k|	if (card) {
  ------------------
  |  Branch (165:6): [True: 2.71k, False: 0]
  ------------------
  166|  2.71k|		struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  167|  2.71k|		sc_file_free(prv->cache.current_ef);
  168|  2.71k|		sc_file_free(prv->cache.current_df);
  169|  2.71k|		memset(&prv->cache, 0, sizeof(prv->cache));
  170|  2.71k|		prv->cache.valid = 0;
  171|  2.71k|	}
  172|  2.71k|}
iasecc_se_get_info:
 1609|    139|{
 1610|    139|	struct sc_context *ctx = card->ctx;
 1611|    139|	struct sc_apdu apdu;
 1612|    139|	unsigned char rbuf[0x100];
 1613|    139|	unsigned char sbuf_iasecc[10] = {
 1614|    139|		0x4D, 0x08, IASECC_SDO_TEMPLATE_TAG, 0x06,
  ------------------
  |  |   29|    139|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 1615|    139|		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   27|    139|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |  102|    139|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   59|    139|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 1616|    139|		se->reference & 0x3F,
 1617|    139|		0x02, IASECC_SDO_CLASS_SE, 0x80
  ------------------
  |  |  102|    139|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 1618|    139|	};
 1619|    139|	int rv;
 1620|       |
 1621|    139|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|    139|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (1623:6): [True: 22, False: 117]
  ------------------
 1624|     22|		rv = iasecc_select_mf(card, NULL);
 1625|     22|		LOG_TEST_RET(ctx, rv, "MF invalid");
  ------------------
  |  |  174|     22|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     22|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     22|	int _ret = (r); \
  |  |  |  |  168|     22|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1626|     22|	}
 1627|       |
 1628|    131|	if (se->reference > IASECC_SE_REF_MAX)
  ------------------
  |  |   66|    131|#define IASECC_SE_REF_MAX	0x0F
  ------------------
  |  Branch (1628:6): [True: 0, False: 131]
  ------------------
 1629|    131|                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|    131|	rv = iasecc_se_get_info_from_cache(card, se);
 1632|    131|	if (rv == SC_ERROR_OBJECT_NOT_FOUND)   {
  ------------------
  |  |   88|    131|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1632:6): [True: 131, False: 0]
  ------------------
 1633|    131|		sc_log(ctx, "No SE#%X info in cache, try to use 'GET DATA'", se->reference);
  ------------------
  |  |   71|    131|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1634|       |
 1635|    131|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    131|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1636|    131|		apdu.data = sbuf_iasecc;
 1637|    131|		apdu.datalen = sizeof(sbuf_iasecc);
 1638|    131|		apdu.lc = apdu.datalen;
 1639|    131|		apdu.resp = rbuf;
 1640|    131|		apdu.resplen = sizeof(rbuf);
 1641|    131|		apdu.le = sizeof(rbuf);
 1642|       |
 1643|    131|		rv = sc_transmit_apdu(card, &apdu);
 1644|    131|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    131|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    131|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    131|	int _ret = (r); \
  |  |  |  |  168|    131|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  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|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1645|    123|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1646|    123|		LOG_TEST_RET(ctx, rv, "get SE data  error");
  ------------------
  |  |  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: 16, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  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|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 107]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1647|       |
 1648|    107|		rv = iasecc_se_parse(card, apdu.resp, apdu.resplen, se);
 1649|    107|		LOG_TEST_RET(ctx, rv, "cannot parse SE data");
  ------------------
  |  |  174|    107|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    107|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    107|	int _ret = (r); \
  |  |  |  |  168|    107|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 98, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|     98|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     98|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     98|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     98|		return _ret; \
  |  |  |  |  172|     98|	} \
  |  |  |  |  173|    107|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|       |
 1651|      9|		rv = iasecc_se_cache_info(card, se);
 1652|      9|		LOG_TEST_RET(ctx, rv, "failed to put SE data into cache");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1653|      9|	}
 1654|       |
 1655|      9|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1656|      9|}
sc_get_iasecc_driver:
 3638|  15.7k|{
 3639|  15.7k|	return sc_get_driver();
 3640|  15.7k|}
card-iasecc.c:iasecc_is_cpx:
  586|  10.2k|{
  587|  10.2k|	switch(card->type) {
  588|  2.26k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (588:3): [True: 2.26k, False: 7.97k]
  ------------------
  589|  2.53k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (589:3): [True: 276, False: 9.95k]
  ------------------
  590|  2.53k|			return 1;
  591|  7.69k|		default:
  ------------------
  |  Branch (591:3): [True: 7.69k, False: 2.53k]
  ------------------
  592|  7.69k|			return 0;
  593|  10.2k|	}
  594|       |
  595|      0|	return 0;
  596|  10.2k|}
card-iasecc.c:iasecc_select_mf:
  283|  2.65k|{
  284|  2.65k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  285|  2.65k|	struct sc_context *ctx = card->ctx;
  286|  2.65k|	struct sc_file *mf_file = NULL;
  287|  2.65k|	struct sc_path path;
  288|  2.65k|	int rv;
  289|       |
  290|  2.65k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.65k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.65k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|  2.65k|	if (file_out)
  ------------------
  |  Branch (292:6): [True: 1.79k, False: 865]
  ------------------
  293|  1.79k|		*file_out = NULL;
  294|       |
  295|  2.65k|	memset(&path, 0, sizeof(struct sc_path));
  296|  2.65k|	if (!card->ef_atr || !card->ef_atr->aid.len)   {
  ------------------
  |  Branch (296:6): [True: 585, False: 2.07k]
  |  Branch (296:23): [True: 1.91k, False: 159]
  ------------------
  297|  2.49k|		struct sc_apdu apdu;
  298|  2.49k|		unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  299|       |
  300|       |		/* ISO 'select' command fails when not FCP data returned */
  301|  2.49k|		sc_format_path("3F00", &path);
  302|  2.49k|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  2.49k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  303|       |
  304|  2.49k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|  2.49k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|  2.49k|		apdu.lc = path.len;
  306|  2.49k|		apdu.data = path.value;
  307|  2.49k|		apdu.datalen = path.len;
  308|  2.49k|		apdu.resplen = sizeof(apdu_resp);
  309|  2.49k|		apdu.resp = apdu_resp;
  310|       |
  311|       |		/* TODO: this might be obsolete now that 0x0c (no data) is default for p2 */
  312|  2.49k|		if (card->type == SC_CARD_TYPE_IASECC_MI2)
  ------------------
  |  Branch (312:7): [True: 0, False: 2.49k]
  ------------------
  313|      0|			apdu.p2 = 0x04;
  314|       |
  315|  2.49k|		rv = sc_transmit_apdu(card, &apdu);
  316|  2.49k|		LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 10, False: 2.48k]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|  2.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.48k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|  2.48k|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  318|  2.48k|		LOG_TEST_RET(card->ctx, rv, "Cannot select MF");
  ------------------
  |  |  174|  2.48k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.48k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.48k|	int _ret = (r); \
  |  |  |  |  168|  2.48k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.58k, False: 899]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.58k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.58k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.58k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.58k|		return _ret; \
  |  |  |  |  172|  1.58k|	} \
  |  |  |  |  173|  2.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 899]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|  2.48k|	}
  320|    159|	else   {
  321|    159|		memset(&path, 0, sizeof(path));
  322|    159|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    159|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  323|    159|		memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  324|    159|		path.len = card->ef_atr->aid.len;
  325|    159|		rv = iasecc_select_file(card, &path, file_out);
  326|    159|		LOG_TEST_RET(ctx, rv, "Unable to ROOT selection");
  ------------------
  |  |  174|    159|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    159|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    159|	int _ret = (r); \
  |  |  |  |  168|    159|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 78, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|     78|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     78|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     78|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     78|		return _ret; \
  |  |  |  |  172|     78|	} \
  |  |  |  |  173|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|    159|	}
  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|    980|	mf_file = sc_file_new();
  334|    980|	if (mf_file == NULL)
  ------------------
  |  Branch (334:6): [True: 0, False: 980]
  ------------------
  335|    980|		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|    980|	mf_file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    980|#define SC_FILE_TYPE_DF			0x04
  ------------------
  337|    980|	mf_file->path = path;
  338|       |
  339|    980|	sc_invalidate_cache(card);
  340|    980|	sc_file_dup(&prv->cache.current_df, mf_file);
  341|    980|	prv->cache.valid = 1;
  342|       |
  343|    980|	if (file_out && *file_out == NULL)
  ------------------
  |  Branch (343:6): [True: 834, False: 146]
  |  Branch (343:18): [True: 813, False: 21]
  ------------------
  344|    813|		*file_out = mf_file;
  345|    167|	else
  346|    167|		sc_file_free(mf_file);
  347|       |
  348|    980|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    980|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    980|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    980|	int _ret = r; \
  |  |  |  |  155|    980|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 980, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    980|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 980]
  |  |  |  |  ------------------
  |  |  |  |  157|    980|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    980|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    980|	return _ret; \
  |  |  |  |  163|    980|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|    980|}
card-iasecc.c:iasecc_select_file:
  863|  5.94k|{
  864|  5.94k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  865|  5.94k|	struct sc_context *ctx = card->ctx;
  866|  5.94k|	struct sc_path lpath;
  867|  5.94k|	int rv, ii;
  868|       |
  869|  5.94k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.94k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.94k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.94k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.94k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.94k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  870|  5.94k|	memcpy(&lpath, path, sizeof(struct sc_path));
  871|  5.94k|	if (file_out)
  ------------------
  |  Branch (871:6): [True: 2.85k, False: 3.09k]
  ------------------
  872|  2.85k|		*file_out = NULL;
  873|       |
  874|  5.94k|	sc_log(ctx, "iasecc_select_file(card:%p) path.len %zu; path.type %i; aid_len %zu",
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  875|  5.94k|			card, path->len, path->type, path->aid.len);
  876|  5.94k|	sc_log(ctx, "iasecc_select_file() path:%s", sc_print_path(path));
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  877|       |
  878|  5.94k|	if ((!iasecc_is_cpx(card)) &&
  ------------------
  |  Branch (878:6): [True: 5.15k, False: 790]
  ------------------
  879|  5.15k|	    (card->type != SC_CARD_TYPE_IASECC_GEMALTO) &&
  ------------------
  |  Branch (879:6): [True: 4.09k, False: 1.05k]
  ------------------
  880|  4.09k|	    (path->type != SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  8.19k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (880:7): [True: 2.77k, False: 1.32k]
  ------------------
  881|  2.77k|			&& lpath.len >= 2
  ------------------
  |  Branch (881:7): [True: 2.77k, False: 3]
  ------------------
  882|  2.77k|			&& lpath.value[0] == 0x3F && lpath.value[1] == 0x00))   {
  ------------------
  |  Branch (882:7): [True: 2.62k, False: 151]
  |  Branch (882:33): [True: 2.58k, False: 33]
  ------------------
  883|  2.58k|		sc_log(ctx, "EF.ATR(aid:'%s')", card->ef_atr ? sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len) : "");
  ------------------
  |  |   71|  5.17k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 2.01k, False: 576]
  |  |  ------------------
  ------------------
  884|       |
  885|  2.58k|		rv = iasecc_select_mf(card, file_out);
  886|  2.58k|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|  2.58k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.58k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.58k|	int _ret = (r); \
  |  |  |  |  168|  2.58k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.65k, False: 937]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.65k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.65k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.65k|		return _ret; \
  |  |  |  |  172|  1.65k|	} \
  |  |  |  |  173|  2.58k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 937]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  887|       |
  888|    937|		memmove(&lpath.value[0], &lpath.value[2], lpath.len - 2);
  889|    937|		lpath.len -=  2;
  890|    937|	}
  891|       |
  892|  4.29k|	if (lpath.aid.len)	{
  ------------------
  |  Branch (892:6): [True: 192, False: 4.10k]
  ------------------
  893|    192|		struct sc_file *file = NULL;
  894|    192|		struct sc_path ppath;
  895|       |
  896|    192|		sc_log(ctx, "iasecc_select_file() select parent AID:%p/%zu", lpath.aid.value, lpath.aid.len);
  ------------------
  |  |   71|    192|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  897|    192|		sc_log(ctx, "iasecc_select_file() select parent AID:%s", sc_dump_hex(lpath.aid.value, lpath.aid.len));
  ------------------
  |  |   71|    192|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  898|    192|		memset(&ppath, 0, sizeof(ppath));
  899|    192|		memcpy(ppath.value, lpath.aid.value, lpath.aid.len);
  900|    192|		ppath.len = lpath.aid.len;
  901|    192|		ppath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    192|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  902|       |
  903|    192|		rv = iasecc_select_file(card, &ppath, &file);
  904|    192|		LOG_TEST_GOTO_ERR(ctx, rv, "select AID path failed");
  ------------------
  |  |  184|    192|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    192|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    192|	int _ret = (r); \
  |  |  |  |  178|    192|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 84, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  179|     84|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     84|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     84|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     84|		goto err; \
  |  |  |  |  182|     84|	} \
  |  |  |  |  183|    192|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  905|       |
  906|    108|		if (file_out) {
  ------------------
  |  Branch (906:7): [True: 108, False: 0]
  ------------------
  907|    108|			sc_file_free(*file_out);
  908|    108|			*file_out = file;
  909|    108|		} else {
  910|      0|			sc_file_free(file);
  911|      0|		}
  912|       |
  913|    108|		if (lpath.type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|    108|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (913:7): [True: 0, False: 108]
  ------------------
  914|      0|			lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  915|    108|	}
  916|       |
  917|  4.21k|	if (lpath.type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  4.21k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (917:6): [True: 1.91k, False: 2.29k]
  ------------------
  918|  1.91k|		lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|  1.91k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  919|       |
  920|  4.21k|	if (!lpath.len) {
  ------------------
  |  Branch (920:6): [True: 5, False: 4.20k]
  ------------------
  921|      5|		if (file_out) {
  ------------------
  |  Branch (921:7): [True: 3, False: 2]
  ------------------
  922|      3|			sc_file_free(*file_out);
  923|      3|			*file_out = NULL;
  924|      3|		}
  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|  4.20k|	do   {
  929|  4.20k|		struct sc_apdu apdu;
  930|  4.20k|		struct sc_file *file = NULL;
  931|  4.20k|		unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  932|  4.20k|		size_t pathlen = lpath.len;
  933|       |
  934|  4.20k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  4.20k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  935|       |
  936|  4.20k|		if (card->type != SC_CARD_TYPE_IASECC_GEMALTO
  ------------------
  |  Branch (936:7): [True: 3.20k, False: 1.00k]
  ------------------
  937|  3.20k|				&& card->type != SC_CARD_TYPE_IASECC_OBERTHUR
  ------------------
  |  Branch (937:8): [True: 2.96k, False: 237]
  ------------------
  938|  2.96k|				&& card->type != SC_CARD_TYPE_IASECC_SAGEM
  ------------------
  |  Branch (938:8): [True: 772, False: 2.19k]
  ------------------
  939|    772|				&& card->type != SC_CARD_TYPE_IASECC_AMOS
  ------------------
  |  Branch (939:8): [True: 772, False: 0]
  ------------------
  940|    772|				&& card->type != SC_CARD_TYPE_IASECC_MI
  ------------------
  |  Branch (940:8): [True: 772, False: 0]
  ------------------
  941|    772|				&& card->type != SC_CARD_TYPE_IASECC_MI2
  ------------------
  |  Branch (941:8): [True: 772, False: 0]
  ------------------
  942|    772|				&& !iasecc_is_cpx(card)) {
  ------------------
  |  Branch (942:8): [True: 0, False: 772]
  ------------------
  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|  4.20k|		if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  4.20k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (947:7): [True: 8, False: 4.19k]
  ------------------
  948|      8|			apdu.p1 = 0x02;
  949|      8|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (949:8): [True: 0, False: 8]
  ------------------
  950|      0|				apdu.p1 = 0x01;
  951|      8|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (951:8): [True: 0, False: 8]
  ------------------
  952|      8|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (952:8): [True: 0, False: 8]
  ------------------
  953|      8|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (953:8): [True: 0, False: 8]
  ------------------
  954|      8|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (954:8): [True: 0, False: 8]
  ------------------
  955|      8|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (955:8): [True: 1, False: 7]
  ------------------
  956|      7|			    iasecc_is_cpx(card)
  ------------------
  |  Branch (956:8): [True: 4, False: 3]
  ------------------
  957|      8|			    )   {
  958|      5|				apdu.p2 = 0x04;
  959|      5|			}
  960|      8|		}
  961|  4.19k|		else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|  4.19k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (961:12): [True: 1.91k, False: 2.28k]
  ------------------
  962|  1.91k|			apdu.p1 = 0x09;
  963|  1.91k|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (963:8): [True: 60, False: 1.85k]
  ------------------
  964|  1.85k|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (964:8): [True: 0, False: 1.85k]
  ------------------
  965|  1.85k|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (965:8): [True: 0, False: 1.85k]
  ------------------
  966|  1.85k|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (966:8): [True: 0, False: 1.85k]
  ------------------
  967|  1.85k|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (967:8): [True: 380, False: 1.47k]
  ------------------
  968|  1.47k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (968:8): [True: 431, False: 1.04k]
  ------------------
  969|    871|				apdu.p2 = 0x04;
  970|    871|			}
  971|  1.91k|		}
  972|  2.28k|		else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|  2.28k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (972:12): [True: 0, False: 2.28k]
  ------------------
  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|  2.28k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  2.28k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (977:12): [True: 2.28k, False: 0]
  ------------------
  978|  2.28k|			apdu.p1 = 0x04;
  979|  2.28k|			if (card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (979:8): [True: 0, False: 2.28k]
  ------------------
  980|  2.28k|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (980:8): [True: 0, False: 2.28k]
  ------------------
  981|  2.28k|			    card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (981:8): [True: 177, False: 2.10k]
  ------------------
  982|  2.10k|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (982:8): [True: 621, False: 1.48k]
  ------------------
  983|  1.48k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (983:8): [True: 337, False: 1.14k]
  ------------------
  984|  1.13k|				apdu.p2 = 0x04;
  985|  1.13k|			}
  986|  2.28k|		}
  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|  4.41k|		for (ii=0; ii<2; ii++)   {
  ------------------
  |  Branch (993:14): [True: 4.41k, False: 0]
  ------------------
  994|  4.41k|			apdu.lc = pathlen;
  995|  4.41k|			apdu.data = lpath.value;
  996|  4.41k|			apdu.datalen = pathlen;
  997|       |
  998|  4.41k|			apdu.resp = rbuf;
  999|  4.41k|			apdu.resplen = sizeof(rbuf);
 1000|  4.41k|			apdu.le = 256;
 1001|       |
 1002|  4.41k|			rv = sc_transmit_apdu(card, &apdu);
 1003|  4.41k|			LOG_TEST_GOTO_ERR(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  184|  4.41k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.41k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.41k|	int _ret = (r); \
  |  |  |  |  178|  4.41k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 110, False: 4.30k]
  |  |  |  |  ------------------
  |  |  |  |  179|    110|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    110|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    110|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    110|		goto err; \
  |  |  |  |  182|    110|	} \
  |  |  |  |  183|  4.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4.30k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1004|  4.30k|			rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|  4.30k|			if (rv == SC_ERROR_INCORRECT_PARAMETERS &&
  ------------------
  |  |   55|  8.60k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1005:8): [True: 267, False: 4.03k]
  ------------------
 1006|    267|					lpath.type == SC_PATH_TYPE_DF_NAME && apdu.p2 == 0x00)   {
  ------------------
  |  |  118|  4.57k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1006:6): [True: 243, False: 24]
  |  Branch (1006:44): [True: 209, False: 34]
  ------------------
 1007|    209|				sc_log(ctx, "Warning: SC_ERROR_INCORRECT_PARAMETERS for SC_PATH_TYPE_DF_NAME, try again with P2=0x0C");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1008|    209|				apdu.p2 = 0x0C;
 1009|    209|				continue;
 1010|    209|			}
 1011|       |
 1012|  4.09k|			if (ii)   {
  ------------------
  |  Branch (1012:8): [True: 209, False: 3.88k]
  ------------------
 1013|       |				/* 'SELECT AID' do not returned FCP. Try to emulate. */
 1014|    209|				apdu.resplen = sizeof(rbuf);
 1015|    209|				rv = iasecc_emulate_fcp(ctx, &apdu);
 1016|    209|				LOG_TEST_GOTO_ERR(ctx, rv, "Failed to emulate DF FCP");
  ------------------
  |  |  184|    209|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    209|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    209|	int _ret = (r); \
  |  |  |  |  178|    209|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 209]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    209|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 209]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1017|    209|			}
 1018|       |
 1019|  4.09k|			break;
 1020|  4.09k|		}
 1021|       |
 1022|  4.09k|		LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() check SW failed");
  ------------------
  |  |  184|  4.09k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.09k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.09k|	int _ret = (r); \
  |  |  |  |  178|  4.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.34k, False: 2.75k]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.34k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.34k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.34k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.34k|		goto err; \
  |  |  |  |  182|  1.34k|	} \
  |  |  |  |  183|  4.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.75k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1023|       |
 1024|  2.75k|		sc_log(ctx, "iasecc_select_file() apdu.resp %zu", apdu.resplen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1025|  2.75k|		if (apdu.resplen)   {
  ------------------
  |  Branch (1025:7): [True: 1.31k, False: 1.44k]
  ------------------
 1026|  1.31k|			sc_log(ctx, "apdu.resp %02X:%02X:%02X...", apdu.resp[0], apdu.resp[1], apdu.resp[2]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1027|       |
 1028|  1.31k|			switch (apdu.resp[0]) {
 1029|    243|			case 0x62:
  ------------------
  |  Branch (1029:4): [True: 243, False: 1.07k]
  ------------------
 1030|  1.09k|			case 0x6F:
  ------------------
  |  Branch (1030:4): [True: 847, False: 467]
  ------------------
 1031|  1.09k|				file = sc_file_new();
 1032|  1.09k|				if (file == NULL) {
  ------------------
  |  Branch (1032:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|				file->path = lpath;
 1040|       |
 1041|  1.09k|				rv = iasecc_process_fci(card, file, apdu.resp, apdu.resplen);
 1042|  1.09k|				if (rv) {
  ------------------
  |  Branch (1042:9): [True: 122, False: 968]
  ------------------
 1043|    122|					sc_file_free(file);
 1044|    122|					if (file_out) {
  ------------------
  |  Branch (1044:10): [True: 44, False: 78]
  ------------------
 1045|     44|						sc_file_free(*file_out);
 1046|     44|						*file_out = NULL;
 1047|     44|					}
 1048|    122|					LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    122|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    122|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    122|	int _ret = r; \
  |  |  |  |  155|    122|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 122, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    122|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    122|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 122, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    122|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    122|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    122|	return _ret; \
  |  |  |  |  163|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|    122|				}
 1050|    968|				break;
 1051|    968|			default:
  ------------------
  |  Branch (1051:4): [True: 224, False: 1.09k]
  ------------------
 1052|    224|				if (file_out) {
  ------------------
  |  Branch (1052:9): [True: 76, False: 148]
  ------------------
 1053|     76|					sc_file_free(*file_out);
 1054|     76|					*file_out = NULL;
 1055|     76|				}
 1056|    224|				LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    224|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    224|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    224|	int _ret = r; \
  |  |  |  |  155|    224|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 224, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    224|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    224|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 224, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    224|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    224|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    224|	return _ret; \
  |  |  |  |  163|    224|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1057|  1.31k|			}
 1058|       |
 1059|    968|			sc_log(ctx, "FileType %i", file->type);
  ------------------
  |  |   71|    968|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1060|    968|			if (file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|    968|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1060:8): [True: 225, False: 743]
  ------------------
 1061|    225|				sc_invalidate_cache(card);
 1062|    225|				sc_file_dup(&prv->cache.current_df, file);
 1063|    225|				prv->cache.valid = 1;
 1064|    225|			}
 1065|    743|			else   {
 1066|    743|				sc_file_free(prv->cache.current_ef);
 1067|    743|				sc_file_dup(&prv->cache.current_ef, file);
 1068|    743|				prv->cache.valid = 1;
 1069|    743|			}
 1070|       |
 1071|    968|			if (file_out)   {
  ------------------
  |  Branch (1071:8): [True: 586, False: 382]
  ------------------
 1072|    586|				sc_file_free(*file_out);
 1073|    586|				*file_out = file;
 1074|    586|			}
 1075|    382|			else   {
 1076|    382|				sc_file_free(file);
 1077|    382|			}
 1078|    968|		}
 1079|  1.44k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.44k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1079:12): [True: 676, False: 764]
  ------------------
 1080|    676|			sc_invalidate_cache(card);
 1081|    676|			prv->cache.valid = 1;
 1082|    676|		}
 1083|  2.75k|	} while(0);
  ------------------
  |  Branch (1083:10): [Folded, False: 2.40k]
  ------------------
 1084|       |
 1085|  2.40k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.40k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.40k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.40k|	int _ret = r; \
  |  |  |  |  155|  2.40k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.40k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.40k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.40k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.40k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.40k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.40k|	return _ret; \
  |  |  |  |  163|  2.40k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1086|  1.53k|err:
 1087|  1.53k|	if (file_out) {
  ------------------
  |  Branch (1087:6): [True: 394, False: 1.14k]
  ------------------
 1088|    394|		sc_file_free(*file_out);
 1089|       |		*file_out = NULL;
 1090|    394|	}
 1091|  1.53k|	return rv;
 1092|  2.40k|}
card-iasecc.c:iasecc_emulate_fcp:
  828|    209|{
  829|    209|	unsigned char dummy_df_fcp[] = {
  830|    209|		0x62,0xFF,
  831|    209|			0x82,0x01,0x38,
  832|    209|			0x8A,0x01,0x05,
  833|    209|			0xA1,0x04,0x8C,0x02,0x02,0x00,
  834|    209|			0x84,0xFF,
  835|    209|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  836|    209|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  837|    209|	};
  838|       |
  839|    209|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    209|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    209|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    209|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    209|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 209]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|       |
  841|    209|	if (apdu->p1 != 0x04)
  ------------------
  |  Branch (841:6): [True: 0, False: 209]
  ------------------
  842|    209|		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|    209|	if (apdu->datalen > 16)
  ------------------
  |  Branch (843:6): [True: 0, False: 209]
  ------------------
  844|    209|		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|    209|	if (apdu->resplen < apdu->datalen + 16)
  ------------------
  |  Branch (845:6): [True: 0, False: 209]
  ------------------
  846|    209|		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|    209|	memcpy(dummy_df_fcp + 16, apdu->data, apdu->datalen);
  849|    209|	dummy_df_fcp[15] = apdu->datalen;
  850|    209|	dummy_df_fcp[1] = apdu->datalen + 14;
  851|    209|	apdu->resplen = apdu->datalen + 16;
  852|    209|	memcpy(apdu->resp, dummy_df_fcp, apdu->resplen);
  853|       |
  854|    209|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    209|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    209|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    209|	int _ret = r; \
  |  |  |  |  155|    209|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 209, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    209|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 209]
  |  |  |  |  ------------------
  |  |  |  |  157|    209|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    209|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    209|	return _ret; \
  |  |  |  |  163|    209|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  855|    209|}
card-iasecc.c:iasecc_process_fci:
 1098|  1.09k|{
 1099|  1.09k|	struct sc_context *ctx = card->ctx;
 1100|  1.09k|	size_t taglen, offs, ii;
 1101|  1.09k|	int rv;
 1102|  1.09k|	const unsigned char *acls = NULL, *tag = NULL;
 1103|  1.09k|	unsigned char mask;
 1104|  1.09k|	unsigned char ops_DF[7] = {
 1105|  1.09k|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  168|  1.09k|#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|  1.09k|#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|  1.09k|#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|  1.09k|#define SC_AC_OP_CREATE			3
  ------------------
 1106|  1.09k|	};
 1107|  1.09k|	unsigned char ops_EF[7] = {
 1108|  1.09k|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  168|  1.09k|#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|  1.09k|#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|  1.09k|#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|  1.09k|#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|  1.09k|#define SC_AC_OP_READ			22
  ------------------
 1109|  1.09k|	};
 1110|       |
 1111|  1.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1112|       |
 1113|  1.09k|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x6F, &taglen);
 1114|  1.09k|	sc_log(ctx, "processing FCI: 0x6F tag %p", tag);
  ------------------
  |  |   71|  1.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1115|  1.09k|	if (tag != NULL) {
  ------------------
  |  Branch (1115:6): [True: 811, False: 279]
  ------------------
 1116|    811|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1117|    811|		buf = tag;
 1118|    811|		buflen = taglen;
 1119|    811|	}
 1120|       |
 1121|  1.09k|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x62, &taglen);
 1122|  1.09k|	sc_log(ctx, "processing FCI: 0x62 tag %p", tag);
  ------------------
  |  |   71|  1.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1123|  1.09k|	if (tag != NULL) {
  ------------------
  |  Branch (1123:6): [True: 228, False: 862]
  ------------------
 1124|    228|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    228|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1125|    228|		buf = tag;
 1126|    228|		buflen = taglen;
 1127|    228|	}
 1128|       |
 1129|  1.09k|	rv = iso_ops->process_fci(card, file, buf, buflen);
 1130|  1.09k|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|  1.09k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.09k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.09k|	int _ret = (r); \
  |  |  |  |  168|  1.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.09k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|  1.09k|	sc_log(ctx, "iasecc_process_fci() type %i; let's parse file ACLs", file->type);
  ------------------
  |  |   71|  1.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1138|  1.09k|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS, &taglen);
  ------------------
  |  |   39|  1.09k|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
 1139|  1.09k|	if (tag)
  ------------------
  |  Branch (1139:6): [True: 210, False: 880]
  ------------------
 1140|    210|		acls = sc_asn1_find_tag(ctx, tag, taglen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    210|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1141|    880|	else
 1142|    880|		acls = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    880|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1143|       |
 1144|  1.09k|	if (!acls)   {
  ------------------
  |  Branch (1144:6): [True: 122, False: 968]
  ------------------
 1145|    122|		sc_log(ctx, "ACLs not found in data(%zu) %s", buflen, sc_dump_hex(buf, buflen));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1146|    122|		LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|    122|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    122|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    122|	int _ret = (r); \
  |  |  |  |  168|    122|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 122, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    122|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    122|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    122|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    122|		return _ret; \
  |  |  |  |  172|    122|	} \
  |  |  |  |  173|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|    122|	}
 1148|       |
 1149|    968|	sc_log(ctx, "ACLs(%zu) '%s'", taglen, sc_dump_hex(acls, taglen));
  ------------------
  |  |   71|    968|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1150|    968|	mask = 0x40, offs = 1;
 1151|  6.80k|	for (ii = 0; ii < 7; ii++, mask /= 2)  {
  ------------------
  |  Branch (1151:15): [True: 6.17k, False: 622]
  ------------------
 1152|  6.17k|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|  6.17k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1152:22): [True: 1.54k, False: 4.62k]
  ------------------
 1153|       |
 1154|       |		/* avoid any access to acls[offs] beyond the taglen */
 1155|  6.17k|		if (offs >= taglen) {
  ------------------
  |  Branch (1155:7): [True: 346, False: 5.83k]
  ------------------
 1156|    346|			sc_log(ctx, "Warning: Invalid offset reached during ACL parsing");
  ------------------
  |  |   71|    346|#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|    346|			break;
 1158|    346|		}
 1159|  5.83k|		if (!(mask & acls[0]))
  ------------------
  |  Branch (1159:7): [True: 2.99k, False: 2.83k]
  ------------------
 1160|  2.99k|			continue;
 1161|       |
 1162|  2.83k|		sc_log(ctx, "ACLs mask 0x%X, offs %zu, op 0x%X, acls[offs] 0x%X", mask, offs, op, acls[offs]);
  ------------------
  |  |   71|  2.83k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1163|  2.83k|		if (op == 0xFF)   {
  ------------------
  |  Branch (1163:7): [True: 742, False: 2.09k]
  ------------------
 1164|    742|			;
 1165|    742|		}
 1166|  2.09k|		else if (acls[offs] == 0)   {
  ------------------
  |  Branch (1166:12): [True: 345, False: 1.75k]
  ------------------
 1167|    345|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|    345|#define SC_AC_NONE			0x00000000
  ------------------
 1168|    345|		}
 1169|  1.75k|		else if (acls[offs] == 0xFF)   {
  ------------------
  |  Branch (1169:12): [True: 225, False: 1.52k]
  ------------------
 1170|    225|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    225|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1171|    225|		}
 1172|  1.52k|		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   89|  1.52k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
              		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   93|  1.52k|#define IASECC_SCB_METHOD_USER_AUTH	0x10
  ------------------
  |  Branch (1172:12): [True: 107, False: 1.41k]
  ------------------
 1173|    107|			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |  156|    107|#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|    107|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
 1174|    107|		}
 1175|  1.41k|		else if (acls[offs] & IASECC_SCB_METHOD_MASK)   {
  ------------------
  |  |   89|  1.41k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
  |  Branch (1175:12): [True: 1.20k, False: 218]
  ------------------
 1176|  1.20k|			sc_file_add_acl_entry(file, op, SC_AC_SCB, acls[offs]);
  ------------------
  |  |  157|  1.20k|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
 1177|  1.20k|		}
 1178|    218|		else   {
 1179|    218|			sc_log(ctx, "Warning: non supported SCB method: %X", acls[offs]);
  ------------------
  |  |   71|    218|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1180|    218|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    218|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1181|    218|		}
 1182|       |
 1183|  2.83k|		offs++;
 1184|  2.83k|	}
 1185|       |
 1186|    968|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    968|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    968|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    968|	int _ret = r; \
  |  |  |  |  155|    968|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 968, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    968|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 968]
  |  |  |  |  ------------------
  |  |  |  |  157|    968|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    968|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    968|	return _ret; \
  |  |  |  |  163|    968|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1187|    968|}
card-iasecc.c:iasecc_se_get_info_from_cache:
 1568|    131|{
 1569|    131|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1570|    131|	struct sc_context *ctx = card->ctx;
 1571|    131|	struct iasecc_se_info *si = NULL;
 1572|    131|	int rv;
 1573|       |
 1574|    131|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    131|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    131|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    131|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    131|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 131]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1575|       |
 1576|    131|	for(si = prv->se_info; si; si = si->next)   {
  ------------------
  |  Branch (1576:25): [True: 0, False: 131]
  ------------------
 1577|      0|		if (si->reference != se->reference)
  ------------------
  |  Branch (1577:7): [True: 0, False: 0]
  ------------------
 1578|      0|			continue;
 1579|      0|		if (!(prv->cache.valid && prv->cache.current_df) && si->df)
  ------------------
  |  Branch (1579:9): [True: 0, False: 0]
  |  Branch (1579:29): [True: 0, False: 0]
  |  Branch (1579:55): [True: 0, False: 0]
  ------------------
 1580|      0|			continue;
 1581|      0|		if (prv->cache.valid && prv->cache.current_df && !si->df)
  ------------------
  |  Branch (1581:7): [True: 0, False: 0]
  |  Branch (1581:27): [True: 0, False: 0]
  |  Branch (1581:52): [True: 0, False: 0]
  ------------------
 1582|      0|			continue;
 1583|      0|		if (prv->cache.valid && prv->cache.current_df && si->df)
  ------------------
  |  Branch (1583:7): [True: 0, False: 0]
  |  Branch (1583:27): [True: 0, False: 0]
  |  Branch (1583:52): [True: 0, False: 0]
  ------------------
 1584|      0|			if (memcmp(&prv->cache.current_df->path, &si->df->path, sizeof(struct sc_path)))
  ------------------
  |  Branch (1584:8): [True: 0, False: 0]
  ------------------
 1585|      0|				continue;
 1586|      0|		break;
 1587|      0|	}
 1588|       |
 1589|    131|	if (!si)
  ------------------
  |  Branch (1589:6): [True: 131, False: 0]
  ------------------
 1590|    131|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    131|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1591|       |
 1592|      0|	memcpy(se, si, sizeof(struct iasecc_se_info));
 1593|       |
 1594|      0|	if (si->df)   {
  ------------------
  |  Branch (1594:6): [True: 0, False: 0]
  ------------------
 1595|      0|		sc_file_dup(&se->df, si->df);
 1596|      0|		if (se->df == NULL)
  ------------------
  |  Branch (1596:7): [True: 0, False: 0]
  ------------------
 1597|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1598|      0|	}
 1599|       |
 1600|      0|	rv = iasecc_docp_copy(ctx, &si->docp, &se->docp);
 1601|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1602|       |
 1603|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1604|      0|}
card-iasecc.c:iasecc_se_cache_info:
 1525|      9|{
 1526|      9|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1527|      9|	struct sc_context *ctx = card->ctx;
 1528|      9|	struct iasecc_se_info *se_info = NULL, *si = NULL;
 1529|      9|	int rv;
 1530|       |
 1531|      9|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      9|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      9|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1532|       |
 1533|      9|	se_info = calloc(1, sizeof(struct iasecc_se_info));
 1534|      9|	if (!se_info)
  ------------------
  |  Branch (1534:6): [True: 0, False: 9]
  ------------------
 1535|      9|		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|      9|	memcpy(se_info, se, sizeof(struct iasecc_se_info));
 1537|       |
 1538|      9|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (1538:6): [True: 9, False: 0]
  |  Branch (1538:26): [True: 8, False: 1]
  ------------------
 1539|      8|		sc_file_dup(&se_info->df, prv->cache.current_df);
 1540|      8|		if (se_info->df == NULL)   {
  ------------------
  |  Branch (1540:7): [True: 0, False: 8]
  ------------------
 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|      8|	}
 1545|       |
 1546|      9|	rv = iasecc_docp_copy(ctx, &se->docp, &se_info->docp);
 1547|      9|	if (rv < 0)   {
  ------------------
  |  Branch (1547:6): [True: 0, False: 9]
  ------------------
 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|      9|	if (!prv->se_info)   {
  ------------------
  |  Branch (1553:6): [True: 9, False: 0]
  ------------------
 1554|      9|		prv->se_info = se_info;
 1555|      9|	}
 1556|      0|	else    {
 1557|      0|		for (si = prv->se_info; si->next; si = si->next)
  ------------------
  |  Branch (1557:27): [True: 0, False: 0]
  ------------------
 1558|      0|			;
 1559|      0|		si->next = se_info;
 1560|      0|	}
 1561|       |
 1562|      9|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1563|      9|}
card-iasecc.c:sc_get_driver:
 3591|  15.7k|{
 3592|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3593|       |
 3594|  15.7k|	if (!iso_ops)
  ------------------
  |  Branch (3594:6): [True: 1, False: 15.7k]
  ------------------
 3595|      1|		iso_ops = iso_drv->ops;
 3596|       |
 3597|  15.7k|	iasecc_ops = *iso_ops;
 3598|       |
 3599|  15.7k|	iasecc_ops.match_card = iasecc_match_card;
 3600|  15.7k|	iasecc_ops.init = iasecc_init;
 3601|  15.7k|	iasecc_ops.finish = iasecc_finish;
 3602|  15.7k|	iasecc_ops.read_binary = iasecc_read_binary;
 3603|       |	/*	write_binary: ISO7816 implementation works	*/
 3604|       |	/*	update_binary: ISO7816 implementation works	*/
 3605|  15.7k|	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|  15.7k|	iasecc_ops.select_file = iasecc_select_file;
 3612|       |	/*	get_response: Untested	*/
 3613|  15.7k|	iasecc_ops.get_challenge = iasecc_get_challenge;
 3614|  15.7k|	iasecc_ops.logout = iasecc_logout;
 3615|       |	/*	restore_security_env	*/
 3616|  15.7k|	iasecc_ops.set_security_env = iasecc_set_security_env;
 3617|  15.7k|	iasecc_ops.decipher = iasecc_decipher;
 3618|  15.7k|	iasecc_ops.compute_signature = iasecc_compute_signature;
 3619|  15.7k|	iasecc_ops.create_file = iasecc_create_file;
 3620|  15.7k|	iasecc_ops.delete_file = iasecc_delete_file;
 3621|       |	/*	list_files	*/
 3622|  15.7k|	iasecc_ops.check_sw = iasecc_check_sw;
 3623|  15.7k|	iasecc_ops.card_ctl = iasecc_card_ctl;
 3624|  15.7k|	iasecc_ops.process_fci = iasecc_process_fci;
 3625|       |	/*	construct_fci: Not needed	*/
 3626|  15.7k|	iasecc_ops.pin_cmd = iasecc_pin_cmd;
 3627|       |	/*	get_data: Not implemented	*/
 3628|       |	/*	put_data: Not implemented	*/
 3629|       |	/*	delete_record: Not implemented	*/
 3630|       |
 3631|  15.7k|	iasecc_ops.read_public_key = iasecc_read_public_key;
 3632|       |
 3633|  15.7k|	return &iasecc_drv;
 3634|  15.7k|}
card-iasecc.c:iasecc_match_card:
  353|  11.2k|{
  354|  11.2k|	struct sc_context *ctx = card->ctx;
  355|  11.2k|	int i;
  356|       |
  357|  11.2k|	i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
  358|  11.2k|	if (i < 0)   {
  ------------------
  |  Branch (358:6): [True: 10.4k, False: 833]
  ------------------
  359|  10.4k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
  360|  10.4k|		return 0;
  361|  10.4k|	}
  362|       |
  363|    833|	sc_log(ctx, "'%s' card matched", iasecc_known_atrs[i].name);
  ------------------
  |  |   71|    833|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  364|    833|	return 1;
  365|  11.2k|}
card-iasecc.c:iasecc_init:
  624|    833|{
  625|    833|	struct sc_context *ctx = card->ctx;
  626|    833|	struct iasecc_private_data *private_data = NULL;
  627|    833|	int rv = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    833|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  628|    833|	void *old_drv_data = card->drv_data;
  629|       |
  630|    833|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    833|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    833|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    833|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    833|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 833]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|    833|	private_data = (struct iasecc_private_data *) calloc(1, sizeof(struct iasecc_private_data));
  632|    833|	if (private_data == NULL)
  ------------------
  |  Branch (632:6): [True: 0, False: 833]
  ------------------
  633|    833|		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|    833|	card->cla  = 0x00;
  636|    833|	card->drv_data = private_data;
  637|       |
  638|    833|	if (card->type == SC_CARD_TYPE_IASECC_GEMALTO)
  ------------------
  |  Branch (638:6): [True: 107, False: 726]
  ------------------
  639|    107|		rv = iasecc_init_gemalto(card);
  640|    726|	else if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (640:11): [True: 39, False: 687]
  ------------------
  641|     39|		rv = iasecc_init_oberthur(card);
  642|    687|	else if (card->type == SC_CARD_TYPE_IASECC_SAGEM)
  ------------------
  |  Branch (642:11): [True: 533, False: 154]
  ------------------
  643|    533|		rv = iasecc_init_amos_or_sagem(card);
  644|    154|	else if (card->type == SC_CARD_TYPE_IASECC_AMOS)
  ------------------
  |  Branch (644:11): [True: 0, False: 154]
  ------------------
  645|      0|		rv = iasecc_init_amos_or_sagem(card);
  646|    154|	else if (card->type == SC_CARD_TYPE_IASECC_MI)
  ------------------
  |  Branch (646:11): [True: 0, False: 154]
  ------------------
  647|      0|		rv = iasecc_init_amos_or_sagem(card);
  648|    154|	else if (iasecc_is_cpx(card))
  ------------------
  |  Branch (648:11): [True: 154, False: 0]
  ------------------
  649|    154|		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|    833|	if (!rv)   {
  ------------------
  |  Branch (655:6): [True: 548, False: 285]
  ------------------
  656|    548|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (656:7): [True: 548, False: 0]
  |  Branch (656:23): [True: 23, False: 525]
  ------------------
  657|     23|			struct sc_path path;
  658|       |
  659|     23|			memset(&path, 0, sizeof(struct sc_path));
  660|     23|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|     23|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  661|     23|			memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  662|     23|			path.len = card->ef_atr->aid.len;
  663|       |
  664|     23|			rv = iasecc_select_file(card, &path, NULL);
  665|     23|			sc_log(ctx, "Select ECC ROOT with the AID from EF.ATR: rv %i", rv);
  ------------------
  |  |   71|     23|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  666|     23|			LOG_TEST_GOTO_ERR(ctx, rv, "Select EF.ATR AID failed");
  ------------------
  |  |  184|     23|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     23|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     23|	int _ret = (r); \
  |  |  |  |  178|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|     23|		}
  668|       |
  669|    544|		iasecc_get_serialnr(card, NULL);
  670|    544|	}
  671|       |
  672|    829|#ifdef ENABLE_SM
  673|    829|	card->sm_ctx.ops.read_binary = _iasecc_sm_read_binary;
  674|    829|	card->sm_ctx.ops.update_binary = _iasecc_sm_update_binary;
  675|    829|#endif
  676|       |
  677|    829|	if (!rv && card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (677:6): [True: 544, False: 285]
  |  Branch (677:13): [True: 544, False: 0]
  |  Branch (677:29): [True: 19, False: 525]
  ------------------
  678|     19|		sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  679|     19|	}
  680|       |
  681|    833|err:
  682|    833|	if (rv < 0) {
  ------------------
  |  Branch (682:6): [True: 289, False: 544]
  ------------------
  683|    289|		sc_invalidate_cache(card);
  684|    289|		free(private_data);
  685|    289|		card->drv_data = old_drv_data;
  686|    544|	} else {
  687|    544|		free(old_drv_data);
  688|    544|	}
  689|       |
  690|    833|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    833|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    833|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    833|	int _ret = r; \
  |  |  |  |  155|    833|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 833, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    833|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    289|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 289, False: 544]
  |  |  |  |  ------------------
  |  |  |  |  157|    833|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    833|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    833|	return _ret; \
  |  |  |  |  163|    833|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|    833|}
card-iasecc.c:iasecc_init_gemalto:
  419|    107|{
  420|    107|	struct sc_context *ctx = card->ctx;
  421|    107|	struct sc_path path;
  422|    107|	unsigned int flags;
  423|    107|	int rv = 0;
  424|       |
  425|    107|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    107|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    107|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    107|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    107|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 107]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|       |
  427|    107|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    107|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    107|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    107|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    107|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    107|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    107|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    107|#define SC_ALGORITHM_RSA_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|    107|#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|    107|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    107|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    107|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    107|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    107|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    107|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    107|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  428|       |
  429|    107|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    107|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    107|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    107|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    107|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    107|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    107|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    107|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    107|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    107|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  430|       |
  431|    107|	sc_format_path("3F00", &path);
  432|    107|	if (SC_SUCCESS != sc_select_file(card, &path, NULL)) {
  ------------------
  |  |   28|    107|#define SC_SUCCESS				0
  ------------------
  |  Branch (432:6): [True: 83, False: 24]
  ------------------
  433|       |		/* Result ignored*/
  434|     83|		sc_log(card->ctx, "Warning, MF select failed");
  ------------------
  |  |   71|     83|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  435|     83|	}
  436|       |
  437|    107|	rv = iasecc_parse_ef_atr(card);
  438|    107|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  439|    107|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|    107|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (439:6): [True: 2, False: 105]
  ------------------
  440|      2|		sc_log(ctx, "Select MF");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  441|      2|		rv = iasecc_select_mf(card, NULL);
  442|      2|		sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  443|      2|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  444|       |
  445|      1|		rv = iasecc_parse_ef_atr(card);
  446|      1|		sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  447|      1|	}
  448|    106|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  449|    106|	LOG_TEST_RET(ctx, rv, "Cannot read/parse EF.ATR");
  ------------------
  |  |  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: 49, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  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|    106|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  450|       |
  451|     57|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  452|     57|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  453|       |
  454|     57|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|     57|}
card-iasecc.c:iasecc_parse_ef_atr:
  369|    862|{
  370|    862|	struct sc_context *ctx = card->ctx;
  371|    862|	struct iasecc_private_data *pdata = (struct iasecc_private_data *) card->drv_data;
  372|    862|	struct iasecc_version *version = &pdata->version;
  373|    862|	struct iasecc_io_buffer_sizes *sizes = &pdata->max_sizes;
  374|    862|	int rv;
  375|       |
  376|    862|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    862|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    862|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    862|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    862|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 862]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    862|	rv = sc_parse_ef_atr(card);
  378|    862|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    862|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    862|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    862|	int _ret = (r); \
  |  |  |  |  168|    862|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 198, False: 664]
  |  |  |  |  ------------------
  |  |  |  |  169|    198|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    198|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    198|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    198|		return _ret; \
  |  |  |  |  172|    198|	} \
  |  |  |  |  173|    862|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 664]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|    664|	if (card->ef_atr->pre_issuing_len < 4)
  ------------------
  |  Branch (380:6): [True: 110, False: 554]
  ------------------
  381|    664|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid pre-issuing data");
  ------------------
  |  |  174|    110|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    110|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    110|	int _ret = (r); \
  |  |  |  |  168|    110|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 110, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    110|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    110|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    110|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    110|		return _ret; \
  |  |  |  |  172|    110|	} \
  |  |  |  |  173|    110|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    554|	version->ic_manufacturer =	card->ef_atr->pre_issuing[0];
  384|    554|	version->ic_type =		card->ef_atr->pre_issuing[1];
  385|    554|	version->os_version =		card->ef_atr->pre_issuing[2];
  386|    554|	version->iasecc_version =	card->ef_atr->pre_issuing[3];
  387|    554|	sc_log(ctx, "EF.ATR: IC manufacturer/type %X/%X, OS/IasEcc versions %X/%X",
  ------------------
  |  |   71|    554|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  388|    554|		version->ic_manufacturer, version->ic_type, version->os_version, version->iasecc_version);
  389|       |
  390|    554|	if (card->ef_atr->issuer_data_len < 16)
  ------------------
  |  Branch (390:6): [True: 6, False: 548]
  ------------------
  391|    554|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid issuer data");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |
  393|    548|	sizes->send =	 card->ef_atr->issuer_data[2] * 0x100 + card->ef_atr->issuer_data[3];
  394|    548|	sizes->send_sc = card->ef_atr->issuer_data[6] * 0x100 + card->ef_atr->issuer_data[7];
  395|    548|	sizes->recv =	 card->ef_atr->issuer_data[10] * 0x100 + card->ef_atr->issuer_data[11];
  396|    548|	sizes->recv_sc = card->ef_atr->issuer_data[14] * 0x100 + card->ef_atr->issuer_data[15];
  397|       |
  398|    548|	sc_log(ctx, "EF.ATR: IO Buffer Size send/sc %zd/%zd recv/sc %zd/%zd",
  ------------------
  |  |   71|    548|#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|    548|			sizes->send, sizes->send_sc, sizes->recv, sizes->recv_sc);
  400|       |
  401|    548|	card->max_send_size = sizes->send;
  402|    548|	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|    548|	if (card->max_send_size > 0xFF)
  ------------------
  |  Branch (408:6): [True: 208, False: 340]
  ------------------
  409|    208|		card->max_send_size -= 5;
  410|       |
  411|    548|	sc_log(ctx, "EF.ATR: max send/recv sizes %zX/%zX", card->max_send_size, card->max_recv_size);
  ------------------
  |  |   71|    548|#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|    548|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    548|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    548|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    548|	int _ret = r; \
  |  |  |  |  155|    548|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 548, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    548|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 548]
  |  |  |  |  ------------------
  |  |  |  |  157|    548|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    548|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    548|	return _ret; \
  |  |  |  |  163|    548|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|    548|}
card-iasecc.c:iasecc_init_oberthur:
  488|     39|{
  489|     39|	struct sc_context *ctx = card->ctx;
  490|     39|	unsigned int flags;
  491|     39|	int rv = 0;
  492|       |
  493|     39|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     39|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     39|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     39|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     39|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 39]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|       |
  495|     39|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     39|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     39|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     39|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     39|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     39|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     39|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     39|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     39|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     39|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     39|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     39|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     39|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  496|       |
  497|     39|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  498|     39|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  499|       |
  500|     39|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     39|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     39|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     39|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     39|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     39|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     39|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     39|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     39|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     39|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  501|       |
  502|     39|	iasecc_parse_ef_atr(card);
  503|       |
  504|       |	/* if we fail to select CM, */
  505|     39|	if (gp_select_card_manager(card)) {
  ------------------
  |  Branch (505:6): [True: 17, False: 22]
  ------------------
  506|     17|		gp_select_isd_rid(card);
  507|     17|	}
  508|       |
  509|     39|	rv = iasecc_oberthur_match(card);
  510|     39|	LOG_TEST_RET(ctx, rv, "unknown Oberthur's IAS/ECC card");
  ------------------
  |  |  174|     39|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     39|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     39|	int _ret = (r); \
  |  |  |  |  168|     39|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 39]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|       |
  512|     39|	rv = iasecc_select_mf(card, NULL);
  513|     39|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|     39|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     39|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     39|	int _ret = (r); \
  |  |  |  |  168|     39|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|     24|	rv = iasecc_parse_ef_atr(card);
  516|     24|	LOG_TEST_RET(ctx, rv, "EF.ATR read or parse error");
  ------------------
  |  |  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: 11, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|       |
  518|     13|	sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.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__
  |  |  ------------------
  ------------------
  519|     13|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|     13|}
card-iasecc.c:iasecc_oberthur_match:
  460|     39|{
  461|     39|	struct sc_context *ctx = card->ctx;
  462|     39|	unsigned char *hist = card->reader->atr_info.hist_bytes;
  463|       |
  464|     39|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     39|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     39|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     39|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     39|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 39]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|       |
  466|     39|	if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
  ------------------
  |  Branch (466:6): [True: 0, False: 39]
  |  Branch (466:23): [True: 0, False: 39]
  ------------------
  467|     39|		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|     39|	sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
  ------------------
  |  |  129|     39|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     39|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|       |
  471|     39|	if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
  ------------------
  |  Branch (471:6): [True: 0, False: 39]
  ------------------
  472|     39|		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|     39|	if (!card->ef_atr)
  ------------------
  |  Branch (474:6): [True: 35, False: 4]
  ------------------
  475|     35|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  476|     39|	if (!card->ef_atr)
  ------------------
  |  Branch (476:6): [True: 0, False: 39]
  ------------------
  477|     39|		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|     39|	memcpy(card->ef_atr->aid.value, OberthurIASECC_AID.value, OberthurIASECC_AID.len);
  480|     39|	card->ef_atr->aid.len = OberthurIASECC_AID.len;
  481|       |
  482|     39|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     39|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  483|     39|}
card-iasecc.c:iasecc_init_amos_or_sagem:
  550|    533|{
  551|    533|	struct sc_context *ctx = card->ctx;
  552|    533|	unsigned int flags;
  553|    533|	int rv = 0;
  554|       |
  555|    533|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    533|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    533|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    533|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    533|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 533]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|       |
  557|    533|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    533|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    533|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    533|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    533|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    533|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    533|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    533|#define SC_ALGORITHM_RSA_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|    533|#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|    533|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    533|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    533|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    533|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    533|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    533|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    533|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  558|       |
  559|    533|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  560|    533|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  561|       |
  562|    533|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    533|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    533|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    533|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    533|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    533|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    533|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    533|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    533|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    533|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  563|       |
  564|    533|	if (card->type == SC_CARD_TYPE_IASECC_MI)   {
  ------------------
  |  Branch (564:6): [True: 0, False: 533]
  ------------------
  565|      0|		rv = iasecc_mi_match(card);
  566|      0|		if (rv)
  ------------------
  |  Branch (566:7): [True: 0, False: 0]
  ------------------
  567|      0|			card->type = SC_CARD_TYPE_IASECC_MI2;
  568|      0|		else
  569|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|      0|	}
  571|       |
  572|    533|	rv = iasecc_parse_ef_atr(card);
  573|    533|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|    533|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (573:6): [True: 7, False: 526]
  ------------------
  574|      7|		rv = iasecc_select_mf(card, NULL);
  575|      7|		LOG_TEST_RET(ctx, rv, "MF selection 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: 3, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  576|       |
  577|      4|		rv = iasecc_parse_ef_atr(card);
  578|      4|	}
  579|    530|	LOG_TEST_RET(ctx, rv, "IASECC: ATR parse failed");
  ------------------
  |  |  174|    530|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    530|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    530|	int _ret = (r); \
  |  |  |  |  168|    530|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 124, False: 406]
  |  |  |  |  ------------------
  |  |  |  |  169|    124|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    124|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    124|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    124|		return _ret; \
  |  |  |  |  172|    124|	} \
  |  |  |  |  173|    530|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 406]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|       |
  581|    406|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    406|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    406|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    406|	int _ret = r; \
  |  |  |  |  155|    406|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 406, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    406|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 406]
  |  |  |  |  ------------------
  |  |  |  |  157|    406|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    406|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    406|	return _ret; \
  |  |  |  |  163|    406|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|    406|}
card-iasecc.c:iasecc_init_cpx:
  600|    154|{
  601|    154|	struct sc_context *ctx = card->ctx;
  602|    154|	unsigned int flags;
  603|    154|	int rv = 0;
  604|       |
  605|    154|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    154|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    154|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    154|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    154|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 154]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  606|       |
  607|    154|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    154|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    154|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    154|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    154|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    154|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    154|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    154|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    154|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    154|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  608|       |
  609|    154|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    154|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    154|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    154|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    154|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    154|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    154|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    154|#define SC_ALGORITHM_RSA_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|    154|#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|    154|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    154|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    154|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    154|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    154|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    154|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    154|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  610|       |
  611|    154|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  612|    154|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  613|    154|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  614|       |
  615|    154|	rv = iasecc_parse_ef_atr(card);
  616|    154|	LOG_TEST_RET(ctx, rv, "Parse EF.ATR");
  ------------------
  |  |  174|    154|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    154|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    154|	int _ret = (r); \
  |  |  |  |  168|    154|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 82, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  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|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|       |
  618|     72|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     72|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     72|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     72|	int _ret = r; \
  |  |  |  |  155|     72|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 72, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     72|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  157|     72|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     72|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     72|	return _ret; \
  |  |  |  |  163|     72|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|     72|}
card-iasecc.c:iasecc_get_serialnr:
 2464|    829|{
 2465|    829|	struct sc_context *ctx = card->ctx;
 2466|    829|	struct sc_iin *iin = &card->serialnr.iin;
 2467|    829|	struct sc_apdu apdu;
 2468|    829|	unsigned char rbuf[0xC0];
 2469|    829|	size_t ii, offs, len;
 2470|    829|	int rv;
 2471|       |
 2472|    829|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    829|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    829|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    829|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    829|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 829]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2473|    829|	if (card->serialnr.len)
  ------------------
  |  Branch (2473:6): [True: 8, False: 821]
  ------------------
 2474|      8|		goto end;
 2475|       |
 2476|    821|	memset(&card->serialnr, 0, sizeof(card->serialnr));
 2477|       |
 2478|    821|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |  292|    821|#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|    821|#define IASECC_SFI_EF_SN	0x1C
  ------------------
 2479|    821|	apdu.le = sizeof(rbuf);
 2480|    821|	apdu.resp = rbuf;
 2481|    821|	apdu.resplen = sizeof(rbuf);
 2482|       |
 2483|    821|	rv = sc_transmit_apdu(card, &apdu);
 2484|    821|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    821|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    821|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    821|	int _ret = (r); \
  |  |  |  |  168|    821|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 812]
  |  |  |  |  ------------------
  |  |  |  |  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|    821|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 812]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2485|    812|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2486|    812|	LOG_TEST_RET(ctx, rv, "Get 'serial number' data failed");
  ------------------
  |  |  174|    812|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    812|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    812|	int _ret = (r); \
  |  |  |  |  168|    812|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 499, False: 313]
  |  |  |  |  ------------------
  |  |  |  |  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|    812|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 313]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2487|       |
 2488|    313|	if (apdu.resplen < 2 || rbuf[0] != ISO7812_PAN_SN_TAG || rbuf[1] > (apdu.resplen-2))
  ------------------
  |  |   29|    356|#define ISO7812_PAN_SN_TAG	0x5A
  ------------------
  |  Branch (2488:6): [True: 270, False: 43]
  |  Branch (2488:26): [True: 26, False: 17]
  |  Branch (2488:59): [True: 1, False: 16]
  ------------------
 2489|    313|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "serial number parse error");
  ------------------
  |  |  174|    297|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    297|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    297|	int _ret = (r); \
  |  |  |  |  168|    297|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 297, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    297|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    297|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    297|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    297|		return _ret; \
  |  |  |  |  172|    297|	} \
  |  |  |  |  173|    297|} 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: 6, False: 10]
  ------------------
 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|     70|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2517:14): [True: 60, False: 10]
  ------------------
 2518|     60|			*(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|     96|		for (ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (2525:13): [True: 80, False: 16]
  ------------------
 2526|     80|			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|     24|end:
 2532|     24|	if (serial)
  ------------------
  |  Branch (2532:6): [True: 12, False: 12]
  ------------------
 2533|     12|		memcpy(serial, &card->serialnr, sizeof(*serial));
 2534|       |
 2535|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2536|     24|}
card-iasecc.c:_iasecc_sm_read_binary:
  760|    194|{
  761|    194|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  762|    194|	struct sc_context *ctx = card->ctx;
  763|    194|	const struct sc_acl_entry *entry = NULL;
  764|    194|	int rv;
  765|       |
  766|    194|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    194|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    194|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    194|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    194|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 194]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|    194|	sc_log(ctx, "iasecc_sm_read_binary() card:%p offs:%i count:%zu ", card, offs, count);
  ------------------
  |  |   71|    194|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  768|    194|	if (offs > 0x7fff)
  ------------------
  |  Branch (768:6): [True: 0, False: 194]
  ------------------
  769|    194|		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|    194|	if (count == 0)
  ------------------
  |  Branch (771:6): [True: 0, False: 194]
  ------------------
  772|      0|		return 0;
  773|       |
  774|    194|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (774:6): [True: 194, False: 0]
  |  Branch (774:26): [True: 193, False: 1]
  ------------------
  775|    193|		entry = sc_file_get_acl_entry(prv->cache.current_ef, SC_AC_OP_READ);
  ------------------
  |  |  188|    193|#define SC_AC_OP_READ			22
  ------------------
  776|    193|		if (!entry)
  ------------------
  |  Branch (776:7): [True: 23, False: 170]
  ------------------
  777|    193|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "iasecc_sm_read() 'READ' ACL not present");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     23|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     23|		return _ret; \
  |  |  |  |  172|     23|	} \
  |  |  |  |  173|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|       |
  779|    170|		sc_log(ctx, "READ method/reference %X/%X", entry->method, entry->key_ref);
  ------------------
  |  |   71|    170|#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|    170|		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |  157|    170|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
              		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |   91|    147|#define IASECC_SCB_METHOD_SM		0x40
  ------------------
  |  Branch (780:7): [True: 147, False: 23]
  |  Branch (780:39): [True: 139, False: 8]
  ------------------
  781|    139|			unsigned char se_num = entry->key_ref & IASECC_SCB_METHOD_MASK_REF;
  ------------------
  |  |   90|    139|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
  782|       |
  783|    139|			rv = iasecc_sm_read_binary(card, se_num, offs, buff, count);
  784|    139|			LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|    139|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 139, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|    139|		}
  786|    170|	}
  787|       |
  788|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|     32|}
card-iasecc.c:iasecc_finish:
 1414|    544|{
 1415|    544|	struct sc_context *ctx = card->ctx;
 1416|    544|	struct iasecc_private_data *private_data = (struct iasecc_private_data *)card->drv_data;
 1417|    544|	struct iasecc_se_info *se_info = private_data->se_info, *next;
 1418|       |
 1419|    544|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    544|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    544|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    544|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    544|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 544]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1420|       |
 1421|    544|	sc_invalidate_cache(card);
 1422|       |
 1423|    553|	while (se_info)   {
  ------------------
  |  Branch (1423:9): [True: 9, False: 544]
  ------------------
 1424|      9|		sc_file_free(se_info->df);
 1425|      9|		next = se_info->next;
 1426|      9|		free(se_info);
 1427|      9|		se_info = next;
 1428|      9|	}
 1429|       |
 1430|    544|	free(card->drv_data);
 1431|    544|	card->drv_data = NULL;
 1432|       |
 1433|    544|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    544|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    544|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    544|	int _ret = r; \
  |  |  |  |  155|    544|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 544, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    544|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 544]
  |  |  |  |  ------------------
  |  |  |  |  157|    544|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    544|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    544|	return _ret; \
  |  |  |  |  163|    544|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1434|    544|}
card-iasecc.c:iasecc_read_binary:
  697|  2.08k|{
  698|  2.08k|	struct sc_context *ctx = card->ctx;
  699|  2.08k|	struct sc_apdu apdu;
  700|  2.08k|	int rv;
  701|       |
  702|  2.08k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.08k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.08k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.08k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.08k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  703|  2.08k|	sc_log(ctx, "iasecc_read_binary(card:%p) offs %i; count %zu", card, offs, count);
  ------------------
  |  |   71|  2.08k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  704|  2.08k|	if (offs > 0x7fff) {
  ------------------
  |  Branch (704:6): [True: 2, False: 2.08k]
  ------------------
  705|      2|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", offs);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  706|      2|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      2|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  707|      2|	}
  708|       |
  709|  2.08k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (offs >> 8) & 0x7F, offs & 0xFF);
  ------------------
  |  |  292|  2.08k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  710|  2.08k|	apdu.le = count < 0x100 ? count : 0x100;
  ------------------
  |  Branch (710:12): [True: 271, False: 1.81k]
  ------------------
  711|  2.08k|	apdu.resplen = count;
  712|  2.08k|	apdu.resp = buf;
  713|       |
  714|  2.08k|	rv = sc_transmit_apdu(card, &apdu);
  715|  2.08k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  2.08k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.08k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.08k|	int _ret = (r); \
  |  |  |  |  168|  2.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 2.07k]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|  2.07k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  717|  2.07k|	LOG_TEST_RET(ctx, rv, "iasecc_read_binary() failed");
  ------------------
  |  |  174|  2.07k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.07k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.07k|	int _ret = (r); \
  |  |  |  |  168|  2.07k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 504, False: 1.56k]
  |  |  |  |  ------------------
  |  |  |  |  169|    504|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    504|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    504|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    504|		return _ret; \
  |  |  |  |  172|    504|	} \
  |  |  |  |  173|  2.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.56k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  718|  1.56k|	sc_log(ctx, "iasecc_read_binary() apdu.resplen %zu", apdu.resplen);
  ------------------
  |  |   71|  1.56k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  719|       |
  720|  1.56k|	if (apdu.resplen == IASECC_READ_BINARY_LENGTH_MAX && apdu.resplen < count)   {
  ------------------
  |  |   76|  3.13k|#define IASECC_READ_BINARY_LENGTH_MAX	0xE7
  ------------------
  |  Branch (720:6): [True: 31, False: 1.53k]
  |  Branch (720:55): [True: 30, False: 1]
  ------------------
  721|     30|		rv = iasecc_read_binary(card, (int)(offs + apdu.resplen), buf + apdu.resplen, count - apdu.resplen, flags);
  722|     30|		if (rv != SC_ERROR_WRONG_LENGTH)   {
  ------------------
  |  |   56|     30|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (722:7): [True: 29, False: 1]
  ------------------
  723|     29|			LOG_TEST_RET(ctx, rv, "iasecc_read_binary() read tail 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: 15, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|     14|			apdu.resplen += rv;
  725|     14|		}
  726|     30|	}
  727|       |
  728|  1.55k|	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: 239, False: 1.31k]
  |  |  |  |  ------------------
  |  |  |  |  156|    239|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 239]
  |  |  |  |  ------------------
  |  |  |  |  157|    239|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.31k|	} else { \
  |  |  |  |  159|  1.31k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.31k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.31k|	} \
  |  |  |  |  162|  1.55k|	return _ret; \
  |  |  |  |  163|  1.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  729|  1.55k|}
card-iasecc.c:iasecc_get_challenge:
 1367|    352|{
 1368|       |	/* As IAS/ECC cannot handle other data length than 0x08 */
 1369|    352|	u8 rbuf[8];
 1370|    352|	size_t out_len;
 1371|    352|	int r;
 1372|       |
 1373|    352|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    352|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    352|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    352|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    352|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 352]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1374|       |
 1375|    352|	r = iso_ops->get_challenge(card, rbuf, sizeof rbuf);
 1376|    352|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE cmd failed");
  ------------------
  |  |  174|    352|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    352|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    352|	int _ret = (r); \
  |  |  |  |  168|    352|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 228, False: 124]
  |  |  |  |  ------------------
  |  |  |  |  169|    228|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    228|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    228|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    228|		return _ret; \
  |  |  |  |  172|    228|	} \
  |  |  |  |  173|    352|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 124]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1377|       |
 1378|    124|	if (len < (size_t) r) {
  ------------------
  |  Branch (1378:6): [True: 2, False: 122]
  ------------------
 1379|      2|		out_len = len;
 1380|    122|	} else {
 1381|    122|		out_len = (size_t) r;
 1382|    122|	}
 1383|    124|	memcpy(rnd, rbuf, out_len);
 1384|       |
 1385|    124|	LOG_FUNC_RETURN(card->ctx, (int) out_len);
  ------------------
  |  |  164|    124|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    124|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    124|	int _ret = r; \
  |  |  |  |  155|    124|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 119]
  |  |  |  |  ------------------
  |  |  |  |  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|    119|	} else { \
  |  |  |  |  159|    119|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    119|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    119|	} \
  |  |  |  |  162|    124|	return _ret; \
  |  |  |  |  163|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1386|    124|}
card-iasecc.c:iasecc_sdo_get_data:
 2848|    246|{
 2849|    246|	struct sc_context *ctx = card->ctx;
 2850|    246|	int rv, sdo_tag;
 2851|       |
 2852|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2853|       |
 2854|    246|	sdo_tag = iasecc_sdo_tag_from_class(sdo->sdo_class);
 2855|       |
 2856|    246|	rv = iasecc_sdo_get_tagged_data(card, sdo_tag, sdo);
 2857|       |	/* When there is no public data 'GET DATA' returns error */
 2858|    246|	if (rv != SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    246|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (2858:6): [True: 238, False: 8]
  ------------------
 2859|    246|		LOG_TEST_RET(ctx, rv, "cannot parse ECC SDO data");
  ------------------
  |  |  174|    238|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    238|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    238|	int _ret = (r); \
  |  |  |  |  168|    238|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 234, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|    234|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    234|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    234|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    234|		return _ret; \
  |  |  |  |  172|    234|	} \
  |  |  |  |  173|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2860|       |
 2861|     12|	rv = iasecc_sdo_get_tagged_data(card, IASECC_DOCP_TAG, sdo);
  ------------------
  |  |   31|     12|#define IASECC_DOCP_TAG				0xA0
  ------------------
 2862|     12|	LOG_TEST_RET(ctx, rv, "cannot parse ECC DOCP data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    246|{
 2750|    246|	switch (sdo_class & ~IASECC_OBJECT_REF_LOCAL)   {
  ------------------
  |  |   59|    246|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2750:10): [True: 246, False: 0]
  ------------------
 2751|    246|	case IASECC_SDO_CLASS_CHV:
  ------------------
  |  |   98|    246|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (2751:2): [True: 246, False: 0]
  ------------------
 2752|    246|		return IASECC_SDO_CHV_TAG;
  ------------------
  |  |   63|    246|#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: 246]
  ------------------
 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: 246]
  ------------------
 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: 246]
  ------------------
 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: 246]
  ------------------
 2760|      0|		return IASECC_SDO_KEYSET_TAG;
  ------------------
  |  |   83|      0|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
 2761|    246|	}
 2762|       |
 2763|      0|	return -1;
 2764|    246|}
card-iasecc.c:iasecc_sdo_get_tagged_data:
 2769|    258|{
 2770|    258|	struct sc_context *ctx = card->ctx;
 2771|    258|	struct sc_apdu apdu;
 2772|    258|	unsigned char sbuf[0x100];
 2773|    258|	size_t offs = sizeof(sbuf) - 1;
 2774|    258|	unsigned char rbuf[0x400];
 2775|    258|	int rv;
 2776|       |
 2777|    258|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    258|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    258|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    258|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    258|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 258]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2778|       |
 2779|    258|	sc_log(ctx, "sdo_tag=0x%x sdo_ref=0x%x sdo_class=0x%x", sdo_tag,
  ------------------
  |  |   71|    258|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2780|    258|			sdo->sdo_ref, sdo->sdo_class);
 2781|       |
 2782|       |	/* XXX: for the CPx, the SDO are available from some specific path */
 2783|    258|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (2783:6): [True: 28, False: 230]
  ------------------
 2784|     28|		struct sc_path path;
 2785|     28|		char *path_str = NULL;
 2786|     28|		switch(sdo_tag) {
 2787|      0|			case IASECC_SDO_PRVKEY_TAG:
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (2787:4): [True: 0, False: 28]
  ------------------
 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|     21|			case IASECC_SDO_CHV_TAG:
  ------------------
  |  |   63|     21|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (2791:4): [True: 21, False: 7]
  ------------------
 2792|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 81 01 03 7F 41 80 */
 2793|     21|			path_str = "3F00";
 2794|     21|			break;
 2795|      7|			default:
  ------------------
  |  Branch (2795:4): [True: 7, False: 21]
  ------------------
 2796|      7|			path_str = NULL;
 2797|      7|			break;
 2798|     28|		}
 2799|     28|		if (path_str) {
  ------------------
  |  Branch (2799:7): [True: 21, False: 7]
  ------------------
 2800|     21|			sc_log(ctx, "Warning: Enforce the path=%s", path_str);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2801|     21|			sc_format_path(path_str, &path);
 2802|     21|			rv = iasecc_select_file(card, &path, NULL);
 2803|     21|			LOG_TEST_RET(ctx, rv, "path error");
  ------------------
  |  |  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: 10, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2804|     21|		}
 2805|     28|	}
 2806|       |
 2807|    248|	sbuf[offs--] = 0x80;
 2808|    248|	sbuf[offs--] = sdo_tag & 0xFF;
 2809|    248|	if ((sdo_tag >> 8) & 0xFF)
  ------------------
  |  Branch (2809:6): [True: 236, False: 12]
  ------------------
 2810|    236|		sbuf[offs--] = (sdo_tag >> 8) & 0xFF;
 2811|    248|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2812|    248|	offs--;
 2813|       |
 2814|    248|	sbuf[offs--] = sdo->sdo_ref & 0x9F;
 2815|    248|	sbuf[offs--] = sdo->sdo_class | IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    248|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2816|    248|	sbuf[offs--] = IASECC_SDO_TAG_HEADER;
  ------------------
  |  |   27|    248|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
 2817|       |
 2818|    248|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2819|    248|	offs--;
 2820|    248|	sbuf[offs--] = IASECC_SDO_TEMPLATE_TAG;
  ------------------
  |  |   29|    248|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 2821|       |
 2822|    248|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2823|    248|	offs--;
 2824|    248|	sbuf[offs] = 0x4D;
 2825|       |
 2826|    248|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    248|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 2827|    248|	apdu.data = sbuf + offs;
 2828|    248|	apdu.datalen = sizeof(sbuf) - offs;
 2829|    248|	apdu.lc = sizeof(sbuf) - offs;
 2830|    248|	apdu.resp = rbuf;
 2831|    248|	apdu.resplen = sizeof(rbuf);
 2832|    248|	apdu.le = 0x100;
 2833|       |
 2834|    248|	rv = sc_transmit_apdu(card, &apdu);
 2835|    248|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    248|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    248|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    248|	int _ret = (r); \
  |  |  |  |  168|    248|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 236]
  |  |  |  |  ------------------
  |  |  |  |  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|    248|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 236]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2836|    236|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2837|    236|	LOG_TEST_RET(ctx, rv, "SDO get data error");
  ------------------
  |  |  174|    236|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    236|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    236|	int _ret = (r); \
  |  |  |  |  168|    236|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 35, False: 201]
  |  |  |  |  ------------------
  |  |  |  |  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|    236|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 201]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2838|       |
 2839|    201|	rv = iasecc_sdo_parse(card, apdu.resp, apdu.resplen, sdo);
 2840|    201|	LOG_TEST_RET(ctx, rv, "cannot parse SDO data");
  ------------------
  |  |  174|    201|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    201|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    201|	int _ret = (r); \
  |  |  |  |  168|    201|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 197, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|    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
  |  |  |  |  ------------------
  |  |  |  |  170|    197|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    197|		return _ret; \
  |  |  |  |  172|    197|	} \
  |  |  |  |  173|    201|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2841|       |
 2842|      4|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2843|      4|}
card-iasecc.c:iasecc_check_sw:
 1487|  13.6k|{
 1488|  13.6k|	if (sw1 == 0x62 && sw2 == 0x82)
  ------------------
  |  Branch (1488:6): [True: 1.89k, False: 11.8k]
  |  Branch (1488:21): [True: 1.83k, False: 58]
  ------------------
 1489|  1.83k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.83k|#define SC_SUCCESS				0
  ------------------
 1490|       |
 1491|  11.8k|	return iso_ops->check_sw(card, sw1, sw2);
 1492|  13.6k|}
card-iasecc.c:iasecc_card_ctl:
 2973|    528|{
 2974|    528|	struct sc_context *ctx = card->ctx;
 2975|    528|	struct iasecc_sdo *sdo = (struct iasecc_sdo *) ptr;
 2976|       |
 2977|    528|	switch (cmd) {
  ------------------
  |  Branch (2977:10): [True: 285, False: 243]
  ------------------
 2978|    285|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2978:2): [True: 285, False: 243]
  ------------------
 2979|    285|		return iasecc_get_serialnr(card, (struct sc_serial_number *)ptr);
 2980|      0|	case SC_CARDCTL_IASECC_SDO_CREATE:
  ------------------
  |  Branch (2980:2): [True: 0, False: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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: 528]
  ------------------
 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|    528|	}
 3008|    243|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    243|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3009|    528|}
card-iasecc.c:iasecc_pin_cmd:
 2428|    285|{
 2429|    285|	struct sc_context *ctx = card->ctx;
 2430|    285|	int rv;
 2431|       |
 2432|    285|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    285|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    285|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    285|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    285|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2433|    285|	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|    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__
  |  |  ------------------
  ------------------
 2434|    285|			data->cmd, data->pin_type, data->pin_reference,
 2435|    285|			data->pin1.data, data->pin1.len, data->pin2.data, data->pin2.len);
 2436|       |
 2437|    285|	switch (data->cmd)   {
 2438|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2438:2): [True: 0, False: 285]
  ------------------
 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: 285]
  ------------------
 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: 285]
  ------------------
 2448|      0|		rv = iasecc_pin_reset(card, data);
 2449|      0|		break;
 2450|    285|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    285|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2450:2): [True: 285, False: 0]
  ------------------
 2451|    285|		rv = iasecc_pin_get_info(card, data);
 2452|    285|		break;
 2453|      0|	default:
  ------------------
  |  Branch (2453:2): [True: 0, False: 285]
  ------------------
 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|    285|	}
 2457|       |
 2458|    285|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    285|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    285|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    285|	int _ret = r; \
  |  |  |  |  155|    285|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 285, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    285|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    285|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 285, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    285|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    285|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    285|	return _ret; \
  |  |  |  |  163|    285|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2459|    285|}
card-iasecc.c:iasecc_pin_get_status:
 1895|    285|{
 1896|    285|	struct sc_context *ctx = card->ctx;
 1897|    285|	struct sc_pin_cmd_data info;
 1898|    285|	int rv;
 1899|       |
 1900|    285|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    285|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    285|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    285|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    285|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1901|       |
 1902|    285|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    285|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1902:6): [True: 0, False: 285]
  ------------------
 1903|    285|		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|    285|	memset(&info, 0, sizeof(info));
 1906|    285|	info.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    285|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1907|    285|	info.pin_type = data->pin_type;
 1908|    285|	info.pin_reference = data->pin_reference;
 1909|       |
 1910|    285|	rv = iso_ops->pin_cmd(card, &info);
 1911|    285|	LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
  ------------------
  |  |  174|    285|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    285|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    285|	int _ret = (r); \
  |  |  |  |  168|    285|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 253]
  |  |  |  |  ------------------
  |  |  |  |  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|    285|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 253]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1912|       |
 1913|    253|	data->pin1.max_tries = info.pin1.max_tries;
 1914|    253|	data->pin1.tries_left = info.pin1.tries_left;
 1915|    253|	data->pin1.logged_in = info.pin1.logged_in;
 1916|       |
 1917|    253|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    253|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    253|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    253|	int _ret = r; \
  |  |  |  |  155|    253|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 253, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    253|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 253]
  |  |  |  |  ------------------
  |  |  |  |  157|    253|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    253|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    253|	return _ret; \
  |  |  |  |  163|    253|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1918|    253|}
card-iasecc.c:iasecc_pin_get_policy:
 2014|    253|{
 2015|    253|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 2016|    253|	struct sc_context *ctx = card->ctx;
 2017|    253|	struct sc_file *save_current_df = NULL, *save_current_ef = NULL;
 2018|    253|	struct iasecc_sdo sdo;
 2019|    253|	struct sc_path path;
 2020|    253|	int rv;
 2021|       |
 2022|    253|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    253|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    253|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    253|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    253|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 253]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2023|    253|	sc_log(ctx, "iasecc_pin_get_policy(card:%p)", card);
  ------------------
  |  |   71|    253|#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|    253|	if (data->pin_type != SC_AC_CHV)   {
  ------------------
  |  |  151|    253|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2025:6): [True: 0, False: 253]
  ------------------
 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|    253|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (2030:6): [True: 253, False: 0]
  |  Branch (2030:26): [True: 10, False: 243]
  ------------------
 2031|     10|		sc_file_dup(&save_current_df, prv->cache.current_df);
 2032|     10|		if (save_current_df == NULL) {
  ------------------
  |  Branch (2032:7): [True: 0, False: 10]
  ------------------
 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|     10|	}
 2038|       |
 2039|    253|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (2039:6): [True: 253, False: 0]
  |  Branch (2039:26): [True: 35, False: 218]
  ------------------
 2040|     35|		sc_file_dup(&save_current_ef, prv->cache.current_ef);
 2041|     35|		if (save_current_ef == NULL) {
  ------------------
  |  Branch (2041:7): [True: 0, False: 35]
  ------------------
 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|     35|	}
 2047|       |
 2048|    253|	if (!(data->pin_reference & IASECC_OBJECT_REF_LOCAL) && prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  |   59|    253|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2048:6): [True: 253, False: 0]
  |  Branch (2048:58): [True: 253, False: 0]
  |  Branch (2048:78): [True: 10, False: 243]
  ------------------
 2049|     10|		sc_format_path("3F00", &path);
 2050|     10|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     10|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 2051|     10|		rv = iasecc_select_file(card, &path, NULL);
 2052|     10|		LOG_TEST_GOTO_ERR(ctx, rv, "Unable to select MF");
  ------------------
  |  |  184|     10|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     10|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     10|	int _ret = (r); \
  |  |  |  |  178|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2053|     10|	}
 2054|       |
 2055|    246|	memset(&sdo, 0, sizeof(sdo));
 2056|    246|	sdo.sdo_class = IASECC_SDO_CLASS_CHV;
  ------------------
  |  |   98|    246|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
 2057|       |
 2058|    246|	sdo.sdo_ref = data->pin_reference & ~IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    246|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2059|       |
 2060|    246|	sc_log(ctx, "iasecc_pin_get_policy() reference %i", sdo.sdo_ref);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2061|       |
 2062|    246|	rv = iasecc_sdo_get_data(card, &sdo);
 2063|    246|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot get SDO PIN data");
  ------------------
  |  |  184|    246|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    246|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    246|	int _ret = (r); \
  |  |  |  |  178|    246|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 246, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    246|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    246|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    246|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    246|		goto err; \
  |  |  |  |  182|    246|	} \
  |  |  |  |  183|    246|} 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|    253|err:
 2106|    253|	sc_file_free(save_current_df);
 2107|    253|	sc_file_free(save_current_ef);
 2108|       |
 2109|    253|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    253|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    253|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    253|	int _ret = r; \
  |  |  |  |  155|    253|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 253, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    253|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    253|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 253, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    253|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    253|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    253|	return _ret; \
  |  |  |  |  163|    253|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2110|    253|}
card-iasecc.c:iasecc_pin_get_info:
 2115|    285|{
 2116|    285|	struct sc_context *ctx = card->ctx;
 2117|    285|	struct iasecc_pin_policy policy;
 2118|    285|	int rv;
 2119|       |
 2120|    285|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    285|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    285|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    285|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    285|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 285]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2121|    285|	sc_log(ctx, "iasecc_pin_get_info(card:%p)", card);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 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|    285|	rv = iasecc_pin_get_status(card, data);
 2130|    285|	LOG_TEST_RET(ctx, rv, "Failed to get PIN status");
  ------------------
  |  |  174|    285|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    285|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    285|	int _ret = (r); \
  |  |  |  |  168|    285|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 253]
  |  |  |  |  ------------------
  |  |  |  |  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|    285|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 253]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2131|       |
 2132|    253|	rv = iasecc_pin_get_policy(card, data, &policy);
 2133|    253|	LOG_TEST_RET(ctx, rv, "Failed to get PIN policy");
  ------------------
  |  |  174|    253|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    253|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    253|	int _ret = (r); \
  |  |  |  |  168|    253|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 253, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    253|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    253|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    253|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    253|		return _ret; \
  |  |  |  |  172|    253|	} \
  |  |  |  |  173|    253|} 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|    483|{
  226|    483|	free(priv->cache_buf);
  227|    483|	list_destroy(&priv->pki_list);
  228|    483|	list_destroy(&priv->containers);
  229|    483|	list_destroy(&priv->keyrefmap);
  230|    483|	free(priv);
  231|    483|	return;
  232|    483|}
idprime_new_private_data:
  235|    483|{
  236|    483|	idprime_private_data_t *priv;
  237|       |
  238|    483|	priv = calloc(1, sizeof(idprime_private_data_t));
  239|    483|	if (priv == NULL)
  ------------------
  |  Branch (239:6): [True: 0, False: 483]
  ------------------
  240|      0|		return NULL;
  241|       |
  242|       |	/* Initialize PKI Applets list */
  243|    483|	if (list_init(&priv->pki_list) != 0 ||
  ------------------
  |  Branch (243:6): [True: 0, False: 483]
  ------------------
  244|    483|	    list_attributes_copy(&priv->pki_list, idprime_list_meter, 1) != 0) {
  ------------------
  |  Branch (244:6): [True: 0, False: 483]
  ------------------
  245|      0|		idprime_free_private_data(priv);
  246|      0|		return NULL;
  247|      0|	}
  248|       |
  249|       |	/* Initialize container list */
  250|    483|	if (list_init(&priv->containers) != 0 ||
  ------------------
  |  Branch (250:6): [True: 0, False: 483]
  ------------------
  251|    483|	    list_attributes_copy(&priv->containers, idprime_container_list_meter, 1) != 0 ||
  ------------------
  |  Branch (251:6): [True: 0, False: 483]
  ------------------
  252|    483|	    list_attributes_seeker(&priv->containers, idprime_container_list_seeker) != 0) {
  ------------------
  |  Branch (252:6): [True: 0, False: 483]
  ------------------
  253|      0|		idprime_free_private_data(priv);
  254|      0|		return NULL;
  255|      0|	}
  256|       |
  257|       |	/* Initialize keyref list */
  258|    483|	if (list_init(&priv->keyrefmap) != 0 ||
  ------------------
  |  Branch (258:6): [True: 0, False: 483]
  ------------------
  259|    483|	    list_attributes_copy(&priv->keyrefmap, idprime_keyref_list_meter, 1) != 0 ||
  ------------------
  |  Branch (259:6): [True: 0, False: 483]
  ------------------
  260|    483|	    list_attributes_seeker(&priv->keyrefmap, idprime_keyref_list_seeker) != 0) {
  ------------------
  |  Branch (260:6): [True: 0, False: 483]
  ------------------
  261|      0|		idprime_free_private_data(priv);
  262|      0|		return NULL;
  263|      0|	}
  264|    483|	return priv;
  265|    483|}
idprime_add_object_to_list:
  268|    715|{
  269|    715|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (269:6): [True: 0, False: 715]
  ------------------
  270|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  271|    715|	return SC_SUCCESS;
  ------------------
  |  |   28|    715|#define SC_SUCCESS				0
  ------------------
  272|    715|}
sc_get_idprime_driver:
 1281|  15.7k|{
 1282|  15.7k|	return sc_get_driver();
 1283|  15.7k|}
card-idprime.c:idprime_list_meter:
  176|    715|static size_t idprime_list_meter(const void *el) {
  177|    715|	return sizeof(idprime_object_t);
  178|    715|}
card-idprime.c:idprime_container_list_meter:
  180|    120|static size_t idprime_container_list_meter(const void *el) {
  181|    120|	return sizeof(idprime_container_t);
  182|    120|}
card-idprime.c:idprime_keyref_list_meter:
  184|  15.0k|static size_t idprime_keyref_list_meter(const void *el) {
  185|  15.0k|	return sizeof(idprime_keyref_t);
  186|  15.0k|}
card-idprime.c:sc_get_driver:
 1258|  15.7k|{
 1259|  15.7k|	if (iso_ops == NULL) {
  ------------------
  |  Branch (1259:6): [True: 1, False: 15.7k]
  ------------------
 1260|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1261|      1|	}
 1262|       |
 1263|  15.7k|	idprime_ops = *iso_ops;
 1264|  15.7k|	idprime_ops.match_card = idprime_match_card;
 1265|  15.7k|	idprime_ops.init = idprime_init;
 1266|  15.7k|	idprime_ops.finish = idprime_finish;
 1267|       |
 1268|  15.7k|	idprime_ops.read_binary = idprime_read_binary;
 1269|  15.7k|	idprime_ops.select_file = idprime_select_file;
 1270|  15.7k|	idprime_ops.card_ctl = idprime_card_ctl;
 1271|  15.7k|	idprime_ops.set_security_env = idprime_set_security_env;
 1272|  15.7k|	idprime_ops.compute_signature = idprime_compute_signature;
 1273|  15.7k|	idprime_ops.decipher = idprime_decipher;
 1274|       |
 1275|  15.7k|	idprime_ops.get_challenge = idprime_get_challenge;
 1276|       |
 1277|  15.7k|	return &idprime_drv;
 1278|  15.7k|}
card-idprime.c:idprime_match_card:
  754|  8.57k|{
  755|  8.57k|	int i, r;
  756|       |
  757|  8.57k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  8.57k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  8.57k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  8.57k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8.57k]
  |  |  ------------------
  ------------------
  758|  8.57k|	i = _sc_match_atr(card, idprime_atrs, &card->type);
  759|  8.57k|	if (i < 0)
  ------------------
  |  Branch (759:6): [True: 8.05k, False: 514]
  ------------------
  760|  8.05k|		return 0;
  761|       |
  762|    514|	r = idprime_select_file_by_path(card, "0101");
  763|    514|	LOG_FUNC_RETURN(card->ctx, r > 0);
  ------------------
  |  |  164|    514|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    514|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    514|	int _ret = r; \
  |  |  |  |  155|    514|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31, False: 483]
  |  |  |  |  ------------------
  |  |  |  |  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|    483|	} else { \
  |  |  |  |  159|    483|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    483|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    483|	} \
  |  |  |  |  162|    514|	return _ret; \
  |  |  |  |  163|    514|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  764|    514|}
card-idprime.c:idprime_select_file_by_path:
  283|  1.41k|{
  284|  1.41k|	int r;
  285|  1.41k|	sc_file_t *file = NULL;
  286|  1.41k|	sc_path_t index_path;
  287|       |
  288|       |	/* First, we need to make sure the IDPrime AID is selected */
  289|  1.41k|	r = idprime_select_idprime(card);
  290|  1.41k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.41k|#define SC_SUCCESS				0
  ------------------
  |  Branch (290:6): [True: 133, False: 1.28k]
  ------------------
  291|    133|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    133|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    133|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    133|	int _ret = r; \
  |  |  |  |  155|    133|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 133, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    133|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    133|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 133, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    133|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    133|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    133|	return _ret; \
  |  |  |  |  163|    133|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|    133|	}
  293|       |
  294|       |	/* Returns FCI with expected length of data */
  295|  1.28k|	sc_format_path(str_path, &index_path);
  296|  1.28k|	r = iso_ops->select_file(card, &index_path, &file);
  297|       |
  298|  1.28k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.28k|#define SC_SUCCESS				0
  ------------------
  |  Branch (298:6): [True: 13, False: 1.27k]
  ------------------
  299|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  300|     13|	}
  301|       |	/* Ignore too large files */
  302|  1.27k|	if (file->size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  1.27k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (302:6): [True: 0, False: 1.27k]
  ------------------
  303|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  304|  1.27k|	} else {
  305|  1.27k|		r = (int)file->size;
  306|  1.27k|	}
  307|  1.27k|	sc_file_free(file);
  308|  1.27k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.27k|	int _ret = r; \
  |  |  |  |  155|  1.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 1.26k]
  |  |  |  |  ------------------
  |  |  |  |  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.26k|	} else { \
  |  |  |  |  159|  1.26k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.26k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.26k|	} \
  |  |  |  |  162|  1.27k|	return _ret; \
  |  |  |  |  163|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|  1.27k|}
card-idprime.c:idprime_select_idprime:
  277|  1.41k|{
  278|       |	return iso_ops->select_file(card, &idprime_path, NULL);
  279|  1.41k|}
card-idprime.c:idprime_init:
  565|    483|{
  566|    483|	int r;
  567|    483|	unsigned long flags, ext_flags;
  568|    483|	idprime_private_data_t *priv = NULL;
  569|    483|	struct sc_apdu apdu;
  570|    483|	u8 rbuf[CPLC_LENGTH];
  571|    483|	size_t rbuflen = sizeof(rbuf);
  572|       |
  573|    483|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    483|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    483|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    483|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 483]
  |  |  ------------------
  ------------------
  574|       |
  575|       |	/* We need to differentiate the OS version since they behave slightly differently */
  576|    483|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  301|    483|#define SC_APDU_CASE_2			0x22
  ------------------
  577|    483|	apdu.resp = rbuf;
  578|    483|	apdu.resplen = rbuflen;
  579|    483|	apdu.le = rbuflen;
  580|    483|	r = sc_transmit_apdu(card, &apdu);
  581|    483|	if (r == SC_SUCCESS && apdu.resplen == CPLC_LENGTH) {
  ------------------
  |  |   28|    966|#define SC_SUCCESS				0
  ------------------
              	if (r == SC_SUCCESS && apdu.resplen == CPLC_LENGTH) {
  ------------------
  |  |  563|    476|#define CPLC_LENGTH 45
  ------------------
  |  Branch (581:6): [True: 476, False: 7]
  |  Branch (581:25): [True: 7, False: 469]
  ------------------
  582|       |		/* We are interested in the OS release level here */
  583|      7|		switch (rbuf[11]) {
  584|      1|		case 0x01:
  ------------------
  |  Branch (584:3): [True: 1, False: 6]
  ------------------
  585|      1|			sc_log(card->ctx, "Detected IDPrime applet version 1");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  586|      1|			break;
  587|      2|		case 0x02:
  ------------------
  |  Branch (587:3): [True: 2, False: 5]
  ------------------
  588|      2|			sc_log(card->ctx, "Detected IDPrime applet version 2");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  589|      2|			break;
  590|      1|		case 0x03:
  ------------------
  |  Branch (590:3): [True: 1, False: 6]
  ------------------
  591|      1|			sc_log(card->ctx, "Detected IDPrime applet version 3");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  592|      1|			break;
  593|      1|		case 0x04:
  ------------------
  |  Branch (593:3): [True: 1, False: 6]
  ------------------
  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|      2|		default:
  ------------------
  |  Branch (596:3): [True: 2, False: 5]
  ------------------
  597|      2|			sc_log(card->ctx, "Unknown OS version received: %d", rbuf[11]);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  598|      2|			break;
  599|      7|		}
  600|    476|	} else {
  601|    476|		sc_log(card->ctx, "Failed to get CPLC data or invalid length returned, err=%d, len=%zu",
  ------------------
  |  |   71|    476|#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|    476|				r, apdu.resplen);
  603|    476|	}
  604|       |
  605|       |	/* Proprietary data -- Applet version */
  606|    483|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, 0xDF, 0x30);
  ------------------
  |  |  301|    483|#define SC_APDU_CASE_2			0x22
  ------------------
  607|    483|	apdu.resp = rbuf;
  608|    483|	apdu.resplen = rbuflen;
  609|    483|	apdu.le = rbuflen;
  610|    483|	r = sc_transmit_apdu(card, &apdu);
  611|    483|	if (r == SC_SUCCESS && apdu.resplen >= 10) {
  ------------------
  |  |   28|    966|#define SC_SUCCESS				0
  ------------------
  |  Branch (611:6): [True: 478, False: 5]
  |  Branch (611:25): [True: 8, False: 470]
  ------------------
  612|       |		/* Ber-TLV encoded */
  613|      8|		if (rbuf[0] == 0xDF && rbuf[1] == 0x30 && rbuf[2] == apdu.resplen - 3) {
  ------------------
  |  Branch (613:7): [True: 5, False: 3]
  |  Branch (613:26): [True: 4, False: 1]
  |  Branch (613:45): [True: 1, False: 3]
  ------------------
  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|      8|	}
  617|       |
  618|    483|	priv = idprime_new_private_data();
  619|    483|	if (!priv) {
  ------------------
  |  Branch (619:6): [True: 0, False: 483]
  ------------------
  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|    483|	r = idprime_select_file_by_path(card, "0204");;
  625|    483|	if (r <= 0) {
  ------------------
  |  Branch (625:6): [True: 51, False: 432]
  ------------------
  626|     51|		idprime_free_private_data(priv);
  627|     51|		if (r == 0)
  ------------------
  |  Branch (627:7): [True: 1, False: 50]
  ------------------
  628|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  629|     51|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     51|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     51|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|     51|	}
  631|       |
  632|    432|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Container file found");
  ------------------
  |  |   70|    432|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  633|       |
  634|    432|	r = idprime_process_containermap(card, priv, r);
  635|    432|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    432|#define SC_SUCCESS				0
  ------------------
  |  Branch (635:6): [True: 54, False: 378]
  ------------------
  636|     54|		idprime_free_private_data(priv);
  637|     54|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     54|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     54|	int _ret = r; \
  |  |  |  |  155|     54|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     54|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|     54|	}
  639|       |
  640|    378|	if (card->type == SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (640:6): [True: 74, False: 304]
  ------------------
  641|     74|		if ((r = idprime_select_file_by_path(card, "0005")) <= 0) {
  ------------------
  |  Branch (641:7): [True: 10, False: 64]
  ------------------
  642|     10|			idprime_free_private_data(priv);
  643|     10|			if (r == 0)
  ------------------
  |  Branch (643:8): [True: 1, False: 9]
  ------------------
  644|      1|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  645|     10|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  646|     10|		}
  647|       |
  648|     64|		if ((r = idprime_process_keyrefmap(card, priv, r)) != SC_SUCCESS) {
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  |  Branch (648:7): [True: 23, False: 41]
  ------------------
  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|     64|	}
  653|       |
  654|       |	/* Select and process the index file */
  655|    345|	r = idprime_select_file_by_path(card, "0101");
  656|    345|	if (r <= 0) {
  ------------------
  |  Branch (656:6): [True: 58, False: 287]
  ------------------
  657|     58|		idprime_free_private_data(priv);
  658|     58|		if (r == 0)
  ------------------
  |  Branch (658:7): [True: 1, False: 57]
  ------------------
  659|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  660|     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|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     58|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     58|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     58|	return _ret; \
  |  |  |  |  163|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  661|     58|	}
  662|       |
  663|    287|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Index file found");
  ------------------
  |  |   70|    287|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  664|       |
  665|    287|	r = idprime_process_index(card, priv, r);
  666|    287|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    287|#define SC_SUCCESS				0
  ------------------
  |  Branch (666:6): [True: 27, False: 260]
  ------------------
  667|     27|		idprime_free_private_data(priv);
  668|     27|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     27|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     27|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     27|	int _ret = r; \
  |  |  |  |  155|     27|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     27|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     27|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     27|	return _ret; \
  |  |  |  |  163|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  669|     27|	}
  670|       |
  671|    260|	card->drv_data = priv;
  672|       |
  673|    260|	switch (card->type) {
  674|      1|	case SC_CARD_TYPE_IDPRIME_3810:
  ------------------
  |  Branch (674:2): [True: 1, False: 259]
  ------------------
  675|      1|		card->name = "Gemalto IDPrime 3810";
  676|      1|		break;
  677|      1|	case SC_CARD_TYPE_IDPRIME_830:
  ------------------
  |  Branch (677:2): [True: 1, False: 259]
  ------------------
  678|      1|		card->name = "Gemalto IDPrime MD 830";
  679|      1|		break;
  680|     31|	case SC_CARD_TYPE_IDPRIME_930:
  ------------------
  |  Branch (680:2): [True: 31, False: 229]
  ------------------
  681|     31|	case SC_CARD_TYPE_IDPRIME_930_PLUS:
  ------------------
  |  Branch (681:2): [True: 0, False: 260]
  ------------------
  682|     31|		card->name = "Gemalto IDPrime 930/3930";
  683|     31|		break;
  684|      5|	case SC_CARD_TYPE_IDPRIME_940:
  ------------------
  |  Branch (684:2): [True: 5, False: 255]
  ------------------
  685|      5|		card->name = "Gemalto IDPrime 940";
  686|      5|		break;
  687|      5|	case SC_CARD_TYPE_IDPRIME_840:
  ------------------
  |  Branch (687:2): [True: 5, False: 255]
  ------------------
  688|      5|		card->name = "Gemalto IDPrime MD 840";
  689|      5|		break;
  690|    217|	case SC_CARD_TYPE_IDPRIME_GENERIC:
  ------------------
  |  Branch (690:2): [True: 217, False: 43]
  ------------------
  691|    217|	default:
  ------------------
  |  Branch (691:2): [True: 0, False: 260]
  ------------------
  692|    217|		card->name = "Gemalto IDPrime (generic)";
  693|    217|		break;
  694|    260|	}
  695|    260|	card->cla = 0x00;
  696|       |
  697|       |	/* Set up algorithm info for RSA. */
  698|    260|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    260|#define SC_ALGORITHM_RSA_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|    260|#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|    260|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  699|    260|		| SC_ALGORITHM_RSA_PAD_PSS
  ------------------
  |  |  107|    260|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  700|    260|		| SC_ALGORITHM_RSA_PAD_OAEP
  ------------------
  |  |  108|    260|#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|    260|		| (SC_ALGORITHM_RSA_HASH_SHA256 | SC_ALGORITHM_RSA_HASH_SHA384 | SC_ALGORITHM_RSA_HASH_SHA512)
  ------------------
  |  |  138|    260|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
              		| (SC_ALGORITHM_RSA_HASH_SHA256 | SC_ALGORITHM_RSA_HASH_SHA384 | SC_ALGORITHM_RSA_HASH_SHA512)
  ------------------
  |  |  139|    260|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
              		| (SC_ALGORITHM_RSA_HASH_SHA256 | SC_ALGORITHM_RSA_HASH_SHA384 | SC_ALGORITHM_RSA_HASH_SHA512)
  ------------------
  |  |  140|    260|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  703|    260|		| (SC_ALGORITHM_MGF1_SHA256 | SC_ALGORITHM_MGF1_SHA384 | SC_ALGORITHM_MGF1_SHA512)
  ------------------
  |  |  146|    260|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              		| (SC_ALGORITHM_MGF1_SHA256 | SC_ALGORITHM_MGF1_SHA384 | SC_ALGORITHM_MGF1_SHA512)
  ------------------
  |  |  147|    260|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              		| (SC_ALGORITHM_MGF1_SHA256 | SC_ALGORITHM_MGF1_SHA384 | SC_ALGORITHM_MGF1_SHA512)
  ------------------
  |  |  148|    260|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
  704|    260|		;
  705|       |
  706|    260|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  707|    260|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  708|    260|	switch (card->type) {
  709|      0|	case SC_CARD_TYPE_IDPRIME_930_PLUS:
  ------------------
  |  Branch (709:2): [True: 0, False: 260]
  ------------------
  710|      5|	case SC_CARD_TYPE_IDPRIME_940:
  ------------------
  |  Branch (710:2): [True: 5, False: 255]
  ------------------
  711|      5|		_sc_card_add_rsa_alg(card, 3072, flags, 0);
  712|       |		/* fallthrough */
  713|     36|	case SC_CARD_TYPE_IDPRIME_930:
  ------------------
  |  Branch (713:2): [True: 31, False: 229]
  ------------------
  714|     36|		_sc_card_add_rsa_alg(card, 4096, flags, 0);
  715|       |		/* fallthrough */
  716|     41|	case SC_CARD_TYPE_IDPRIME_840:
  ------------------
  |  Branch (716:2): [True: 5, False: 255]
  ------------------
  717|       |		/* Set up algorithm info for EC */
  718|     41|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|     41|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|     41|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     41|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  719|     41|		if (card->type == SC_CARD_TYPE_IDPRIME_930_PLUS || card->type == SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (719:7): [True: 0, False: 41]
  |  Branch (719:54): [True: 5, False: 36]
  ------------------
  720|      5|			flags |= SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|      5|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  721|      5|		}
  722|     41|		ext_flags = SC_ALGORITHM_EXT_EC_F_P
  ------------------
  |  |  198|     41|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
  723|     41|			| SC_ALGORITHM_EXT_EC_ECPARAMETERS
  ------------------
  |  |  200|     41|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
  724|     41|			| SC_ALGORITHM_EXT_EC_NAMEDCURVE
  ------------------
  |  |  201|     41|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  725|     41|			| SC_ALGORITHM_EXT_EC_UNCOMPRESES
  ------------------
  |  |  202|     41|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  726|     41|			;
  727|     41|		_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
  728|     41|		_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
  729|     41|		_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
  730|     41|		break;
  731|    219|	default:
  ------------------
  |  Branch (731:2): [True: 219, False: 41]
  ------------------
  732|    219|		break;
  733|    260|	}
  734|       |
  735|    260|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    260|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  736|       |
  737|    260|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    260|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  738|       |
  739|    260|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|    260|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    260|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    260|	int _ret = r; \
  |  |  |  |  155|    260|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 260, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    260|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 260]
  |  |  |  |  ------------------
  |  |  |  |  157|    260|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    260|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    260|	return _ret; \
  |  |  |  |  163|    260|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  740|    260|}
card-idprime.c:idprime_process_containermap:
  312|    432|{
  313|    432|	u8 *buf = NULL;
  314|    432|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|    432|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  315|    432|	int i;
  316|    432|	uint8_t max_entries, container_index;
  317|       |
  318|    432|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    432|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    432|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    432|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 432]
  |  |  ------------------
  ------------------
  319|       |
  320|    432|	buf = malloc(length);
  321|    432|	if (buf == NULL) {
  ------------------
  |  Branch (321:6): [True: 0, False: 432]
  ------------------
  322|      0|		goto done;
  323|      0|	}
  324|       |
  325|    432|	r = 0;
  326|  1.07k|	do {
  327|       |		/* Read at most CONTAINER_OBJ_LEN bytes */
  328|  1.07k|		int read_length = length - r > CONTAINER_OBJ_LEN ? CONTAINER_OBJ_LEN : length - r;
  ------------------
  |  |  142|  1.07k|#define CONTAINER_OBJ_LEN 86
  ------------------
              		int read_length = length - r > CONTAINER_OBJ_LEN ? CONTAINER_OBJ_LEN : length - r;
  ------------------
  |  |  142|    613|#define CONTAINER_OBJ_LEN 86
  ------------------
  |  Branch (328:21): [True: 613, False: 457]
  ------------------
  329|  1.07k|		if (length == r) {
  ------------------
  |  Branch (329:7): [True: 0, False: 1.07k]
  ------------------
  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.07k|		const int got = iso_ops->read_binary(card, r, buf + r, read_length, 0);
  334|  1.07k|		if (got < 1) {
  ------------------
  |  Branch (334:7): [True: 54, False: 1.01k]
  ------------------
  335|     54|			if (got < 0) {
  ------------------
  |  Branch (335:8): [True: 52, False: 2]
  ------------------
  336|     52|				r = got;
  337|     52|			} else {
  338|      2|				r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      2|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  339|      2|			}
  340|     54|			goto done;
  341|     54|		}
  342|       |
  343|  1.01k|		r += got;
  344|       |
  345|       |		/* Try to read chunks of container size and stop when last container looks empty */
  346|  1.01k|		container_index = r > CONTAINER_OBJ_LEN ? (r / CONTAINER_OBJ_LEN - 1) * CONTAINER_OBJ_LEN : 0;
  ------------------
  |  |  142|  1.01k|#define CONTAINER_OBJ_LEN 86
  ------------------
              		container_index = r > CONTAINER_OBJ_LEN ? (r / CONTAINER_OBJ_LEN - 1) * CONTAINER_OBJ_LEN : 0;
  ------------------
  |  |  142|    382|#define CONTAINER_OBJ_LEN 86
  ------------------
              		container_index = r > CONTAINER_OBJ_LEN ? (r / CONTAINER_OBJ_LEN - 1) * CONTAINER_OBJ_LEN : 0;
  ------------------
  |  |  142|    382|#define CONTAINER_OBJ_LEN 86
  ------------------
  |  Branch (346:21): [True: 382, False: 634]
  ------------------
  347|  1.01k|	} while(length - r > 0 && buf[container_index] != 0);
  ------------------
  |  Branch (347:10): [True: 651, False: 365]
  |  Branch (347:28): [True: 638, False: 13]
  ------------------
  348|    378|	max_entries = r / CONTAINER_OBJ_LEN;
  ------------------
  |  |  142|    378|#define CONTAINER_OBJ_LEN 86
  ------------------
  349|       |
  350|    498|	for (i = 0; i < max_entries; i++) {
  ------------------
  |  Branch (350:14): [True: 121, False: 377]
  ------------------
  351|    121|		u8 *start = &buf[i * CONTAINER_OBJ_LEN];
  ------------------
  |  |  142|    121|#define CONTAINER_OBJ_LEN 86
  ------------------
  352|    121|		idprime_container_t new_container = {0};
  353|    121|		if (start[0] == 0) /* Empty record */
  ------------------
  |  Branch (353:7): [True: 1, False: 120]
  ------------------
  354|      1|			break;
  355|       |
  356|    120|		new_container.index = i;
  357|       |		/* Reading UNICODE characters but skipping second byte */
  358|    120|		int j = 0;
  359|  2.01k|		for (j = 0; j < MAX_CONTAINER_NAME_LEN; j++) {
  ------------------
  |  |  141|  2.01k|#define MAX_CONTAINER_NAME_LEN 39
  ------------------
  |  Branch (359:15): [True: 1.97k, False: 35]
  ------------------
  360|  1.97k|			if (start[2 * j] == 0)
  ------------------
  |  Branch (360:8): [True: 85, False: 1.89k]
  ------------------
  361|     85|				break;
  362|  1.89k|			new_container.guid[j] = start[2 * j];
  363|  1.89k|		}
  364|       |
  365|    120|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found container with index=%d, guid=%s", new_container.index, new_container.guid);
  ------------------
  |  |   70|    120|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  366|       |
  367|    120|		if ((r = idprime_add_container_to_list(&priv->containers, &new_container)) != SC_SUCCESS) {
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  |  Branch (367:7): [True: 0, False: 120]
  ------------------
  368|      0|			goto done;
  369|      0|		}
  370|    120|	}
  371|       |
  372|    378|	r = SC_SUCCESS;
  ------------------
  |  |   28|    378|#define SC_SUCCESS				0
  ------------------
  373|    432|done:
  374|    432|	free(buf);
  375|    432|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|     54|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 54, False: 378]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    432|}
card-idprime.c:idprime_add_container_to_list:
  189|    120|{
  190|    120|	if (list_append(list, container) < 0)
  ------------------
  |  Branch (190:6): [True: 0, False: 120]
  ------------------
  191|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  192|    120|	return SC_SUCCESS;
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  193|    120|}
card-idprime.c:idprime_process_keyrefmap:
  379|     64|{
  380|     64|	u8 *buf = NULL;
  381|     64|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     64|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  382|     64|	int i, max_entries;
  383|       |
  384|     64|	buf = malloc(length);
  385|     64|	if (buf == NULL) {
  ------------------
  |  Branch (385:6): [True: 0, False: 64]
  ------------------
  386|      0|		goto done;
  387|      0|	}
  388|       |
  389|     64|	r = 0;
  390|    325|	do {
  391|    325|		if (length == r) {
  ------------------
  |  Branch (391:7): [True: 0, False: 325]
  ------------------
  392|      0|			r = SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|      0|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  393|      0|			goto done;
  394|      0|		}
  395|    325|		const int got = iso_ops->read_binary(card, r, buf + r, length - r, 0);
  396|    325|		if (got < 1) {
  ------------------
  |  Branch (396:7): [True: 23, False: 302]
  ------------------
  397|     23|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     23|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  398|     23|			goto done;
  399|     23|		}
  400|       |
  401|    302|		r += got;
  402|    302|	} while(length - r > 0);
  ------------------
  |  Branch (402:10): [True: 261, False: 41]
  ------------------
  403|     41|	max_entries = r / KEYREF_OBJ_LEN;
  ------------------
  |  |  151|     41|#define KEYREF_OBJ_LEN 8
  ------------------
  404|       |
  405|  17.9k|	for (i = 0; i < max_entries; i++) {
  ------------------
  |  Branch (405:14): [True: 17.9k, False: 41]
  ------------------
  406|  17.9k|		idprime_keyref_t new_keyref;
  407|  17.9k|		u8 *start = &buf[i * KEYREF_OBJ_LEN];
  ------------------
  |  |  151|  17.9k|#define KEYREF_OBJ_LEN 8
  ------------------
  408|  17.9k|		if (start[0] == 0) /* Empty key ref */
  ------------------
  |  Branch (408:7): [True: 2.88k, False: 15.0k]
  ------------------
  409|  2.88k|			continue;
  410|       |
  411|  15.0k|		new_keyref.index = start[2];
  412|  15.0k|		new_keyref.key_reference = start[1];
  413|  15.0k|		new_keyref.pin_index = start[7];
  414|  15.0k|		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|  15.0k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  415|       |
  416|  15.0k|		if ((r = idprime_add_keyref_to_list(&priv->keyrefmap, &new_keyref)) != SC_SUCCESS) {
  ------------------
  |  |   28|  15.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (416:7): [True: 0, False: 15.0k]
  ------------------
  417|      0|			goto done;
  418|      0|		}
  419|  15.0k|	}
  420|     41|	r = SC_SUCCESS;
  ------------------
  |  |   28|     41|#define SC_SUCCESS				0
  ------------------
  421|     64|done:
  422|     64|	free(buf);
  423|     64|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     64|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     64|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     64|	int _ret = r; \
  |  |  |  |  155|     64|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  157|     64|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     64|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  424|     64|}
card-idprime.c:idprime_add_keyref_to_list:
  207|  15.0k|{
  208|  15.0k|	if (list_append(list, keyref) < 0)
  ------------------
  |  Branch (208:6): [True: 0, False: 15.0k]
  ------------------
  209|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  210|  15.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.0k|#define SC_SUCCESS				0
  ------------------
  211|  15.0k|}
card-idprime.c:idprime_process_index:
  427|    287|{
  428|    287|	u8 *buf = NULL;
  429|    287|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|    287|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  430|    287|	int i, num_entries;
  431|    287|	idprime_object_t new_object;
  432|       |
  433|    287|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    287|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    287|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    287|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 287]
  |  |  ------------------
  ------------------
  434|       |
  435|    287|	buf = malloc(length);
  436|    287|	if (buf == NULL) {
  ------------------
  |  Branch (436:6): [True: 0, False: 287]
  ------------------
  437|      0|		goto done;
  438|      0|	}
  439|       |
  440|    287|	r = 0;
  441|    553|	do {
  442|    553|		if (length == r) {
  ------------------
  |  Branch (442:7): [True: 1, False: 552]
  ------------------
  443|      1|			r = SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|      1|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  444|      1|			goto done;
  445|      1|		}
  446|    552|		const int got = iso_ops->read_binary(card, r, buf + r, length - r, 0);
  447|    552|		if (got < 1) {
  ------------------
  |  Branch (447:7): [True: 26, False: 526]
  ------------------
  448|     26|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     26|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  449|     26|			goto done;
  450|     26|		}
  451|       |		/* First byte shows the number of entries, each of them 21 bytes long */
  452|    526|		num_entries = buf[0];
  453|    526|		r += got;
  454|    526|	} while(r < num_entries * 21 + 1);
  ------------------
  |  Branch (454:10): [True: 266, False: 260]
  ------------------
  455|       |
  456|    260|	new_object.fd = 0;
  457|  7.76k|	for (i = 0; i < num_entries; i++) {
  ------------------
  |  Branch (457:14): [True: 7.50k, False: 260]
  ------------------
  458|  7.50k|		u8 *start = &buf[i*21+1];
  459|       |
  460|       |		/* First two bytes specify the object DF */
  461|  7.50k|		new_object.df[0] = start[0];
  462|  7.50k|		new_object.df[1] = start[1];
  463|       |		/* Second two bytes refer to the object size */
  464|  7.50k|		new_object.length = bebytes2ushort(&start[2]);
  465|  7.50k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "df=%s, len=%u",
  ------------------
  |  |   70|  7.50k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|  7.50k|			sc_dump_hex(new_object.df, sizeof(new_object.df)), new_object.length);
  467|       |		/* in minidriver, mscp/kxcNN or kscNN lists certificates */
  468|  7.50k|		if (((memcmp(&start[4], "ksc", 3) == 0) || memcmp(&start[4], "kxc", 3) == 0)
  ------------------
  |  Branch (468:8): [True: 1.06k, False: 6.43k]
  |  Branch (468:46): [True: 12, False: 6.42k]
  ------------------
  469|  1.07k|			&& (memcmp(&start[12], "mscp", 5) == 0)) {
  ------------------
  |  Branch (469:7): [True: 715, False: 364]
  ------------------
  470|    715|			uint8_t cert_id = 0;
  471|    715|			idprime_container_t *container = NULL;
  472|       |
  473|    715|			if (start[7] >= '0' && start[7] <= '9' && start[8] >= '0' && start[8] <= '9') {
  ------------------
  |  Branch (473:8): [True: 667, False: 48]
  |  Branch (473:27): [True: 601, False: 66]
  |  Branch (473:46): [True: 132, False: 469]
  |  Branch (473:65): [True: 34, False: 98]
  ------------------
  474|     34|				cert_id = (start[7] - '0') * 10 + start[8] - '0';
  475|     34|			}
  476|    715|			new_object.fd++;
  477|    715|			new_object.key_reference = -1;
  478|    715|			new_object.valid_key_ref = 0;
  479|    715|			new_object.pin_index = 1;
  480|       |
  481|    715|			container = (idprime_container_t *) list_seek(&priv->containers, &cert_id);
  482|    715|			if (!container) {
  ------------------
  |  Branch (482:8): [True: 715, False: 0]
  ------------------
  483|       |				/* Container map missing container with certificate ID */
  484|    715|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "No corresponding container with private key found for certificate with id=%d", cert_id);
  ------------------
  |  |   70|    715|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  485|    715|				if (card->type != SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (485:9): [True: 705, False: 10]
  ------------------
  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|    705|					sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Adding certificate with fd=%d", new_object.fd);
  ------------------
  |  |   70|    705|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  490|    705|					idprime_add_object_to_list(&priv->pki_list, &new_object);
  491|    705|					continue;
  492|    705|				}
  493|    715|			}
  494|       |
  495|     10|			switch (card->type) {
  496|      0|			case SC_CARD_TYPE_IDPRIME_3810:
  ------------------
  |  Branch (496:4): [True: 0, False: 10]
  ------------------
  497|      0|				new_object.key_reference = 0x31 + cert_id;
  498|      0|				break;
  499|      0|			case SC_CARD_TYPE_IDPRIME_830:
  ------------------
  |  Branch (499:4): [True: 0, False: 10]
  ------------------
  500|      0|				new_object.key_reference = 0x41 + cert_id;
  501|      0|				break;
  502|      0|			case SC_CARD_TYPE_IDPRIME_930:
  ------------------
  |  Branch (502:4): [True: 0, False: 10]
  ------------------
  503|      0|				new_object.key_reference = 0x11 + cert_id * 2;
  504|      0|				break;
  505|      0|			case SC_CARD_TYPE_IDPRIME_930_PLUS:
  ------------------
  |  Branch (505:4): [True: 0, False: 10]
  ------------------
  506|      0|				new_object.key_reference = 0x10 + cert_id * 2;
  507|      0|				break;
  508|     10|			case SC_CARD_TYPE_IDPRIME_940: {
  ------------------
  |  Branch (508:4): [True: 10, False: 0]
  ------------------
  509|     10|					idprime_keyref_t *keyref = (idprime_keyref_t *) list_seek(&priv->keyrefmap, &cert_id);
  510|     10|					if (!keyref) {
  ------------------
  |  Branch (510:10): [True: 10, False: 0]
  ------------------
  511|       |						/* Key reference file does not contain record of the key for given certificate */
  512|     10|						sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "No corresponding key reference found for certificate with id=%d", cert_id);
  ------------------
  |  |   70|     10|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  513|     10|						sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Adding certificate with fd=%d", new_object.fd);
  ------------------
  |  |   70|     10|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  514|     10|						idprime_add_object_to_list(&priv->pki_list, &new_object);
  515|     10|						continue;
  516|     10|					}
  517|      0|					new_object.key_reference = keyref->key_reference;
  518|      0|					new_object.pin_index = keyref->pin_index;
  519|      0|					break;
  520|     10|				}
  521|      0|			case SC_CARD_TYPE_IDPRIME_840:
  ------------------
  |  Branch (521:4): [True: 0, False: 10]
  ------------------
  522|      0|				new_object.key_reference = 0xf7 + cert_id;
  523|      0|				break;
  524|      0|			default:
  ------------------
  |  Branch (524:4): [True: 0, False: 10]
  ------------------
  525|      0|				new_object.key_reference = 0x56 + cert_id;
  526|      0|				break;
  527|     10|			}
  528|      0|			new_object.valid_key_ref = 1;
  529|      0|			if (container != NULL) {
  ------------------
  |  Branch (529:8): [True: 0, False: 0]
  ------------------
  530|      0|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found certificate with fd=%d, key_ref=%d corresponding to container \"%s\"",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  531|      0|					new_object.fd, new_object.key_reference, container->guid);
  532|      0|			} else {
  533|      0|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found certificate with fd=%d, key_ref=%d without corresponding container",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  534|      0|					new_object.fd, new_object.key_reference);
  535|      0|			}
  536|       |
  537|      0|			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|  6.78k|		} else if ((memcmp(&start[4], "tinfo", 6) == 0) && (memcmp(&start[12], "p11", 4) == 0)) {
  ------------------
  |  Branch (540:14): [True: 61, False: 6.72k]
  |  Branch (540:54): [True: 29, False: 32]
  ------------------
  541|     29|			memcpy(priv->tinfo_df, new_object.df, sizeof(priv->tinfo_df));
  542|     29|			priv->tinfo_present = 1;
  543|     29|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found p11/tinfo 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__
  |  |  ------------------
  ------------------
  544|  6.75k|		} else if ((memcmp(&start[4], "cmapfile", 8) == 0) && (memcmp(&start[12], "mscp", 4) == 0)) {
  ------------------
  |  Branch (544:14): [True: 61, False: 6.69k]
  |  Branch (544:57): [True: 36, False: 25]
  ------------------
  545|     36|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found mscp/cmapfile object %s",
  ------------------
  |  |   70|    130|#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: 22, False: 14]
  |  |  |  Branch (70:115): [True: 7, False: 15]
  |  |  ------------------
  ------------------
  546|     36|					(start[0] == 02 && start[1] == 04 ? "(already processed)" : "(in non-standard path!)"));
  547|  6.72k|		} else if (memcmp(&start[4], "cardapps", 8) == 0) {
  ------------------
  |  Branch (547:14): [True: 18, False: 6.70k]
  ------------------
  548|     18|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found cardapps object");
  ------------------
  |  |   70|     18|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  549|  6.70k|		} else if (memcmp(&start[4], "cardid", 6) == 0) {
  ------------------
  |  Branch (549:14): [True: 14, False: 6.68k]
  ------------------
  550|     14|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found cardid object");
  ------------------
  |  |   70|     14|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  551|  6.68k|		} else if (memcmp(&start[4], "cardcf", 6) == 0) {
  ------------------
  |  Branch (551:14): [True: 11, False: 6.67k]
  ------------------
  552|     11|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found cardcf 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__
  |  |  ------------------
  ------------------
  553|     11|		}
  554|  7.50k|	}
  555|       |
  556|    260|	r = SC_SUCCESS;
  ------------------
  |  |   28|    260|#define SC_SUCCESS				0
  ------------------
  557|    287|done:
  558|    287|	free(buf);
  559|    287|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    287|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    287|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    287|	int _ret = r; \
  |  |  |  |  155|    287|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 287, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    287|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 260]
  |  |  |  |  ------------------
  |  |  |  |  157|    287|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    287|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    287|	return _ret; \
  |  |  |  |  163|    287|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|    287|}
card-idprime.c:idprime_finish:
  743|    260|{
  744|    260|	idprime_private_data_t * priv = card->drv_data;
  745|       |
  746|    260|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    260|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    260|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    260|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 260]
  |  |  ------------------
  ------------------
  747|    260|	if (priv) {
  ------------------
  |  Branch (747:6): [True: 260, False: 0]
  ------------------
  748|    260|		idprime_free_private_data(priv);
  749|    260|	}
  750|    260|	return SC_SUCCESS;
  ------------------
  |  |   28|    260|#define SC_SUCCESS				0
  ------------------
  751|    260|}
card-idprime.c:idprime_read_binary:
  968|  1.12k|{
  969|  1.12k|	struct idprime_private_data *priv = card->drv_data;
  970|  1.12k|	int r = 0;
  971|  1.12k|	int size;
  972|  1.12k|	size_t sz;
  973|       |
  974|  1.12k|	sc_log(card->ctx, "called; %zu bytes at offset %d", count, offset);
  ------------------
  |  |   71|  1.12k|#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|  1.12k|	if (!priv->cached && offset == 0) {
  ------------------
  |  Branch (976:6): [True: 111, False: 1.01k]
  |  Branch (976:23): [True: 111, False: 0]
  ------------------
  977|       |		/* Read what was reported by FCI from select command */
  978|    111|		size_t left = priv->file_size;
  979|    111|		unsigned read = 0;
  980|       |
  981|       |		// this function is called to read and uncompress the certificate
  982|    111|		u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  983|    111|		u8 *data_buffer = buffer;
  984|    111|		if (sizeof(buffer) < count || sizeof(buffer) < priv->file_size) {
  ------------------
  |  Branch (984:7): [True: 0, False: 111]
  |  Branch (984:33): [True: 0, False: 111]
  ------------------
  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|    209|		while (left > 0) {
  ------------------
  |  Branch (987:10): [True: 149, False: 60]
  ------------------
  988|    149|			r = iso_ops->read_binary(card, read, buffer + read, priv->file_size - read, flags);
  989|    149|			if (r <= 0) {
  ------------------
  |  Branch (989:8): [True: 51, False: 98]
  ------------------
  990|     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|     50|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 50, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|     51|			}
  992|     98|			left -= r;
  993|     98|			read += r;
  994|     98|		}
  995|     60|		if (read < 4 || read != priv->file_size) {
  ------------------
  |  Branch (995:7): [True: 25, False: 35]
  |  Branch (995:19): [True: 0, False: 35]
  ------------------
  996|     25|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     25|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     25|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     25|	int _ret = r; \
  |  |  |  |  155|     25|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     25|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     25|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     25|	return _ret; \
  |  |  |  |  163|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  997|     25|		}
  998|     35|		if (buffer[0] == 1 && buffer[1] == 0) {
  ------------------
  |  Branch (998:7): [True: 7, False: 28]
  |  Branch (998:25): [True: 5, False: 2]
  ------------------
  999|       |			/* Data will be decompressed later */
 1000|      5|			data_buffer += 4;
 1001|      5|			sz = priv->file_size - 4;
 1002|      5|			if (flags)
  ------------------
  |  Branch (1002:8): [True: 0, False: 5]
  ------------------
 1003|      0|				*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|      0|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 1004|     30|		} else {
 1005|     30|			sz = priv->file_size;
 1006|     30|		}
 1007|     35|		priv->cache_buf = malloc(sz);
 1008|     35|		if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (1008:7): [True: 0, False: 35]
  ------------------
 1009|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1010|      0|		}
 1011|     35|		memcpy(priv->cache_buf, data_buffer, sz);
 1012|     35|		priv->cache_buf_len = sz;
 1013|     35|		priv->cached = 1;
 1014|     35|	}
 1015|  1.04k|	if (offset >= priv->cache_buf_len) {
  ------------------
  |  Branch (1015:6): [True: 5, False: 1.04k]
  ------------------
 1016|      5|		return 0;
 1017|      5|	}
 1018|  1.04k|	size = (int) MIN((priv->cache_buf_len - offset), count);
  ------------------
  |  |   70|  1.04k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 5, False: 1.03k]
  |  |  ------------------
  ------------------
 1019|  1.04k|	memcpy(buf, priv->cache_buf + offset, size);
 1020|  1.04k|	return size;
 1021|  1.04k|}
card-idprime.c:idprime_select_file:
  942|  1.61k|{
  943|  1.61k|	int r;
  944|  1.61k|	idprime_private_data_t * priv = card->drv_data;
  945|       |
  946|  1.61k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.61k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.61k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.61k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.61k]
  |  |  ------------------
  ------------------
  947|       |
  948|       |	/* forget any old cached values */
  949|  1.61k|	if (priv->cache_buf) {
  ------------------
  |  Branch (949:6): [True: 23, False: 1.58k]
  ------------------
  950|     23|		free(priv->cache_buf);
  951|     23|		priv->cache_buf = NULL;
  952|     23|	}
  953|  1.61k|	priv->cache_buf_len = 0;
  954|  1.61k|	priv->cached = 0;
  955|       |
  956|  1.61k|	r = iso_ops->select_file(card, in_path, file_out);
  957|  1.61k|	if (r == SC_SUCCESS && file_out != NULL) {
  ------------------
  |  |   28|  3.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (957:6): [True: 245, False: 1.36k]
  |  Branch (957:25): [True: 183, False: 62]
  ------------------
  958|       | 	 	/* Cache the real file size for the caching read_binary() */
  959|    183| 	 	priv->file_size = (*file_out)->size;
  960|    183|	}
  961|       |	/* Return the exit code of the select command */
  962|  1.61k|	return r;
  963|  1.61k|}
card-idprime.c:idprime_card_ctl:
  909|  2.97k|{
  910|  2.97k|	idprime_private_data_t * priv = card->drv_data;
  911|       |
  912|  2.97k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.97k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.97k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.97k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.97k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.97k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  913|  2.97k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  2.97k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  914|       |
  915|  2.97k|	if (priv == NULL) {
  ------------------
  |  Branch (915:6): [True: 0, False: 2.97k]
  ------------------
  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|  2.97k|	switch (cmd) {
  ------------------
  |  Branch (918:10): [True: 2.67k, False: 298]
  ------------------
  919|    291|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (919:3): [True: 291, False: 2.68k]
  ------------------
  920|    291|			return idprime_get_serial(card, (sc_serial_number_t *) ptr);
  921|    291|		case SC_CARDCTL_IDPRIME_GET_TOKEN_NAME:
  ------------------
  |  Branch (921:3): [True: 291, False: 2.68k]
  ------------------
  922|    291|			return idprime_get_token_name(card, (char **) ptr);
  923|    291|		case SC_CARDCTL_IDPRIME_INIT_GET_OBJECTS:
  ------------------
  |  Branch (923:3): [True: 291, False: 2.68k]
  ------------------
  924|    291|			return idprime_get_init_and_get_count(&priv->pki_list, &priv->pki_current,
  925|    291|				(int *)ptr);
  926|    757|		case SC_CARDCTL_IDPRIME_GET_NEXT_OBJECT:
  ------------------
  |  Branch (926:3): [True: 757, False: 2.21k]
  ------------------
  927|    757|			return idprime_fill_prkey_info(&priv->pki_list, &priv->pki_current,
  928|    757|				(sc_pkcs15_prkey_info_t *)ptr);
  929|    291|		case SC_CARDCTL_IDPRIME_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (929:3): [True: 291, False: 2.68k]
  ------------------
  930|    291|			return idprime_final_iterator(&priv->pki_list);
  931|    757|		case SC_CARDCTL_IDPRIME_GET_PIN_ID:
  ------------------
  |  Branch (931:3): [True: 757, False: 2.21k]
  ------------------
  932|    757|			return idprime_get_pin_id(&priv->pki_list, &priv->pki_current,
  933|    757|				(const char **)ptr);
  934|  2.97k|	}
  935|       |
  936|    298|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    298|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    298|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    298|	int _ret = r; \
  |  |  |  |  155|    298|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 298, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    298|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    298|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 298, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    298|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    298|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    298|	return _ret; \
  |  |  |  |  163|    298|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  937|    298|}
card-idprime.c:idprime_get_serial:
  826|    291|{
  827|    291|	sc_path_t cardid_path;
  828|    291|	sc_file_t *file = NULL;
  829|    291|	u8 buf[IDPRIME_CARDID_LEN];
  830|    291|	int r;
  831|       |
  832|    291|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    291|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    291|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    291|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    291|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 291]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  833|       |
  834|       |	/* XXX this is assumed to be cardid for windows. It can be read from the index file */
  835|    291|	sc_format_path("0201", &cardid_path);
  836|    291|	r = iso_ops->select_file(card, &cardid_path, &file);
  837|    291|	if (r != SC_SUCCESS || file->size != IDPRIME_CARDID_LEN) { /* The cardid is always 16 B */
  ------------------
  |  |   28|    582|#define SC_SUCCESS				0
  ------------------
              	if (r != SC_SUCCESS || file->size != IDPRIME_CARDID_LEN) { /* The cardid is always 16 B */
  ------------------
  |  |  823|     20|#define IDPRIME_CARDID_LEN 16
  ------------------
  |  Branch (837:6): [True: 271, False: 20]
  |  Branch (837:25): [True: 17, False: 3]
  ------------------
  838|    288|		sc_file_free(file);
  839|    288|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|    288|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    288|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    288|	int _ret = r; \
  |  |  |  |  155|    288|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 288, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    288|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    288|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    288|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    288|	return _ret; \
  |  |  |  |  163|    288|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|    288|	}
  841|       |
  842|      3|	r = iso_ops->read_binary(card, 0, buf, file->size, 0);
  843|      3|	sc_file_free(file);
  844|      3|	if (r < 1) {
  ------------------
  |  Branch (844:6): [True: 1, False: 2]
  ------------------
  845|      1|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|      2|	} else if (r != IDPRIME_CARDID_LEN) {
  ------------------
  |  |  823|      2|#define IDPRIME_CARDID_LEN 16
  ------------------
  |  Branch (846:13): [True: 1, False: 1]
  ------------------
  847|      1|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  848|      1|	}
  849|       |
  850|      1|	serial->len = MIN(IDPRIME_CARDID_LEN, SC_MAX_SERIALNR);
  ------------------
  |  |   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|    291|{
  857|    291|	idprime_private_data_t * priv = card->drv_data;
  858|    291|	sc_path_t tinfo_path = {"\x00\x00", 2, 0, 0, SC_PATH_TYPE_PATH, {"", 0}};
  ------------------
  |  |  119|    291|#define SC_PATH_TYPE_PATH		2
  ------------------
  859|    291|	sc_file_t *file = NULL;
  860|    291|	u8 buf[2];
  861|    291|	char *name;
  862|    291|	int r;
  863|       |
  864|    291|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    291|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    291|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    291|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    291|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 291]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  865|       |
  866|    291|	if (tname == NULL) {
  ------------------
  |  Branch (866:6): [True: 0, False: 291]
  ------------------
  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|    291|	if (!priv->tinfo_present) {
  ------------------
  |  Branch (870:6): [True: 267, False: 24]
  ------------------
  871|    267|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    267|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    267|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    267|	int _ret = r; \
  |  |  |  |  155|    267|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 267, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    267|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    267|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 267, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    267|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    267|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    267|	return _ret; \
  |  |  |  |  163|    267|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  872|    267|	}
  873|       |
  874|     24|	memcpy(tinfo_path.value, priv->tinfo_df, 2);
  875|     24|	r = iso_ops->select_file(card, &tinfo_path, &file);
  876|     24|	if (r != SC_SUCCESS || file->size == 0) {
  ------------------
  |  |   28|     48|#define SC_SUCCESS				0
  ------------------
  |  Branch (876:6): [True: 13, False: 11]
  |  Branch (876:25): [True: 1, False: 10]
  ------------------
  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|     10|	r = iso_ops->read_binary(card, 0, buf, 2, 0);
  883|     10|	if (r < 2 || buf[1] > file->size) { /* make sure we do not overrun */
  ------------------
  |  Branch (883:6): [True: 1, False: 9]
  |  Branch (883:15): [True: 1, False: 8]
  ------------------
  884|      2|		sc_file_free(file);
  885|      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: 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|      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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|      2|	}
  887|      8|	sc_file_free(file);
  888|       |
  889|      8|	name = malloc(buf[1]);
  890|      8|	if (name == NULL) {
  ------------------
  |  Branch (890:6): [True: 0, False: 8]
  ------------------
  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|      8|	r = iso_ops->read_binary(card, 2, (unsigned char *)name, buf[1], 0);
  895|      8|	if (r < 1) {
  ------------------
  |  Branch (895:6): [True: 4, False: 4]
  ------------------
  896|      4|		free(name);
  897|      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|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  898|      4|	}
  899|       |
  900|      4|	if (name[r-1] != '\0') {
  ------------------
  |  Branch (900:6): [True: 2, False: 2]
  ------------------
  901|      2|		name[r-1] = '\0';
  902|      2|	}
  903|      4|	*tname = name;
  904|       |
  905|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  906|      4|}
card-idprime.c:idprime_get_init_and_get_count:
  768|    291|{
  769|    291|	if (countp == NULL || entry == NULL) {
  ------------------
  |  Branch (769:6): [True: 0, False: 291]
  |  Branch (769:24): [True: 0, False: 291]
  ------------------
  770|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  771|      0|	}
  772|    291|	*countp = list_size(list);
  773|    291|	list_iterator_start(list);
  774|    291|	*entry = list_iterator_next(list);
  775|    291|	return SC_SUCCESS;
  ------------------
  |  |   28|    291|#define SC_SUCCESS				0
  ------------------
  776|    291|}
card-idprime.c:idprime_fill_prkey_info:
  787|    757|{
  788|    757|	memset(prkey_info, 0, sizeof(sc_pkcs15_prkey_info_t));
  789|    757|	if (*entry == NULL) {
  ------------------
  |  Branch (789:6): [True: 0, False: 757]
  ------------------
  790|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  791|      0|	}
  792|       |
  793|    757|	prkey_info->path.len = sizeof((*entry)->df);
  794|    757|	memcpy(prkey_info->path.value, (*entry)->df, sizeof((*entry)->df));
  795|    757|	prkey_info->path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    757|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  796|       |	/* Do not specify the length -- it will be read from the FCI */
  797|    757|	prkey_info->path.count = -1;
  798|       |
  799|       |	/* TODO figure out the IDs as the original driver? */
  800|    757|	prkey_info->id.value[0] = ((*entry)->fd >> 8) & 0xff;
  801|    757|	prkey_info->id.value[1] = (*entry)->fd & 0xff;
  802|    757|	prkey_info->id.len = 2;
  803|    757|	if ((*entry)->valid_key_ref)
  ------------------
  |  Branch (803:6): [True: 0, False: 757]
  ------------------
  804|      0|		prkey_info->key_reference = (*entry)->key_reference;
  805|    757|	else
  806|    757|		prkey_info->key_reference = -1;
  807|    757|	*entry = list_iterator_next(list);
  808|    757|	return SC_SUCCESS;
  ------------------
  |  |   28|    757|#define SC_SUCCESS				0
  ------------------
  809|    757|}
card-idprime.c:idprime_final_iterator:
  780|    291|{
  781|    291|	list_iterator_stop(list);
  782|    291|	return SC_SUCCESS;
  ------------------
  |  |   28|    291|#define SC_SUCCESS				0
  ------------------
  783|    291|}
card-idprime.c:idprime_get_pin_id:
  813|    757|{
  814|    757|	if (pin_id == NULL || entry == NULL) {
  ------------------
  |  Branch (814:6): [True: 0, False: 757]
  |  Branch (814:24): [True: 0, False: 757]
  ------------------
  815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  816|      0|	}
  817|    757|	*pin_id = "11"; // normal PIN id
  818|    757|	if ((*entry)->pin_index != 1)
  ------------------
  |  Branch (818:6): [True: 0, False: 757]
  ------------------
  819|      0|		*pin_id = "83"; // signature PIN id
  820|    757|	return SC_SUCCESS;
  ------------------
  |  |   28|    757|#define SC_SUCCESS				0
  ------------------
  821|    757|}
card-idprime.c:idprime_get_challenge:
 1226|    407|{
 1227|    407|	u8 rbuf[16];
 1228|    407|	size_t out_len;
 1229|    407|	struct sc_apdu apdu;
 1230|    407|	int r;
 1231|       |
 1232|    407|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    407|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    407|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    407|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    407|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 407]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1233|       |
 1234|    407|	if (len <= 8) {
  ------------------
  |  Branch (1234:6): [True: 19, False: 388]
  ------------------
 1235|       |		/* official closed driver always calls this regardless the length */
 1236|     19|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x84, 0x00, 0x01);
  ------------------
  |  |  301|     19|#define SC_APDU_CASE_2			0x22
  ------------------
 1237|     19|		apdu.le = apdu.resplen = 8;
 1238|    388|	} else {
 1239|       |		/* this was discovered accidentally - all 16 bytes seem random */
 1240|    388|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x84, 0x00, 0x00);
  ------------------
  |  |  301|    388|#define SC_APDU_CASE_2			0x22
  ------------------
 1241|    388|		apdu.le = apdu.resplen = 16;
 1242|    388|	}
 1243|    407|	apdu.resp = rbuf;
 1244|       |
 1245|    407|	r = sc_transmit_apdu(card, &apdu);
 1246|    407|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    407|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    407|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    407|	int _ret = (r); \
  |  |  |  |  168|    407|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 404]
  |  |  |  |  ------------------
  |  |  |  |  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|    407|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 404]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1247|       |
 1248|    404|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1249|    404|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE failed");
  ------------------
  |  |  174|    404|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    404|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    404|	int _ret = (r); \
  |  |  |  |  168|    404|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 125, False: 279]
  |  |  |  |  ------------------
  |  |  |  |  169|    125|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    125|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    125|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    125|		return _ret; \
  |  |  |  |  172|    125|	} \
  |  |  |  |  173|    404|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 279]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1250|       |
 1251|    279|	out_len = len < apdu.resplen ? len : apdu.resplen;
  ------------------
  |  Branch (1251:12): [True: 1, False: 278]
  ------------------
 1252|    279|	memcpy(rnd, rbuf, out_len);
 1253|       |
 1254|    279|	LOG_FUNC_RETURN(card->ctx, (int) out_len);
  ------------------
  |  |  164|    279|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    279|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    279|	int _ret = r; \
  |  |  |  |  155|    279|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 275]
  |  |  |  |  ------------------
  |  |  |  |  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|    275|	} else { \
  |  |  |  |  159|    275|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    275|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    275|	} \
  |  |  |  |  162|    279|	return _ret; \
  |  |  |  |  163|    279|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1255|    279|}

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

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

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

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

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

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

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

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

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

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

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

populate_blobs_to_mf:
  381|    633|{
  382|    633|	pgp_do_info_t	*info;
  383|       |
  384|    633|	if (priv->mf == NULL)
  ------------------
  |  Branch (384:6): [True: 0, False: 633]
  ------------------
  385|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  386|       |
  387|  37.6k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (387:33): [True: 37.6k, False: 0]
  |  Branch (387:51): [True: 37.0k, False: 633]
  ------------------
  388|  37.0k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (388:7): [True: 27.3k, False: 9.64k]
  |  Branch (388:53): [True: 11.8k, False: 15.5k]
  ------------------
  389|  11.8k|			pgp_blob_t *child = NULL;
  390|  11.8k|			sc_file_t *file = sc_file_new();
  391|       |
  392|  11.8k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  393|       |
  394|       |			/* catch out of memory condition */
  395|  11.8k|			if (child == NULL) {
  ------------------
  |  Branch (395:8): [True: 0, False: 11.8k]
  ------------------
  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|  11.8k|		}
  400|  37.0k|	}
  401|    633|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    633|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    633|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    633|	int _ret = r; \
  |  |  |  |  155|    633|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 633, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    633|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 633]
  |  |  |  |  ------------------
  |  |  |  |  157|    633|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    633|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    633|	return _ret; \
  |  |  |  |  163|    633|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|    633|}
_pgp_add_algo:
  740|    721|{
  741|    721|	unsigned long flags = 0, ext_flags = 0;
  742|       |
  743|    721|	if (!card || !key_info)
  ------------------
  |  Branch (743:6): [True: 0, False: 721]
  |  Branch (743:15): [True: 0, False: 721]
  ------------------
  744|      0|		return 0;
  745|       |
  746|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  747|    721|	switch (key_info->algorithm) {
  748|    721|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  870|    721|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (748:2): [True: 721, False: 0]
  ------------------
  749|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 /
  750|       |		 * v3.x section 7.2.11 & 7.2.12 */
  751|    721|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  111|    721|#define SC_ALGORITHM_RSA_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|    721|#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|    721|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  752|    721|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  133|    721|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  753|    721|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |   93|    721|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  754|       |
  755|    721|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  756|    721|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  757|    721|				do_num, key_info->u.rsa.modulus_len);
  758|    721|		break;
  759|      0|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  871|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (759:2): [True: 0, False: 721]
  ------------------
  760|       |		/* The montgomery curve (curve25519) needs to go through
  761|       |		 * different paths, otherwise we handle it as a normal EC key */
  762|      0|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (762:7): [True: 0, False: 0]
  ------------------
  763|      0|			break;
  764|       |		/* fall through */
  765|      0|	case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  872|      0|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (765:2): [True: 0, False: 721]
  ------------------
  766|       |		/* v3.0+: ECC [RFC 4880 & 6637] */
  767|       |
  768|       |		/* Allow curve to be used by both ECDH and ECDSA.
  769|       |		 * pgp_init set these flags the same way */
  770|      0|		flags = SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  771|      0|		flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  772|      0|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|      0|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  773|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  774|      0|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|      0|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  775|       |
  776|      0|		_sc_card_add_ec_alg(card, key_info->u.ec.key_length, flags, ext_flags,
  777|      0|			&key_info->u.ec.oid);
  778|      0|		sc_log(card->ctx, "DO %uX: Added EC algorithm (%d), mod_len = %zu" ,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  779|      0|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  780|      0|		break;
  781|      0|	case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  873|      0|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (781:2): [True: 0, False: 721]
  ------------------
  782|       |		/* EdDSA from draft-ietf-openpgp-rfc4880bis-08 */
  783|       |		/* Handle Yubikey bug, that in DO FA curve25519 has EDDSA algo */
  784|      0|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (784:7): [True: 0, False: 0]
  ------------------
  785|      0|			break;
  786|      0|		_sc_card_add_eddsa_alg(card, key_info->u.ec.key_length,
  787|      0|				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  188|      0|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
              				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  788|       |
  789|      0|		sc_log(card->ctx, "DO %uX: Added EDDSA algorithm (%d), mod_len = %zu" ,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  790|      0|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  791|      0|		break;
  792|      0|	default:
  ------------------
  |  Branch (792:2): [True: 0, False: 721]
  ------------------
  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|    721|	}
  798|       |	/* return true */
  799|    721|	return 1;
  800|    721|}
sc_get_openpgp_driver:
 4209|  15.7k|{
 4210|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4211|       |
 4212|  15.7k|	iso_ops = iso_drv->ops;
 4213|       |
 4214|  15.7k|	pgp_ops = *iso_ops;
 4215|  15.7k|	pgp_ops.match_card	= pgp_match_card;
 4216|  15.7k|	pgp_ops.init		= pgp_init;
 4217|  15.7k|	pgp_ops.finish		= pgp_finish;
 4218|  15.7k|	pgp_ops.select_file	= pgp_select_file;
 4219|  15.7k|	pgp_ops.list_files	= pgp_list_files;
 4220|  15.7k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4221|  15.7k|	pgp_ops.read_binary	= pgp_read_binary;
 4222|  15.7k|	pgp_ops.write_binary	= NULL;
 4223|  15.7k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4224|  15.7k|	pgp_ops.logout		= pgp_logout;
 4225|  15.7k|	pgp_ops.get_data	= pgp_get_data;
 4226|  15.7k|	pgp_ops.put_data	= pgp_put_data;
 4227|  15.7k|	pgp_ops.set_security_env= pgp_set_security_env;
 4228|  15.7k|	pgp_ops.compute_signature= pgp_compute_signature;
 4229|  15.7k|	pgp_ops.decipher	= pgp_decipher;
 4230|  15.7k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4231|  15.7k|	pgp_ops.delete_file	= pgp_delete_file;
 4232|  15.7k|	pgp_ops.update_binary	= pgp_update_binary;
 4233|  15.7k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4234|       |
 4235|  15.7k|	return &pgp_drv;
 4236|  15.7k|}
card-openpgp.c:pgp_new_blob:
 1240|  37.7k|{
 1241|  37.7k|	pgp_blob_t *blob = NULL;
 1242|       |
 1243|  37.7k|	if (file == NULL)
  ------------------
  |  Branch (1243:6): [True: 0, False: 37.7k]
  ------------------
 1244|      0|		return NULL;
 1245|       |
 1246|  37.7k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1246:6): [True: 37.7k, False: 0]
  ------------------
 1247|  37.7k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  37.7k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1248|  37.7k|		pgp_do_info_t *info;
 1249|       |
 1250|  37.7k|		blob->file = file;
 1251|       |
 1252|  37.7k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  37.7k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1253|  37.7k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  37.7k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1254|  37.7k|		blob->file->id           = file_id;
 1255|       |
 1256|  37.7k|		blob->id     = file_id;
 1257|  37.7k|		blob->parent = parent;
 1258|       |
 1259|  37.7k|		if (parent != NULL) {
  ------------------
  |  Branch (1259:7): [True: 37.1k, False: 633]
  ------------------
 1260|  37.1k|			pgp_blob_t **p;
 1261|       |
 1262|       |			/* set file's path = parent's path + file's id */
 1263|  37.1k|			blob->file->path = parent->file->path;
 1264|  37.1k|			sc_append_file_id(&blob->file->path, file_id);
 1265|       |
 1266|       |			/* append blob to list of parent's children */
 1267|  3.95M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1267:29): [True: 3.91M, False: 37.1k]
  ------------------
 1268|  3.91M|				;
 1269|  37.1k|			*p = blob;
 1270|  37.1k|		}
 1271|    633|		else {
 1272|    633|			char path[10] = "0000";	/* long enough */
 1273|       |
 1274|       |			/* no parent: set file's path = file's id */
 1275|    633|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1275:8): [True: 0, False: 633]
  ------------------
 1276|      0|				free(blob);
 1277|      0|				return NULL;
 1278|      0|			}
 1279|       |
 1280|    633|			sc_format_path(path, &blob->file->path);
 1281|    633|		}
 1282|       |
 1283|       |		/* find matching DO info: set file type depending on it */
 1284|  1.49M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1284:34): [True: 1.49M, False: 0]
  |  Branch (1284:52): [True: 1.48M, False: 10.1k]
  ------------------
 1285|  1.48M|			if (info->id == file_id) {
  ------------------
  |  Branch (1285:8): [True: 27.5k, False: 1.45M]
  ------------------
 1286|  27.5k|				blob->info = info;
 1287|  27.5k|				blob->file->type = blob->info->type;
 1288|  27.5k|				pgp_attach_acl(card, blob->file, info);
 1289|  27.5k|				break;
 1290|  27.5k|			}
 1291|  1.48M|		}
 1292|  37.7k|	}
 1293|       |
 1294|  37.7k|	return blob;
 1295|  37.7k|}
card-openpgp.c:pgp_attach_acl:
 1172|  27.5k|{
 1173|  27.5k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  27.5k|#define SC_AC_NONE			0x00000000
  ------------------
 1174|  27.5k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  27.5k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1175|       |
 1176|       |	/* Write access */
 1177|  27.5k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1177:10): [True: 27.5k, False: 0]
  ------------------
 1178|  8.96k|	case WRITE_NEVER:
  ------------------
  |  Branch (1178:2): [True: 8.96k, False: 18.6k]
  ------------------
 1179|  8.96k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  8.96k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1180|  8.96k|		break;
 1181|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1181:2): [True: 0, False: 27.5k]
  ------------------
 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.26k|	case WRITE_PIN2:
  ------------------
  |  Branch (1185:2): [True: 1.26k, False: 26.3k]
  ------------------
 1186|  1.26k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.26k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1187|  1.26k|		key_ref = 0x02;
 1188|  1.26k|		break;
 1189|  17.3k|	case WRITE_PIN3:
  ------------------
  |  Branch (1189:2): [True: 17.3k, False: 10.2k]
  ------------------
 1190|  17.3k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  17.3k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1191|  17.3k|		key_ref = 0x03;
 1192|  17.3k|		break;
 1193|  27.5k|	}
 1194|       |
 1195|  27.5k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  55.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: 27.5k, False: 0]
  |  Branch (1195:30): [True: 0, False: 0]
  ------------------
 1196|  27.5k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  27.5k|#define SC_AC_OP_WRITE			24
  ------------------
 1197|  27.5k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  27.5k|#define SC_AC_OP_UPDATE			23
  ------------------
 1198|  27.5k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  27.5k|#define SC_AC_OP_DELETE			2
  ------------------
 1199|  27.5k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  27.5k|#define SC_AC_OP_CREATE			3
  ------------------
 1200|  27.5k|	}
 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|  27.5k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  27.5k|#define SC_AC_NONE			0x00000000
  ------------------
 1208|  27.5k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  27.5k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1209|       |	/* Read access */
 1210|  27.5k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1210:10): [True: 2.58k, False: 25.0k]
  ------------------
 1211|  1.31k|	case READ_NEVER:
  ------------------
  |  Branch (1211:2): [True: 1.31k, False: 26.2k]
  ------------------
 1212|  1.31k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.31k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1213|  1.31k|		break;
 1214|      0|	case READ_PIN1:
  ------------------
  |  Branch (1214:2): [True: 0, False: 27.5k]
  ------------------
 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|    633|	case READ_PIN2:
  ------------------
  |  Branch (1218:2): [True: 633, False: 26.9k]
  ------------------
 1219|    633|		method = SC_AC_CHV;
  ------------------
  |  |  151|    633|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1220|    633|		key_ref = 0x02;
 1221|    633|		break;
 1222|    633|	case READ_PIN3:
  ------------------
  |  Branch (1222:2): [True: 633, False: 26.9k]
  ------------------
 1223|    633|		method = SC_AC_CHV;
  ------------------
  |  |  151|    633|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1224|    633|		key_ref = 0x03;
 1225|    633|		break;
 1226|  27.5k|	}
 1227|       |
 1228|  27.5k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  55.1k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  25.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1228:6): [True: 2.58k, False: 25.0k]
  |  Branch (1228:30): [True: 0, False: 25.0k]
  ------------------
 1229|  2.58k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  2.58k|#define SC_AC_OP_READ			22
  ------------------
 1230|  2.58k|	}
 1231|  27.5k|}
card-openpgp.c:pgp_match_card:
  326|  3.35k|{
  327|  3.35k|	int i;
  328|       |
  329|  3.35k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.35k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.35k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.35k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.35k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.35k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.35k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 16, False: 3.33k]
  ------------------
  333|     16|		card->name = pgp_atrs[i].name;
  334|     16|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  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: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|     16|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     16|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     16|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|     16|	}
  336|  3.33k|	else {
  337|  3.33k|		sc_path_t	partial_aid;
  338|  3.33k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.33k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.33k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.33k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.33k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.33k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.33k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 638, False: 2.69k]
  ------------------
  346|    638|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    638|			card->name = default_cardname;
  348|       |
  349|    638|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 637, False: 1]
  ------------------
  350|    637|				(void) get_full_pgp_aid(card, file);
  351|    638|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 87, False: 551]
  ------------------
  352|     87|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     87|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     87|				switch (major) {
  355|      4|					case 1:
  ------------------
  |  Branch (355:6): [True: 4, False: 83]
  ------------------
  356|      4|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      4|						card->name = default_cardname_v1;
  358|      4|						break;
  359|      5|					case 2:
  ------------------
  |  Branch (359:6): [True: 5, False: 82]
  ------------------
  360|      5|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|      5|						card->name = default_cardname_v2;
  362|      5|						break;
  363|      6|					case 3:
  ------------------
  |  Branch (363:6): [True: 6, False: 81]
  ------------------
  364|      6|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      6|						card->name = default_cardname_v3;
  366|      6|						break;
  367|     72|					default:
  ------------------
  |  Branch (367:6): [True: 72, False: 15]
  ------------------
  368|     72|						break;
  369|     87|				}
  370|     87|			}
  371|    638|			sc_file_free(file);
  372|    638|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    638|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    638|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    638|	int _ret = r; \
  |  |  |  |  155|    638|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 638]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    638|	} else { \
  |  |  |  |  159|    638|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    638|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    638|	} \
  |  |  |  |  162|    638|	return _ret; \
  |  |  |  |  163|    638|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    638|		}
  374|  3.33k|	}
  375|  2.69k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.69k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.69k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.69k|	int _ret = r; \
  |  |  |  |  155|  2.69k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.69k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.69k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.69k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.69k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.69k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.69k|	return _ret; \
  |  |  |  |  163|  2.69k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.69k|}
card-openpgp.c:get_full_pgp_aid:
  307|  1.27k|{
  308|  1.27k|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.27k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|  1.27k|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 1.27k, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|  1.27k|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|  1.27k|		file->namelen = MAX(r, 0);
  ------------------
  |  |   67|  1.27k|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (67:20): [True: 558, False: 718]
  |  |  ------------------
  ------------------
  314|  1.27k|	}
  315|       |
  316|  1.27k|	return r;
  317|  1.27k|}
card-openpgp.c:pgp_init:
  409|    654|{
  410|    654|	struct pgp_priv_data *priv;
  411|    654|	sc_path_t	path;
  412|    654|	sc_file_t	*file = NULL;
  413|    654|	int		r, i;
  414|       |
  415|    654|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    654|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    654|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    654|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    654|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 654]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|       |
  417|    654|	priv = calloc (1, sizeof *priv);
  418|    654|	if (!priv)
  ------------------
  |  Branch (418:6): [True: 0, False: 654]
  ------------------
  419|    654|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|    654|	card->drv_data = priv;
  421|       |
  422|    654|	card->cla = 0x00;
  423|       |
  424|       |	/* select application "OpenPGP" */
  425|    654|	sc_format_path("D276:0001:2401", &path);
  426|    654|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    654|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  427|    654|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (427:6): [True: 14, False: 640]
  ------------------
  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|    640|	if (!file)   {
  ------------------
  |  Branch (434:6): [True: 0, False: 640]
  ------------------
  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|    640|	if (file->namelen != 16) {
  ------------------
  |  Branch (439:6): [True: 639, False: 1]
  ------------------
  440|       |		/* explicitly get the full aid */
  441|    639|		r = get_full_pgp_aid(card, file);
  442|    639|		if (r < 0) {
  ------------------
  |  Branch (442:7): [True: 7, False: 632]
  ------------------
  443|      7|			sc_file_free(file);
  444|      7|			pgp_finish(card);
  445|      7|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|      7|		}
  447|    639|	}
  448|       |
  449|       |	/* read information from AID */
  450|    633|	if (file->namelen == 16) {
  ------------------
  |  Branch (450:6): [True: 440, False: 193]
  ------------------
  451|    440|		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|    440|		priv->bcd_version = bebytes2ushort(file->name + 6);
  455|    440|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    440|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  456|    440|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    440|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  457|       |
  458|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  459|    440|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (459:7): [True: 2, False: 438]
  ------------------
  460|    438|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (460:7): [True: 2, False: 436]
  ------------------
  461|    436|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (461:7): [True: 4, False: 432]
  ------------------
  462|      8|			snprintf(card_name, sizeof(card_name),
  463|      8|				 "OpenPGP card v%u.%u (%04X %08lX)",
  464|      8|				 card->version.hw_major, card->version.hw_minor,
  465|      8|				 bebytes2ushort(file->name + 8),
  466|      8|				 bebytes2ulong(file->name + 10));
  467|      8|		}
  468|    432|		else if (card->name != NULL) {
  ------------------
  |  Branch (468:12): [True: 432, False: 0]
  ------------------
  469|       |			/* for other cards, append serial number to the card name */
  470|    432|			snprintf(card_name, sizeof(card_name),
  471|    432|				 "%s (%04X %08lX)",
  472|    432|				 card->name,
  473|    432|				 bebytes2ushort(file->name + 8),
  474|    432|				 bebytes2ulong(file->name + 10));
  475|    432|		}
  476|    440|		card->name = card_name;
  477|       |
  478|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  479|    440|		memcpy(card->serialnr.value, file->name + 8, 6);
  480|    440|		card->serialnr.len = 6;
  481|    440|	} else {
  482|       |		/* set detailed card version */
  483|    193|		switch (card->type) {
  484|      4|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (484:4): [True: 4, False: 189]
  ------------------
  485|      4|				priv->bcd_version = OPENPGP_CARD_3_0;
  486|      4|				break;
  487|      1|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (487:4): [True: 1, False: 192]
  ------------------
  488|      3|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (488:4): [True: 2, False: 191]
  ------------------
  489|      3|				priv->bcd_version = OPENPGP_CARD_2_0;
  490|      3|				break;
  491|    186|			default:
  ------------------
  |  Branch (491:4): [True: 186, False: 7]
  ------------------
  492|    186|				priv->bcd_version = OPENPGP_CARD_1_1;
  493|    186|				break;
  494|    193|		}
  495|    193|	}
  496|       |
  497|       |	/* set pointer to correct list of card objects */
  498|    633|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (498:22): [True: 223, False: 410]
  ------------------
  499|    633|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (499:8): [True: 6, False: 404]
  ------------------
  500|    410|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (500:8): [True: 21, False: 383]
  ------------------
  501|    404|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (501:8): [True: 5, False: 378]
  ------------------
  502|    383|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (502:8): [True: 1, False: 377]
  ------------------
  503|    378|			  :					     pgp34_objects;
  504|       |
  505|       |	/* With gnuk, we use different curves */
  506|    633|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (506:6): [True: 7, False: 626]
  ------------------
  507|      7|		priv->ec_curves = ec_curves_gnuk;
  508|    626|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (508:13): [True: 375, False: 251]
  ------------------
  509|    375|		priv->ec_curves = ec_curves_openpgp34;
  510|    375|	} else {
  511|    251|		priv->ec_curves = ec_curves_openpgp;
  512|    251|	}
  513|       |
  514|       |	/* change file path to MF for reuse in MF */
  515|    633|	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|    633|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  520|    633|	if (!priv->mf) {
  ------------------
  |  Branch (520:6): [True: 0, False: 633]
  ------------------
  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|    633|	priv->current = priv->mf;
  528|       |
  529|    633|	r = populate_blobs_to_mf(card, priv);
  530|    633|	if (r < 0) {
  ------------------
  |  Branch (530:6): [True: 0, False: 633]
  ------------------
  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|    633|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (536:6): [True: 47, False: 586]
  ------------------
  537|     47|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     47|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     47|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     47|	int _ret = r; \
  |  |  |  |  155|     47|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  157|     47|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     47|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     47|	return _ret; \
  |  |  |  |  163|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|     47|	}
  539|       |
  540|       |	/* if algorithm attributes can be changed,
  541|       |	 * add supported algorithms based on specification for pkcs15-init */
  542|    586|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (542:6): [True: 35, False: 551]
  ------------------
  543|     35|		unsigned long flags_rsa, flags_ecc, ext_flags;
  544|     35|		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|     35|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  111|     35|#define SC_ALGORITHM_RSA_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|#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|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  548|     35|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  133|     35|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  549|     35|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     35|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     35|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|     35|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  551|     35|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|     35|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  552|     35|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|     35|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     35|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  553|     35|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     35|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|     35|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|     35|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  555|       |
  556|     35|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  188|     35|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  557|     35|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     35|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  558|       |		/* xeddsa may allow signing at some time */
  559|     35|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  173|     35|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  560|     35|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     35|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  561|       |
  562|     35|		switch (card->type) {
  563|      4|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (563:4): [True: 4, False: 31]
  ------------------
  564|       |				/* RSA 1024 was removed for v3+ */
  565|      4|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  566|      4|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  567|       |				/* fallthrough */
  568|      4|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (568:4): [True: 0, False: 35]
  ------------------
  569|      4|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  570|     52|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (570:15): [True: 48, False: 4]
  ------------------
  571|     48|				{
  572|     48|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   70|     48|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (572:10): [True: 36, False: 12]
  ------------------
  573|     36|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  574|     36|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  575|     12|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|     12|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (575:15): [True: 6, False: 6]
  ------------------
  576|      6|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  577|      6|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  578|      6|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|      6|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (578:15): [True: 6, False: 0]
  ------------------
  579|      6|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  580|      6|								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|     48|				}
  584|      4|				break;
  585|      4|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (585:4): [True: 1, False: 34]
  ------------------
  586|     31|			default:
  ------------------
  |  Branch (586:4): [True: 30, False: 5]
  ------------------
  587|     31|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  588|     31|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  589|     31|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  590|     31|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  591|     31|				break;
  592|     35|		}
  593|     35|	}
  594|       |
  595|    586|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 586]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|    586|}
card-openpgp.c:pgp_get_blob:
 1480|  5.29k|{
 1481|  5.29k|	pgp_blob_t		*child;
 1482|  5.29k|	int			r;
 1483|       |
 1484|  5.29k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1484:6): [True: 1.11k, False: 4.17k]
  ------------------
 1485|  1.11k|		return r;
 1486|       |
 1487|  46.6k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1487:28): [True: 44.8k, False: 1.82k]
  ------------------
 1488|  44.8k|		if (child->id == id) {
  ------------------
  |  Branch (1488:7): [True: 2.35k, False: 42.4k]
  ------------------
 1489|  2.35k|			(void) pgp_read_blob(card, child);
 1490|  2.35k|			*ret = child;
 1491|  2.35k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.35k|#define SC_SUCCESS				0
  ------------------
 1492|  2.35k|		}
 1493|  44.8k|	}
 1494|       |
 1495|       |	/* This part is for "NOT FOUND" cases */
 1496|       |
 1497|       |	/* Special case:
 1498|       |	 * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
 1499|       |	 * So, if these blob was not found, we create it. */
 1500|  1.82k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  3.64k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|     70|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|     70|#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: 35, False: 1.78k]
  |  Branch (1500:36): [True: 0, False: 35]
  |  Branch (1500:53): [True: 35, False: 0]
  |  Branch (1500:75): [True: 0, False: 0]
  ------------------
 1501|     35|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1502|     35|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1503|     35|		if (child) {
  ------------------
  |  Branch (1503:7): [True: 35, False: 0]
  ------------------
 1504|     35|			pgp_set_blob(child, NULL, 0);
 1505|     35|			*ret = child;
 1506|     35|			return SC_SUCCESS;
  ------------------
  |  |   28|     35|#define SC_SUCCESS				0
  ------------------
 1507|     35|		}
 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|     35|			       "Not enough memory to create blob for DO %X",
 1511|     35|			       id);
 1512|     35|	}
 1513|       |
 1514|  1.78k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.78k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1515|  1.82k|}
card-openpgp.c:pgp_enumerate_blob:
 1398|  5.67k|{
 1399|  5.67k|	const u8	*in;
 1400|  5.67k|	int		r;
 1401|  5.67k|	sc_file_t	*file = NULL;
 1402|       |
 1403|  5.67k|	if (blob->files != NULL)
  ------------------
  |  Branch (1403:6): [True: 3.86k, False: 1.81k]
  ------------------
 1404|  3.86k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.86k|#define SC_SUCCESS				0
  ------------------
 1405|       |
 1406|  1.81k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1406:6): [True: 1.04k, False: 762]
  ------------------
 1407|  1.04k|		return r;
 1408|       |
 1409|    762|	in = blob->data;
 1410|       |
 1411|  26.4k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1411:9): [True: 26.0k, False: 401]
  ------------------
 1412|  26.0k|		unsigned int	cla, tag, tmptag;
 1413|  26.0k|		size_t		len;
 1414|  26.0k|		const u8	*data = in;
 1415|  26.0k|		pgp_blob_t	*new;
 1416|       |
 1417|  26.0k|		if (!in)
  ------------------
  |  Branch (1417:7): [True: 0, False: 26.0k]
  ------------------
 1418|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1419|       |
 1420|  26.0k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1421|  26.0k|					&cla, &tag, &len);
 1422|  26.0k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  26.0k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1422:7): [True: 140, False: 25.8k]
  ------------------
 1423|    140|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1424|    140|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    140|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1425|    140|		}
 1426|       |		/* Check for unknown error, or empty data */
 1427|  25.8k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    304|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1427:8): [True: 304, False: 25.5k]
  |  Branch (1427:19): [True: 0, False: 304]
  ------------------
 1428|  25.8k|		    (data == NULL)) {
  ------------------
  |  Branch (1428:7): [True: 115, False: 25.7k]
  ------------------
 1429|    115|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1430|    115|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    115|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1431|    115|		}
 1432|       |
 1433|       |		/* undo ASN1's split of tag & class */
 1434|  26.8k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1434:22): [True: 1.08k, False: 25.7k]
  ------------------
 1435|  1.08k|			cla <<= 8;
 1436|  1.08k|		}
 1437|  25.7k|		tag |= cla;
 1438|       |		/* Check for length mismatch */
 1439|  25.7k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  25.7k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1439:7): [True: 304, False: 25.4k]
  ------------------
 1440|  25.4k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1440:7): [True: 0, False: 25.4k]
  ------------------
 1441|       |			// Check if it is not known Yubikey 5 issue
 1442|    304|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1442:8): [True: 95, False: 209]
  |  Branch (1442:29): [True: 11, False: 198]
  ------------------
 1443|    106|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1444|    106|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    106|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1445|    106|			}
 1446|    304|		}
 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|  25.6k|		if (tag == blob->id) {
  ------------------
  |  Branch (1451:7): [True: 456, False: 25.2k]
  ------------------
 1452|    456|			in = data;
 1453|    456|			continue;
 1454|    456|		}
 1455|       |
 1456|       |		/* create fake file system hierarchy by
 1457|       |		 * using constructed DOs as DF */
 1458|  25.2k|		file = sc_file_new();
 1459|  25.2k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1459:7): [True: 0, False: 25.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|  25.2k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  25.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1463:7): [True: 0, False: 25.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|  25.2k|		in = data + len;
 1468|  25.2k|	}
 1469|       |
 1470|    401|	return SC_SUCCESS;
  ------------------
  |  |   28|    401|#define SC_SUCCESS				0
  ------------------
 1471|    762|}
card-openpgp.c:pgp_set_blob:
 1140|  25.9k|{
 1141|  25.9k|	if (blob->data)
  ------------------
  |  Branch (1141:6): [True: 0, False: 25.9k]
  ------------------
 1142|      0|		free(blob->data);
 1143|  25.9k|	blob->data = NULL;
 1144|  25.9k|	blob->len    = 0;
 1145|  25.9k|	blob->status = 0;
 1146|       |
 1147|  25.9k|	if (len > 0) {
  ------------------
  |  Branch (1147:6): [True: 11.2k, False: 14.7k]
  ------------------
 1148|  11.2k|		void *tmp = calloc(1, len);
 1149|       |
 1150|  11.2k|		if (tmp == NULL)
  ------------------
  |  Branch (1150:7): [True: 0, False: 11.2k]
  ------------------
 1151|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|       |
 1153|  11.2k|		blob->data = tmp;
 1154|  11.2k|		blob->len  = (unsigned int)len;
 1155|  11.2k|		if (data != NULL)
  ------------------
  |  Branch (1155:7): [True: 11.2k, False: 0]
  ------------------
 1156|  11.2k|			memcpy(blob->data, data, len);
 1157|  11.2k|	}
 1158|       |
 1159|  25.9k|	if (blob->file)
  ------------------
  |  Branch (1159:6): [True: 25.9k, False: 0]
  ------------------
 1160|  25.9k|		blob->file->size = len;
 1161|       |
 1162|  25.9k|	return SC_SUCCESS;
  ------------------
  |  |   28|  25.9k|#define SC_SUCCESS				0
  ------------------
 1163|  25.9k|}
card-openpgp.c:pgp_read_blob:
 1348|  4.17k|{
 1349|  4.17k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  4.17k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1350|       |
 1351|  4.17k|	if (blob->data != NULL)
  ------------------
  |  Branch (1351:6): [True: 896, False: 3.28k]
  ------------------
 1352|    896|		return SC_SUCCESS;
  ------------------
  |  |   28|    896|#define SC_SUCCESS				0
  ------------------
 1353|  3.28k|	if (blob->info == NULL)
  ------------------
  |  Branch (1353:6): [True: 3, False: 3.27k]
  ------------------
 1354|      3|		return blob->status;
 1355|       |
 1356|  3.27k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1356:6): [True: 3.22k, False: 52]
  ------------------
 1357|  3.22k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1358|  3.22k|		size_t	buf_len = sizeof(buffer);
 1359|  3.22k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.22k|#define SC_SUCCESS				0
  ------------------
 1360|       |
 1361|       |		/* buffer length for certificate */
 1362|  3.22k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  6.45k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1362:7): [True: 0, False: 3.22k]
  |  Branch (1362:30): [True: 0, False: 0]
  ------------------
 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.22k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1367:7): [True: 31, False: 3.19k]
  ------------------
 1368|     31|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|     62|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1368:8): [True: 0, False: 31]
  ------------------
 1369|     31|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|     62|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1369:8): [True: 0, False: 31]
  ------------------
 1370|     31|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|     62|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1370:8): [True: 0, False: 31]
  ------------------
 1371|     31|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|     62|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1371:8): [True: 0, False: 31]
  ------------------
 1372|     31|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|     62|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1372:8): [True: 0, False: 31]
  ------------------
 1373|     31|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|     31|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1373:8): [True: 0, False: 31]
  ------------------
 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.22k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1378|       |
 1379|  3.22k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1379:7): [True: 2.49k, False: 733]
  ------------------
 1380|  2.49k|			blob->status = r;
 1381|  2.49k|			return r;
 1382|  2.49k|		}
 1383|       |
 1384|    733|		return pgp_set_blob(blob, buffer, r);
 1385|  3.22k|	}
 1386|     52|	else {		/* un-readable DO or part of a constructed DO */
 1387|     52|		return SC_SUCCESS;
  ------------------
  |  |   28|     52|#define SC_SUCCESS				0
  ------------------
 1388|     52|	}
 1389|  3.27k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  634|  10.3k|{
  635|  10.3k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  10.3k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  636|  10.3k|	struct sc_object_id oid;
  637|  10.3k|	unsigned int j, r;
  638|       |
  639|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |
  641|  10.3k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (641:6): [True: 0, False: 10.3k]
  |  Branch (641:22): [True: 2.58k, False: 7.75k]
  |  Branch (641:44): [True: 0, False: 7.75k]
  ------------------
  642|  7.75k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 7.75k]
  |  Branch (642:27): [True: 0, False: 7.75k]
  |  Branch (642:48): [True: 0, False: 7.75k]
  ------------------
  643|  2.58k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  2.58k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.58k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.58k|	int _ret = r; \
  |  |  |  |  155|  2.58k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.58k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.58k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.58k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.58k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.58k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.58k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.58k|	return _ret; \
  |  |  |  |  163|  2.58k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|  2.58k|	}
  645|       |
  646|  7.75k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  647|       |
  648|  7.75k|	switch (blob->data[0]) {
  649|    975|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  870|    975|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (649:3): [True: 975, False: 6.77k]
  ------------------
  650|    975|			if (blob->len < 5) {
  ------------------
  |  Branch (650:8): [True: 254, False: 721]
  ------------------
  651|    254|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  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|    254|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 254, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|    254|			}
  653|       |
  654|    721|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  870|    721|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  655|    721|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  656|    721|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  657|       |
  658|    721|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (658:32): [True: 228, False: 493]
  ------------------
  659|    721|						  ? blob->data[5]
  660|    721|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  875|  1.21k|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  661|    721|			break;
  662|    529|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  871|    529|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (662:3): [True: 529, False: 7.22k]
  ------------------
  663|  5.45k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  872|  5.45k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (663:3): [True: 4.92k, False: 2.83k]
  ------------------
  664|  6.03k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  873|  6.03k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (664:3): [True: 580, False: 7.17k]
  ------------------
  665|       |
  666|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  667|  6.03k|			key_info->algorithm = blob->data[0];
  668|       |
  669|       |			/* last byte is set to 0xFF if pubkey import is supported */
  670|  6.03k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  881|  6.03k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (670:8): [True: 1.99k, False: 4.04k]
  ------------------
  671|  1.99k|				if (blob->len < 3)
  ------------------
  |  Branch (671:9): [True: 203, False: 1.78k]
  ------------------
  672|    203|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    203|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  673|  1.78k|				key_info->u.ec.oidv_len = blob->len - 2;
  674|  1.78k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  881|  1.78k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  675|  1.78k|			}
  676|  4.04k|			else {
  677|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  678|       |				 * it is not part of OID */
  679|  4.04k|				if (blob->len < 2)
  ------------------
  |  Branch (679:9): [True: 205, False: 3.83k]
  ------------------
  680|    205|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    205|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  681|  3.83k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  880|  3.83k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (681:9): [True: 702, False: 3.13k]
  ------------------
  682|    702|					key_info->u.ec.oidv_len = blob->len - 2;
  683|  3.13k|				else
  684|  3.13k|					key_info->u.ec.oidv_len = blob->len - 1;
  685|  3.83k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  880|  3.83k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  686|  3.83k|			}
  687|       |
  688|       |			/* Create copy of oid from blob */
  689|  5.62k|			sc_init_oid(&oid);
  690|  5.62k|			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.62k|			if (r > 0){
  ------------------
  |  Branch (693:8): [True: 3.37k, False: 2.24k]
  ------------------
  694|  3.37k|				return r;
  695|  3.37k|			}
  696|       |			/* compare with list of supported ec_curves */
  697|  31.4k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (697:16): [True: 29.2k, False: 2.24k]
  ------------------
  698|  29.2k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (698:9): [True: 0, False: 29.2k]
  ------------------
  699|      0|					sc_log(card->ctx, "Matched EC oid %s (%d)",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  700|      0|						sc_dump_oid(&oid), j);
  701|      0|					key_info->u.ec.oid = priv->ec_curves[j].oid;
  702|      0|					key_info->u.ec.key_length = priv->ec_curves[j].size;
  703|      0|					break;
  704|      0|				}
  705|  29.2k|			}
  706|       |			/* We did not match the OID */
  707|  2.24k|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (707:8): [True: 2.24k, False: 0]
  ------------------
  708|  2.24k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  2.24k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.24k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.24k|	int _ret = r; \
  |  |  |  |  155|  2.24k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.24k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.24k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.24k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.24k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.24k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.24k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.24k|	return _ret; \
  |  |  |  |  163|  2.24k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  2.24k|			}
  710|      0|			break;
  711|    747|		default:
  ------------------
  |  Branch (711:3): [True: 747, False: 7.00k]
  ------------------
  712|    747|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    747|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    747|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    747|	int _ret = r; \
  |  |  |  |  155|    747|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 747, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    747|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    747|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 747, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    747|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    747|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    747|	return _ret; \
  |  |  |  |  163|    747|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  713|  7.75k|	}
  714|       |
  715|    721|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    721|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    721|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    721|	int _ret = r; \
  |  |  |  |  155|    721|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 721, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    721|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 721]
  |  |  |  |  ------------------
  |  |  |  |  157|    721|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    721|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    721|	return _ret; \
  |  |  |  |  163|    721|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|    721|}
card-openpgp.c:pgp_get_card_features:
  909|    633|{
  910|    633|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    633|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  911|    633|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  912|    633|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  913|    633|	unsigned int i;
  914|    633|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  915|    633|	int handled_algos = 0;
  916|       |
  917|    633|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    633|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    633|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    633|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    633|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 633]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  918|       |
  919|       |	/* parse card capabilities from historical bytes in ATR */
  920|    633|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (920:6): [True: 141, False: 492]
  ------------------
  921|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  922|    141|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (922:11): [True: 72, False: 69]
  ------------------
  923|     51|			case 0x00:
  ------------------
  |  Branch (923:4): [True: 51, False: 90]
  ------------------
  924|     51|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (924:9): [True: 25, False: 26]
  ------------------
  925|     25|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  926|     25|				}
  927|     51|				break;
  928|     18|			case 0x80:
  ------------------
  |  Branch (928:4): [True: 18, False: 123]
  ------------------
  929|     18|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (929:9): [True: 17, False: 1]
  ------------------
  930|     17|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  931|     17|				}
  932|     18|				break;
  933|      3|			case 0x10:
  ------------------
  |  Branch (933:4): [True: 3, False: 138]
  ------------------
  934|      3|				if (hist_bytes_len > 2) {
  ------------------
  |  Branch (934:9): [True: 2, False: 1]
  ------------------
  935|      2|					pgp_parse_hist_bytes(card, hist_bytes+2, hist_bytes_len-2);
  936|      2|				}
  937|      3|				break;
  938|    141|		}
  939|    141|	}
  940|       |
  941|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  942|    633|	priv->ext_caps &= ~EXT_CAP_LCS;
  943|       |
  944|    633|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (944:6): [True: 410, False: 223]
  ------------------
  945|       |		/* get card capabilities from "historical bytes" DO */
  946|    410|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (946:7): [True: 410, False: 0]
  ------------------
  947|    410|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (947:7): [True: 52, False: 358]
  |  Branch (947:31): [True: 48, False: 4]
  ------------------
  948|       |
  949|     48|			if (blob->len > 4) {
  ------------------
  |  Branch (949:8): [True: 36, False: 12]
  ------------------
  950|     36|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  951|     36|			}
  952|       |
  953|       |			/* get card status from historical bytes status indicator */
  954|     48|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (954:8): [True: 48, False: 0]
  |  Branch (954:35): [True: 37, False: 11]
  ------------------
  955|     37|				priv->state = blob->data[blob->len-3];
  956|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  957|     37|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (957:9): [True: 27, False: 10]
  ------------------
  958|     27|					priv->ext_caps |= EXT_CAP_LCS;
  959|     37|			}
  960|     48|		}
  961|    410|	}
  962|       |
  963|    633|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (963:6): [True: 378, False: 255]
  ------------------
  964|    378|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    378|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  965|    378|	}
  966|       |
  967|    633|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (967:6): [True: 377, False: 256]
  ------------------
  968|       |		/* Parse supported algorithms from Algorithm Information DO
  969|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  970|    377|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (970:7): [True: 377, False: 0]
  ------------------
  971|    377|			pgp_blob_t *child;
  972|    377|			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|  18.2k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (975:32): [True: 17.8k, False: 377]
  ------------------
  976|  17.8k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (976:9): [True: 5.55k, False: 12.3k]
  |  Branch (976:33): [True: 1.99k, False: 10.3k]
  ------------------
  977|  7.55k|					continue;
  978|  10.3k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  979|  10.3k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (979:9): [True: 718, False: 9.60k]
  ------------------
  980|    718|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  981|  10.3k|			}
  982|    377|		}
  983|    377|	}
  984|       |
  985|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  986|    633|	priv->max_specialDO_size = 254;
  987|       |
  988|    633|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (988:6): [True: 633, False: 0]
  ------------------
  989|    633|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (989:6): [True: 100, False: 533]
  ------------------
  990|       |
  991|       |		/* get "extended capabilities" DO */
  992|    100|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (992:7): [True: 64, False: 36]
  ------------------
  993|     64|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (993:7): [True: 63, False: 1]
  |  Branch (993:31): [True: 63, False: 0]
  ------------------
  994|     63|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (994:8): [True: 40, False: 23]
  |  Branch (994:34): [True: 32, False: 8]
  ------------------
  995|     32|				priv->ext_caps |= EXT_CAP_KDF_DO;
  996|     32|			}
  997|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  998|     63|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (998:8): [True: 50, False: 13]
  ------------------
  999|     50|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (999:6): [True: 35, False: 15]
  ------------------
 1000|     35|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
 1001|       |			/* bit 0x08 in first byte means "support for private use DOs" */
 1002|     63|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (1002:8): [True: 33, False: 30]
  ------------------
 1003|     33|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1004|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1005|     63|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1005:8): [True: 29, False: 34]
  ------------------
 1006|     29|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1007|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1008|     63|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1008:8): [True: 36, False: 27]
  ------------------
 1009|     36|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1010|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1011|     63|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1011:8): [True: 33, False: 30]
  ------------------
 1012|     33|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     33|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1013|     33|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1014|     33|			}
 1015|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1016|     63|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1016:8): [True: 33, False: 30]
  ------------------
 1017|     33|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1017:6): [True: 18, False: 15]
  ------------------
 1018|     18|				priv->ext_caps |= EXT_CAP_SM;
 1019|       |
 1020|     63|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1020:8): [True: 45, False: 18]
  |  Branch (1020:51): [True: 18, False: 27]
  ------------------
 1021|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1022|     18|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1023|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1024|     18|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1025|       |
 1026|     18|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1026:9): [True: 7, False: 11]
  ------------------
 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: 4, False: 3]
  |  Branch (1029:45): [True: 1, False: 3]
  ------------------
 1030|      1|						priv->sm_algo = SM_ALGO_3DES;
 1031|       |
 1032|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1033|      7|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1034|      7|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1035|      7|				}
 1036|     11|				else {
 1037|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1038|     11|					priv->sm_algo = blob->data[1];
 1039|     11|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1039:10): [True: 4, False: 7]
  |  Branch (1039:45): [True: 2, False: 2]
  ------------------
 1040|      2|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1041|       |
 1042|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1043|     11|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1044|     11|				}
 1045|     18|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1045:9): [True: 11, False: 7]
  |  Branch (1045:50): [True: 11, False: 0]
  ------------------
 1046|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1047|     11|					if (blob->data[9])
  ------------------
  |  Branch (1047:10): [True: 9, False: 2]
  ------------------
 1048|      9|						priv->ext_caps |= EXT_CAP_MSE;
 1049|     11|				}
 1050|     18|			}
 1051|     63|		}
 1052|       |
 1053|       |		/* get max. PIN length from "CHV status bytes" DO */
 1054|    100|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1054:7): [True: 17, False: 83]
  ------------------
 1055|     17|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1055:4): [True: 6, False: 11]
  |  Branch (1055:28): [True: 5, False: 1]
  ------------------
 1056|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1057|      5|			card->max_pin_len = blob->data[1];
 1058|      5|		}
 1059|       |
 1060|    100|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1060:7): [True: 54, False: 46]
  ------------------
 1061|       |			/* v3.0+: get length info from "extended length information" DO */
 1062|     54|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1062:8): [True: 0, False: 54]
  ------------------
 1063|      0|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1063:5): [True: 0, False: 0]
  |  Branch (1063:29): [True: 0, False: 0]
  ------------------
 1064|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1065|      0|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1066|      0|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1067|      0|			}
 1068|     54|		}
 1069|       |
 1070|    100|#ifdef ENABLE_OPENSSL
 1071|    100|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1071:7): [True: 32, False: 68]
  ------------------
 1072|     32|			int r = pgp_decode_kdf_do(card, priv);
 1073|     32|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     32|#define SC_SUCCESS				0
  ------------------
  |  Branch (1073:8): [True: 29, False: 3]
  ------------------
 1074|     29|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1075|     29|			}
 1076|     32|		}
 1077|    100|#endif /* ENABLE_OPENSSL */
 1078|       |
 1079|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1080|    100|		if (handled_algos) {
  ------------------
  |  Branch (1080:7): [True: 1, False: 99]
  ------------------
 1081|      1|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1082|      1|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1083|      1|		}
 1084|       |
 1085|       |		/* get _current_ algorithms & key lengths from "algorithm attributes" DOs
 1086|       |		 *
 1087|       |		 * All available algorithms should be already provided by pgp_init. However, if another
 1088|       |		 * algorithm is found in the "algorithm attributes" DOs, it is supported by the card as
 1089|       |		 * well and therefore added
 1090|       |		 * see OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1091|    396|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1091:20): [True: 297, False: 99]
  ------------------
 1092|    297|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1093|       |
 1094|    297|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1095|       |
 1096|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1097|    297|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1097:8): [True: 16, False: 281]
  ------------------
 1098|     16|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1098:8): [True: 3, False: 13]
  ------------------
 1099|      3|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1099:9): [True: 0, False: 3]
  ------------------
 1100|      3|					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|      3|			}
 1102|    297|		}
 1103|       |
 1104|     99|	}
 1105|       |
 1106|    632|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    632|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    632|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    632|	int _ret = r; \
  |  |  |  |  155|    632|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 586, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 586]
  |  |  |  |  ------------------
  |  |  |  |  157|    586|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    586|	} else { \
  |  |  |  |  159|     46|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     46|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     46|	} \
  |  |  |  |  162|    632|	return _ret; \
  |  |  |  |  163|    632|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|    632|}
card-openpgp.c:pgp_parse_hist_bytes:
  604|     80|{
  605|     80|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     80|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  606|     80|	const u8 *ptr;
  607|       |
  608|       |	/* IS07816-4 hist bytes: 3rd function table */
  609|     80|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (609:6): [True: 28, False: 52]
  ------------------
  610|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  611|     28|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (611:7): [True: 15, False: 13]
  ------------------
  612|     15|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     15|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  613|     15|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  614|     15|		}
  615|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  616|     28|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (616:7): [True: 19, False: 9]
  ------------------
  617|     19|			priv->ext_caps |= EXT_CAP_CHAINING;
  618|     19|		}
  619|     28|	}
  620|       |
  621|     80|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (621:6): [True: 53, False: 27]
  ------------------
  622|     53|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (622:6): [True: 17, False: 36]
  ------------------
  623|       |		// ToDo ...
  624|     17|	}
  625|     80|}
card-openpgp.c:pgp_decode_kdf_do:
  805|     32|{
  806|     32|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  807|     32|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     32|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  808|     32|	pgp_blob_t *kdf_blob;
  809|     32|	const uint8_t *data;
  810|     32|	size_t data_len;
  811|     32|	size_t tag_len;
  812|     32|	const uint8_t *p;
  813|     32|	pgp_blob_t *blob;
  814|       |
  815|     32|	if (!pin_kdf_info) {
  ------------------
  |  Branch (815:6): [True: 0, False: 32]
  ------------------
  816|      0|		return r;
  817|      0|	}
  818|       |
  819|     32|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     32|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  820|     32|	priv->pin_kdf_info = NULL;
  821|     32|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     32|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     32|#define SC_SUCCESS				0
  ------------------
  |  Branch (821:6): [True: 0, False: 32]
  |  Branch (821:73): [True: 12, False: 20]
  ------------------
  822|     12|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  823|     12|		goto out;
  824|     12|	}
  825|       |
  826|     20|	data = kdf_blob->data;
  827|     20|	data_len = kdf_blob->len;
  828|     20|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  829|     20|	if (!p) {
  ------------------
  |  Branch (829:6): [True: 1, False: 19]
  ------------------
  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|     19|	if (tag_len != 1) {
  ------------------
  |  Branch (833:6): [True: 3, False: 16]
  ------------------
  834|      3|		sc_log(card->ctx, "Unexpected KDF algorithm byte length, expects 1, got %zu", tag_len);
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  835|      3|		goto out;
  836|      3|	}
  837|       |
  838|     16|	if (*p != 0x3) {
  ------------------
  |  Branch (838:6): [True: 4, False: 12]
  ------------------
  839|      4|		if (*p == 0x0) {
  ------------------
  |  Branch (839:7): [True: 1, False: 3]
  ------------------
  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|      3|		} else {
  843|      3|			sc_log(card->ctx, "Unknown KDF algorithm ID %x", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  844|      3|		}
  845|      4|		goto out;
  846|      4|	}
  847|       |
  848|     12|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  849|     12|	if (!p) {
  ------------------
  |  Branch (849:6): [True: 2, False: 10]
  ------------------
  850|      2|		sc_log(card->ctx, "KDF hash algorithm byte not found");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  851|      2|		goto out;
  852|      2|	}
  853|     10|	if (tag_len != 1) {
  ------------------
  |  Branch (853:6): [True: 1, False: 9]
  ------------------
  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|      9|	switch (*p) {
  859|      7|	case 0x08:
  ------------------
  |  Branch (859:2): [True: 7, False: 2]
  ------------------
  860|      7|		pin_kdf_info->hash_algo = "SHA256";
  861|      7|		break;
  862|      1|	case 0x0A:
  ------------------
  |  Branch (862:2): [True: 1, False: 8]
  ------------------
  863|      1|		pin_kdf_info->hash_algo = "SHA512";
  864|      1|		break;
  865|      1|	default:
  ------------------
  |  Branch (865:2): [True: 1, False: 8]
  ------------------
  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|      9|	}
  869|       |
  870|      8|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  871|      8|	if (!p) {
  ------------------
  |  Branch (871:6): [True: 2, False: 6]
  ------------------
  872|      2|		sc_log(card->ctx, "KDF iteration count not found");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  873|      2|		goto out;
  874|      2|	}
  875|      6|	if (tag_len != 4) {
  ------------------
  |  Branch (875:6): [True: 1, False: 5]
  ------------------
  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|      5|	pin_kdf_info->iterations = (uint32_t)bebytes2ulong(p);
  880|       |
  881|      5|	r = pgp_get_blob(card, kdf_blob, 0x84, &blob);
  882|      5|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
  |  Branch (882:6): [True: 2, False: 3]
  ------------------
  883|      2|		sc_log(card->ctx, "Failed to get salt bytes of user password");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  884|      2|		goto out;
  885|      2|	}
  886|      3|	pin_kdf_info->userpw_salt = blob;
  887|       |
  888|      3|	r = pgp_get_blob(card, kdf_blob, 0x86, &blob);
  889|      3|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (889:6): [True: 1, False: 2]
  ------------------
  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|      2|	pin_kdf_info->adminpw_salt = blob;
  894|       |
  895|      2|	sc_log(card->ctx, "KDF derived PIN format enabled");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  896|      2|	priv->pin_kdf_info = pin_kdf_info;
  897|      2|	return r;
  898|     30|out:
  899|     30|	free(pin_kdf_info);
  900|     30|	return r;
  901|      3|}
card-openpgp.c:pgp_finish:
 1115|    654|{
 1116|    654|	if (card != NULL) {
  ------------------
  |  Branch (1116:6): [True: 654, False: 0]
  ------------------
 1117|    654|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    654|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1118|       |
 1119|    654|		if (priv != NULL) {
  ------------------
  |  Branch (1119:7): [True: 654, False: 0]
  ------------------
 1120|       |			/* delete fake file hierarchy */
 1121|    654|			pgp_free_blobs(priv->mf);
 1122|       |
 1123|       |			/* delete kdf do related data if exists */
 1124|    654|			free(priv->pin_kdf_info);
 1125|       |
 1126|       |			/* delete private data */
 1127|    654|			free(priv);
 1128|    654|		}
 1129|    654|		card->drv_data = NULL;
 1130|    654|	}
 1131|    654|	return SC_SUCCESS;
  ------------------
  |  |   28|    654|#define SC_SUCCESS				0
  ------------------
 1132|    654|}
card-openpgp.c:pgp_free_blobs:
 1328|  37.7k|{
 1329|  37.7k|	if (blob) {
  ------------------
  |  Branch (1329:6): [True: 37.7k, False: 21]
  ------------------
 1330|  37.7k|		pgp_blob_t *child = blob->files;
 1331|       |
 1332|  74.9k|		while (child != NULL) {
  ------------------
  |  Branch (1332:10): [True: 37.1k, False: 37.7k]
  ------------------
 1333|  37.1k|			pgp_blob_t *next = child->next;
 1334|       |
 1335|  37.1k|			pgp_free_blobs(child);
 1336|  37.1k|			child = next;
 1337|  37.1k|		}
 1338|  37.7k|		pgp_free_blob(blob);
 1339|  37.7k|	}
 1340|  37.7k|}
card-openpgp.c:pgp_free_blob:
 1303|  37.7k|{
 1304|  37.7k|	if (blob) {
  ------------------
  |  Branch (1304:6): [True: 37.7k, False: 0]
  ------------------
 1305|  37.7k|		if (blob->parent) {
  ------------------
  |  Branch (1305:7): [True: 37.1k, False: 633]
  ------------------
 1306|  37.1k|			pgp_blob_t **p;
 1307|       |
 1308|       |			/* remove blob from list of parent's children */
 1309|  37.1k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1309:35): [True: 37.1k, False: 0]
  |  Branch (1309:49): [True: 0, False: 37.1k]
  ------------------
 1310|      0|				;
 1311|  37.1k|			if (*p == blob)
  ------------------
  |  Branch (1311:8): [True: 37.1k, False: 0]
  ------------------
 1312|  37.1k|				*p = blob->next;
 1313|  37.1k|		}
 1314|       |
 1315|  37.7k|		sc_file_free(blob->file);
 1316|  37.7k|		if (blob->data)
  ------------------
  |  Branch (1316:7): [True: 11.2k, False: 26.5k]
  ------------------
 1317|  11.2k|			free(blob->data);
 1318|  37.7k|		free(blob);
 1319|  37.7k|	}
 1320|  37.7k|}
card-openpgp.c:pgp_select_file:
 1614|  3.90k|{
 1615|  3.90k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  3.90k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1616|  3.90k|	pgp_blob_t	*blob;
 1617|  3.90k|	unsigned int	path_start = 0;
 1618|  3.90k|	unsigned int	n;
 1619|  3.90k|	sc_path_t dummy_path;
 1620|       |
 1621|  3.90k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.90k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.90k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.90k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.90k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.90k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  3.90k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  3.90k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1623:6): [True: 1.31k, False: 2.59k]
  ------------------
 1624|  3.90k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  164|  1.31k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.31k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.31k|	int _ret = r; \
  |  |  |  |  155|  1.31k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.31k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.20k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.20k, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.31k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.31k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.31k|	return _ret; \
  |  |  |  |  163|  1.31k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1625|       |
 1626|  2.59k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1626:6): [True: 0, False: 2.59k]
  |  Branch (1626:23): [True: 0, False: 2.59k]
  ------------------
 1627|  2.59k|		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|  2.59k|				"invalid path length");
 1629|       |
 1630|  2.59k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  5.18k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1630:6): [True: 0, False: 2.59k]
  |  Branch (1630:44): [True: 0, False: 0]
  ------------------
 1631|  2.59k|		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|  2.59k|				"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|  2.59k|	sc_format_path("11001101", &dummy_path);
 1641|  2.59k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1641:6): [True: 0, False: 2.59k]
  ------------------
 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|  2.59k|	path_start = pgp_strip_path(card, path);
 1653|       |
 1654|       |	/* starting with the MF ... */
 1655|  2.59k|	blob = priv->mf;
 1656|       |	/* ... recurse through the tree following the path */
 1657|  3.32k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1657:23): [True: 2.64k, False: 676]
  ------------------
 1658|  2.64k|		unsigned int	id = bebytes2ushort(path->value + n);
 1659|  2.64k|		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|  2.64k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1663:7): [True: 0, False: 2.64k]
  |  Branch (1663:23): [True: 0, False: 2.64k]
  ------------------
 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|  2.64k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1674:7): [True: 1.91k, False: 735]
  ------------------
 1675|  1.91k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.91k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.91k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.91k|	int _ret = r; \
  |  |  |  |  155|  1.91k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.91k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.91k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.91k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.91k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.91k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.91k|	return _ret; \
  |  |  |  |  163|  1.91k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1676|  1.91k|		}
 1677|  2.64k|	}
 1678|       |
 1679|       |	/* success: select file = set "current" pointer to blob found */
 1680|    676|	priv->current = blob;
 1681|       |
 1682|    676|	if (ret)
  ------------------
  |  Branch (1682:6): [True: 49, False: 627]
  ------------------
 1683|     49|		sc_file_dup(ret, blob->file);
 1684|       |
 1685|    676|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    676|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    676|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    676|	int _ret = r; \
  |  |  |  |  155|    676|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 676, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    676|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 676]
  |  |  |  |  ------------------
  |  |  |  |  157|    676|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    676|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    676|	return _ret; \
  |  |  |  |  163|    676|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1686|    676|}
card-openpgp.c:pgp_strip_path:
 1595|  2.59k|{
 1596|  2.59k|	unsigned int start_point = 0;
 1597|       |	/* start_point will move through the path string */
 1598|  2.59k|	if (path->len == 0)
  ------------------
  |  Branch (1598:6): [True: 0, False: 2.59k]
  ------------------
 1599|      0|		return 0;
 1600|       |
 1601|       |	/* ignore 3F00 (MF) at the beginning */
 1602|  2.59k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1602:16): [True: 1.89k, False: 695]
  ------------------
 1603|       |	/* strip path of PKCS15-App DF (5015) */
 1604|  2.59k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1604:17): [True: 1.26k, False: 1.32k]
  ------------------
 1605|  2.59k|	return start_point;
 1606|  2.59k|}
card-openpgp.c:pgp_get_challenge:
 1731|    230|{
 1732|    230|	struct pgp_priv_data *priv;
 1733|       |
 1734|    230|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    230|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    230|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    230|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    230|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 230]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1735|       |
 1736|    230|	priv = DRVDATA(card);
  ------------------
  |  |  189|    230|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1737|    230|	if (0 == (priv->ext_caps & EXT_CAP_GET_CHALLENGE)) {
  ------------------
  |  Branch (1737:6): [True: 24, False: 206]
  ------------------
 1738|     24|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1739|     24|	}
 1740|       |
 1741|    206|	if (priv->max_challenge_size > 0 && len > priv->max_challenge_size) {
  ------------------
  |  Branch (1741:6): [True: 0, False: 206]
  |  Branch (1741:38): [True: 0, False: 0]
  ------------------
 1742|      0|		len = priv->max_challenge_size;
 1743|      0|	}
 1744|       |
 1745|    206|	LOG_FUNC_RETURN(card->ctx, iso_ops->get_challenge(card, rnd, len));
  ------------------
  |  |  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: 11, False: 195]
  |  |  |  |  ------------------
  |  |  |  |  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|    195|	} else { \
  |  |  |  |  159|    195|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    195|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    195|	} \
  |  |  |  |  162|    206|	return _ret; \
  |  |  |  |  163|    206|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1746|    206|}
card-openpgp.c:pgp_read_binary:
 1755|     14|{
 1756|     14|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     14|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1757|     14|	pgp_blob_t	*blob;
 1758|     14|	int		r;
 1759|       |
 1760|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1761|       |
 1762|       |	/* jump to selected file */
 1763|     14|	blob = priv->current;
 1764|       |
 1765|     14|	if (blob == NULL)
  ------------------
  |  Branch (1765:6): [True: 0, False: 14]
  ------------------
 1766|     14|		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|     14|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|     14|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1768:6): [True: 0, False: 14]
  ------------------
 1769|     14|		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|     14|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1771:6): [True: 0, False: 14]
  ------------------
 1772|     14|		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|     14|	if (idx > blob->len)
  ------------------
  |  Branch (1774:6): [True: 0, False: 14]
  ------------------
 1775|     14|		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|     14|	if (idx + count > blob->len)
  ------------------
  |  Branch (1777:6): [True: 0, False: 14]
  ------------------
 1778|      0|		count = blob->len - idx;
 1779|     14|	memcpy(buf, blob->data + idx, count);
 1780|       |
 1781|     14|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  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: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|     14|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     14|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     14|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|     14|}
card-openpgp.c:pgp_pin_cmd:
 2388|     69|{
 2389|     69|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     69|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2390|     69|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2391|       |
 2392|     69|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     69|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     69|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     69|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     69|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2393|       |
 2394|     69|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|     69|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2394:6): [True: 0, False: 69]
  ------------------
 2395|     69|		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|     69|				"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|     69|	data->pin_reference |= 0x80;
 2423|       |
 2424|       |	/* check version-dependent constraints */
 2425|     69|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  416|    138|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|     64|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2425:6): [True: 5, False: 64]
  |  Branch (2425:40): [True: 0, False: 64]
  ------------------
 2426|      5|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2426:7): [True: 2, False: 3]
  ------------------
 2427|      2|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2427:8): [True: 2, False: 0]
  ------------------
 2428|      2|				data->pin_reference = 0x81;
 2429|       |
 2430|      2|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|      2|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2430:8): [True: 2, False: 0]
  ------------------
 2431|      2|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2431:9): [True: 0, False: 2]
  ------------------
 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|      2|					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|      2|							"v2 cards don't support implicit old PIN for PIN change");
 2435|       |
 2436|      2|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      2|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2437|      2|			}
 2438|      3|		} else {
 2439|      3|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2439:8): [True: 3, False: 0]
  ------------------
 2440|      3|				sc_log(card->ctx,
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2441|      3|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2442|      3|				sc_log(card->ctx,
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2443|      3|				       "please make sure that you have verified the relevant PIN first.");
 2444|      3|				data->pin1.len = 0;
 2445|      3|			}
 2446|       |
 2447|      3|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      3|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2448|      3|		}
 2449|      5|	}
 2450|       |
 2451|     69|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  417|    138|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2451:6): [True: 0, False: 69]
  |  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|     69|		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|     69|				"new PIN must be provided for unblock operation");
 2455|       |
 2456|       |	/* ensure pin_reference is 81, 82, 83 */
 2457|     69|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2457:6): [True: 0, False: 69]
  |  Branch (2457:36): [True: 0, False: 69]
  ------------------
 2458|     69|		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|     69|				"Invalid key ID; must be 1, 2, or 3");
 2460|       |
 2461|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2462|     69|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  418|    138|#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|     59|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2462:6): [True: 59, False: 10]
  |  Branch (2462:42): [True: 24, False: 35]
  ------------------
 2463|     24|		u8 c4data[10];
 2464|     24|		int r;
 2465|       |
 2466|     24|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2467|     24|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes 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: 10, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2468|       |
 2469|     14|		if (r != 7)
  ------------------
  |  Branch (2469:7): [True: 9, False: 5]
  ------------------
 2470|     14|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2471|      5|				"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|      5|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2478:7): [True: 0, False: 5]
  |  Branch (2478:48): [True: 0, False: 0]
  ------------------
 2479|      0|			data->pin_reference = 0x81;
 2480|       |
 2481|      5|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2482|      5|		data->pin1.max_tries = 3;
 2483|      5|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      5|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2484|       |
 2485|      5|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2486|      5|	}
 2487|       |
 2488|     45|#ifdef ENABLE_OPENSSL
 2489|     45|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2489:6): [True: 0, False: 45]
  ------------------
 2490|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2491|      0|	}
 2492|     45|#endif /* ENABLE_OPENSSL */
 2493|       |
 2494|     45|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data));
  ------------------
  |  |  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|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 39, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|     45|}
card-openpgp.c:pgp_get_data:
 1994|  4.52k|{
 1995|  4.52k|	sc_apdu_t	apdu;
 1996|  4.52k|	int		r;
 1997|       |
 1998|  4.52k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  4.52k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.52k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.52k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.52k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.52k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1999|       |
 2000|  4.52k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  4.52k|#define SC_APDU_CASE_2			0x22
  ------------------
 2001|  4.52k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  547|  3.22k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2001:13): [True: 3.22k, False: 1.30k]
  |  Branch (2001:33): [True: 3.15k, False: 68]
  ------------------
 2002|  4.52k|	apdu.resp = buf;
 2003|  4.52k|	apdu.resplen = buf_len;
 2004|       |
 2005|  4.52k|	r = sc_transmit_apdu(card, &apdu);
 2006|  4.52k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  4.52k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.52k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.52k|	int _ret = (r); \
  |  |  |  |  168|  4.52k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 35, False: 4.49k]
  |  |  |  |  ------------------
  |  |  |  |  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|  4.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2007|       |
 2008|  4.49k|	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|  4.49k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2012:6): [True: 38, False: 4.45k]
  ------------------
 2013|     38|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|     76|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2013:7): [True: 0, False: 38]
  ------------------
 2014|     38|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|     76|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2014:7): [True: 0, False: 38]
  ------------------
 2015|     38|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|     76|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2015:7): [True: 0, False: 38]
  ------------------
 2016|     38|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|     76|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2016:7): [True: 0, False: 38]
  ------------------
 2017|     38|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|     38|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2017:7): [True: 0, False: 38]
  ------------------
 2018|      0|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2018:7): [True: 0, False: 0]
  ------------------
 2019|      0|			r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2020|      0|			apdu.resplen = 0;
 2021|      0|		}
 2022|      0|	}
 2023|  4.49k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  4.49k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.49k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.49k|	int _ret = (r); \
  |  |  |  |  168|  4.49k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.01k, False: 1.47k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.01k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.01k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.01k|		return _ret; \
  |  |  |  |  172|  3.01k|	} \
  |  |  |  |  173|  4.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2024|       |
 2025|  1.47k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.47k|	int _ret = r; \
  |  |  |  |  155|  1.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 250, False: 1.22k]
  |  |  |  |  ------------------
  |  |  |  |  156|    250|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 250]
  |  |  |  |  ------------------
  |  |  |  |  157|    250|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.22k|	} else { \
  |  |  |  |  159|  1.22k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.22k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.22k|	} \
  |  |  |  |  162|  1.47k|	return _ret; \
  |  |  |  |  163|  1.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2026|  1.47k|}
card-openpgp.c:pgp_card_ctl:
 4009|    113|{
 4010|    113|	int r;
 4011|       |
 4012|    113|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    113|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    113|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    113|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    113|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 113]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4013|       |
 4014|    113|	switch(cmd) {
  ------------------
  |  Branch (4014:9): [True: 52, False: 61]
  ------------------
 4015|     52|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4015:2): [True: 52, False: 61]
  ------------------
 4016|     52|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4017|     52|		LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4018|      0|		break;
 4019|      0|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4019:2): [True: 0, False: 113]
  ------------------
 4020|      0|		r = pgp_select_data(card, *((u8 *) ptr));
 4021|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4022|      0|		break;
 4023|      0|#ifdef ENABLE_OPENSSL
 4024|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4024:2): [True: 0, False: 113]
  ------------------
 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: 113]
  ------------------
 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: 113]
  ------------------
 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|    113|	}
 4038|       |
 4039|     61|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4040|     61|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4169|  7.93k|{
 4170|  7.93k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  7.93k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4171|  7.93k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  7.93k|#define SC_SUCCESS				0
  ------------------
 4172|       |
 4173|  7.93k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.93k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.93k]
  |  |  ------------------
  ------------------
 4174|       |
 4175|  7.93k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  537|  15.8k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4175:6): [True: 0, False: 7.93k]
  ------------------
 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|  7.93k|	if (was_reset > 0) {
  ------------------
  |  Branch (4190:6): [True: 0, False: 7.93k]
  ------------------
 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|  7.93k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.93k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.93k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.93k|	int _ret = r; \
  |  |  |  |  155|  7.93k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.93k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7.93k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.93k|	return _ret; \
  |  |  |  |  163|  7.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4201|  7.93k|}

sc_get_piv_driver:
 6570|  15.7k|{
 6571|  15.7k|	return sc_get_driver();
 6572|  15.7k|}
card-piv.c:sc_get_driver:
 6543|  15.7k|{
 6544|  15.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6545|       |
 6546|  15.7k|	piv_ops = *iso_drv->ops;
 6547|  15.7k|	piv_ops.match_card = piv_match_card;
 6548|  15.7k|	piv_ops.init = piv_init;
 6549|  15.7k|	piv_ops.finish = piv_finish;
 6550|       |
 6551|  15.7k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6552|  15.7k|	piv_ops.get_challenge = piv_get_challenge;
 6553|  15.7k|	piv_ops.logout = piv_logout;
 6554|  15.7k|	piv_ops.read_binary = piv_read_binary;
 6555|  15.7k|	piv_ops.write_binary = piv_write_binary;
 6556|  15.7k|	piv_ops.set_security_env = piv_set_security_env;
 6557|  15.7k|	piv_ops.restore_security_env = piv_restore_security_env;
 6558|  15.7k|	piv_ops.compute_signature = piv_compute_signature;
 6559|  15.7k|	piv_ops.decipher = piv_decipher;
 6560|  15.7k|	piv_ops.check_sw = piv_check_sw;
 6561|  15.7k|	piv_ops.card_ctl = piv_card_ctl;
 6562|  15.7k|	piv_ops.pin_cmd = piv_pin_cmd;
 6563|  15.7k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6564|       |
 6565|  15.7k|	return &piv_drv;
 6566|  15.7k|}
card-piv.c:piv_match_card:
 5508|  5.71k|{
 5509|  5.71k|	int r = 0;
 5510|       |
 5511|  5.71k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.71k|#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.71k|	switch (card->type) {
 5515|  5.71k|	case -1:
  ------------------
  |  Branch (5515:2): [True: 5.71k, False: 0]
  ------------------
 5516|  5.71k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5516:2): [True: 0, False: 5.71k]
  ------------------
 5517|  5.71k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5517:2): [True: 0, False: 5.71k]
  ------------------
 5518|  5.71k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5518:2): [True: 0, False: 5.71k]
  ------------------
 5519|  5.71k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5519:2): [True: 0, False: 5.71k]
  ------------------
 5520|  5.71k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5520:2): [True: 0, False: 5.71k]
  ------------------
 5521|  5.71k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5521:2): [True: 0, False: 5.71k]
  ------------------
 5522|  5.71k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5522:2): [True: 0, False: 5.71k]
  ------------------
 5523|  5.71k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5523:2): [True: 0, False: 5.71k]
  ------------------
 5524|  5.71k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5524:2): [True: 0, False: 5.71k]
  ------------------
 5525|  5.71k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5525:2): [True: 0, False: 5.71k]
  ------------------
 5526|  5.71k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5526:2): [True: 0, False: 5.71k]
  ------------------
 5527|  5.71k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5527:2): [True: 0, False: 5.71k]
  ------------------
 5528|  5.71k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5528:2): [True: 0, False: 5.71k]
  ------------------
 5529|  5.71k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5529:2): [True: 0, False: 5.71k]
  ------------------
 5530|  5.71k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5530:2): [True: 0, False: 5.71k]
  ------------------
 5531|  5.71k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5531:2): [True: 0, False: 5.71k]
  ------------------
 5532|  5.71k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5532:2): [True: 0, False: 5.71k]
  ------------------
 5533|  5.71k|		break;
 5534|      0|	default:
  ------------------
  |  Branch (5534:2): [True: 0, False: 5.71k]
  ------------------
 5535|      0|		return 0; /* can not handle the card */
 5536|  5.71k|	}
 5537|       |
 5538|  5.71k|	r = sc_lock(card);
 5539|  5.71k|	if (r < 0)
  ------------------
  |  Branch (5539:6): [True: 0, False: 5.71k]
  ------------------
 5540|      0|		return 0;
 5541|       |	/* its one we know, or we can test for it in piv_init */
 5542|  5.71k|	r = piv_match_card_continued(card);
 5543|  5.71k|	sc_unlock(card);
 5544|       |
 5545|  5.71k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5545:6): [True: 4.68k, False: 1.03k]
  |  Branch (5545:15): [True: 0, False: 1.03k]
  ------------------
 5546|       |		/* clean up what we left in card */
 5547|  4.68k|		piv_finish(card);
 5548|  4.68k|		return 0; /* match failed */
 5549|  4.68k|	}
 5550|       |
 5551|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5552|  1.03k|	return 1; /* matched */
 5553|  5.71k|}
card-piv.c:piv_match_card_continued:
 5557|  5.71k|{
 5558|  5.71k|	int i, r = 0, r2 = 0;
 5559|  5.71k|	int type = -1;
 5560|  5.71k|	piv_private_data_t *priv = NULL;
 5561|  5.71k|	int saved_type = card->type;
 5562|  5.71k|	sc_apdu_t apdu;
 5563|  5.71k|	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.71k|	switch (card->type) {
 5569|  5.71k|	case -1:
  ------------------
  |  Branch (5569:2): [True: 5.71k, False: 0]
  ------------------
 5570|  5.71k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5570:2): [True: 0, False: 5.71k]
  ------------------
 5571|  5.71k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5571:2): [True: 0, False: 5.71k]
  ------------------
 5572|  5.71k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5572:2): [True: 0, False: 5.71k]
  ------------------
 5573|  5.71k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5573:2): [True: 0, False: 5.71k]
  ------------------
 5574|  5.71k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5574:2): [True: 0, False: 5.71k]
  ------------------
 5575|  5.71k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5575:2): [True: 0, False: 5.71k]
  ------------------
 5576|  5.71k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5576:2): [True: 0, False: 5.71k]
  ------------------
 5577|  5.71k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5577:2): [True: 0, False: 5.71k]
  ------------------
 5578|  5.71k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5578:2): [True: 0, False: 5.71k]
  ------------------
 5579|  5.71k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5579:2): [True: 0, False: 5.71k]
  ------------------
 5580|  5.71k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5580:2): [True: 0, False: 5.71k]
  ------------------
 5581|  5.71k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5581:2): [True: 0, False: 5.71k]
  ------------------
 5582|  5.71k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5582:2): [True: 0, False: 5.71k]
  ------------------
 5583|  5.71k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5583:2): [True: 0, False: 5.71k]
  ------------------
 5584|  5.71k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5584:2): [True: 0, False: 5.71k]
  ------------------
 5585|  5.71k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5585:2): [True: 0, False: 5.71k]
  ------------------
 5586|  5.71k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5586:2): [True: 0, False: 5.71k]
  ------------------
 5587|  5.71k|		type = card->type;
 5588|  5.71k|		break;
 5589|      0|	default:
  ------------------
  |  Branch (5589:2): [True: 0, False: 5.71k]
  ------------------
 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.71k|	}
 5592|  5.71k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.71k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5593|  5.71k|	if (type == -1) {
  ------------------
  |  Branch (5593:6): [True: 5.71k, 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.71k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5601:7): [True: 1.68k, False: 4.03k]
  ------------------
 5602|  1.68k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5602:8): [True: 78, False: 1.60k]
  ------------------
 5603|     78|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5603:6): [True: 15, False: 63]
  ------------------
 5604|     15|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5605|  1.66k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5605:15): [True: 1.04k, False: 622]
  ------------------
 5606|  1.04k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5606:6): [True: 72, False: 973]
  ------------------
 5607|     72|				type = SC_CARD_TYPE_PIV_II_NEO;
 5608|  1.59k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5608:15): [True: 1.00k, False: 591]
  ------------------
 5609|  1.00k|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5609:6): [True: 57, False: 947]
  ------------------
 5610|     57|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5611|  1.53k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5611:15): [True: 947, False: 591]
  ------------------
 5612|    947|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5612:6): [True: 24, False: 923]
  ------------------
 5613|     24|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5614|     24|			}
 5615|       |			/* look for TLV historic data */
 5616|  1.51k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5616:13): [True: 1.48k, False: 33]
  ------------------
 5617|  1.48k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5617:6): [True: 508, False: 973]
  ------------------
 5618|    508|				size_t datalen;
 5619|    508|				const u8 *data;
 5620|       |
 5621|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5622|    508|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5622:9): [True: 206, False: 302]
  ------------------
 5623|    508|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5624|    206|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5624:10): [True: 34, False: 172]
  |  Branch (5624:26): [True: 22, False: 12]
  ------------------
 5625|     22|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5626|    184|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5626:17): [True: 159, False: 25]
  |  Branch (5626:33): [True: 141, False: 18]
  ------------------
 5627|    141|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5628|    141|					}
 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|     43|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5634:15): [True: 18, False: 25]
  |  Branch (5634:31): [True: 14, False: 4]
  ------------------
 5635|     14|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5636|     14|					}
 5637|    302|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5637:16): [True: 48, False: 254]
  ------------------
 5638|    302|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5639|     48|					int k;
 5640|       |
 5641|    142|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5641:18): [True: 96, False: 46]
  ------------------
 5642|     96|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5642:11): [True: 84, False: 12]
  ------------------
 5643|     84|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5643:9): [True: 2, False: 82]
  ------------------
 5644|      2|							type = SC_CARD_TYPE_PIV_II_HIST;
 5645|      2|							break;
 5646|      2|						}
 5647|     96|					}
 5648|     48|				}
 5649|    508|			}
 5650|  1.68k|		}
 5651|       |
 5652|  5.71k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.71k|#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.71k|		if (type == -1) {
  ------------------
  |  Branch (5654:7): [True: 5.37k, False: 347]
  ------------------
 5655|       |			/* use known ATRs  which changes the type */
 5656|  5.37k|			i = _sc_match_atr(card, piv_atrs, &type);
 5657|  5.37k|			if (i < 0)
  ------------------
  |  Branch (5657:8): [True: 5.36k, False: 7]
  ------------------
 5658|  5.36k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5659|  5.37k|		}
 5660|  5.71k|	}
 5661|       |
 5662|  5.71k|	card->type = type;
 5663|       |
 5664|       |	/* we either found via ATR historic bytes or ATR directly */
 5665|  5.71k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.71k|#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.71k|	priv = calloc(1, sizeof(piv_private_data_t));
 5669|       |
 5670|  5.71k|	if (!priv)
  ------------------
  |  Branch (5670:6): [True: 0, False: 5.71k]
  ------------------
 5671|  5.71k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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.71k|	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.71k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  220|  5.71k|#define MAX_FILE_SIZE 65535
  ------------------
 5680|  5.71k|	priv->selected_obj = -1;
 5681|  5.71k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5682|  5.71k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|  5.71k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5683|  5.71k|	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.71k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5695:6): [True: 1.93k, False: 3.78k]
  ------------------
 5696|  1.93k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5696:4): [True: 1.70k, False: 229]
  ------------------
 5697|  1.70k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5697:4): [True: 172, False: 1.53k]
  ------------------
 5698|    172|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5698:4): [True: 121, False: 51]
  ------------------
 5699|    121|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5699:4): [True: 94, False: 27]
  ------------------
 5700|     94|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  385|     94|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5701|     94|	}
 5702|       |
 5703|   348k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5703:14): [True: 343k, False: 5.71k]
  ------------------
 5704|   343k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  646|   343k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5704:7): [True: 114k, False: 228k]
  ------------------
 5705|   114k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|   120k|#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.71k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5724:6): [True: 354, False: 5.36k]
  ------------------
 5725|    354|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  385|    354|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5725:4): [True: 348, False: 6]
  ------------------
 5726|    348|		r = piv_find_discovery(card);
 5727|    348|		if (r < 0) {
  ------------------
  |  Branch (5727:7): [True: 251, False: 97]
  ------------------
 5728|    251|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5729|    251|			r = piv_find_aid(card);
 5730|    251|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    251|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    251|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    251|	int _ret = (r); \
  |  |  |  |  178|    251|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 86, False: 165]
  |  |  |  |  ------------------
  |  |  |  |  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|    251|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 165]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5731|    251|		}
 5732|  5.37k|	} else {
 5733|       |		/* piv_find_aid saves al_label from response */
 5734|  5.37k|		r = piv_find_aid(card);
 5735|  5.37k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  5.37k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.37k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.37k|	int _ret = (r); \
  |  |  |  |  178|  5.37k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.59k, False: 775]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.59k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.59k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.59k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.59k|		goto err; \
  |  |  |  |  182|  4.59k|	} \
  |  |  |  |  183|  5.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 775]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5736|  5.37k|	}
 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|  1.03k|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5741:6): [True: 6, False: 1.03k]
  |  Branch (5741:24): [True: 4, False: 2]
  ------------------
 5742|      4|		switch (card->type) {
  ------------------
  |  Branch (5742:11): [True: 3, False: 1]
  ------------------
 5743|      3|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5743:3): [True: 3, False: 1]
  ------------------
 5744|      3|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5744:3): [True: 0, False: 4]
  ------------------
 5745|      5|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5745:16): [True: 3, False: 2]
  ------------------
 5746|      3|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5746:9): [True: 2, False: 1]
  ------------------
 5747|      2|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5747:7): [True: 1, False: 1]
  ------------------
 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|      3|			}
 5753|      3|			break;
 5754|      4|		}
 5755|      4|	}
 5756|       |
 5757|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5758|  1.03k|			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|  1.03k|	switch (card->type) {
  ------------------
  |  Branch (5766:10): [True: 1.02k, False: 11]
  ------------------
 5767|     61|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5767:2): [True: 61, False: 976]
  ------------------
 5768|    217|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5768:2): [True: 156, False: 881]
  ------------------
 5769|    238|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5769:2): [True: 21, False: 1.01k]
  ------------------
 5770|    251|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5770:2): [True: 13, False: 1.02k]
  ------------------
 5771|    252|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5771:2): [True: 1, False: 1.03k]
  ------------------
 5772|    252|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5772:2): [True: 0, False: 1.03k]
  ------------------
 5773|  1.02k|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5773:2): [True: 774, False: 263]
  ------------------
 5774|  1.02k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|  1.02k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5775|  1.02k|		apdu.lc = 0;
 5776|  1.02k|		apdu.data = NULL;
 5777|  1.02k|		apdu.datalen = 0;
 5778|  1.02k|		apdu.resp = yubico_version_buf;
 5779|  1.02k|		apdu.resplen = sizeof(yubico_version_buf);
 5780|  1.02k|		apdu.le = apdu.resplen;
 5781|  1.02k|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5782|  1.02k|		if (r2 == SC_SUCCESS && apdu.resplen == 3) {
  ------------------
  |  |   28|  2.05k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5782:7): [True: 1.02k, False: 4]
  |  Branch (5782:27): [True: 464, False: 558]
  ------------------
 5783|    464|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5784|    464|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5785|    464|		}
 5786|  1.02k|		break;
 5787|  1.03k|	}
 5788|       |
 5789|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5790|  1.03k|			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|  1.03k|	switch (card->type) {
  ------------------
  |  Branch (5794:10): [True: 775, False: 262]
  ------------------
 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|    774|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5800:2): [True: 774, False: 263]
  ------------------
 5801|    774|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5801:2): [True: 0, False: 1.03k]
  ------------------
 5802|    775|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5802:2): [True: 1, False: 1.03k]
  ------------------
 5803|    775|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5803:2): [True: 0, False: 1.03k]
  ------------------
 5804|    775|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5804:2): [True: 0, False: 1.03k]
  ------------------
 5805|    775|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5805:2): [True: 0, False: 1.03k]
  ------------------
 5806|    775|		r2 = piv_process_ccc(card);
 5807|    775|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    775|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5808|    775|				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|    775|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  174|    775|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5811:7): [True: 4, False: 771]
  ------------------
 5812|      4|			switch (card->type) {
  ------------------
  |  Branch (5812:12): [True: 4, False: 0]
  ------------------
 5813|      4|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5813:4): [True: 4, False: 0]
  ------------------
 5814|      4|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5814:4): [True: 0, False: 4]
  ------------------
 5815|      4|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5815:4): [True: 0, False: 4]
  ------------------
 5816|      4|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5816:4): [True: 0, False: 4]
  ------------------
 5817|      4|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5818|      4|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      4|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5819|      4|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      4|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5820|      4|				break;
 5821|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5821:4): [True: 0, False: 4]
  ------------------
 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: 4]
  ------------------
 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|      4|			}
 5832|      4|		}
 5833|    775|		break;
 5834|       |
 5835|    775|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5835:2): [True: 0, False: 1.03k]
  ------------------
 5836|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5836:2): [True: 0, False: 1.03k]
  ------------------
 5837|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5837:2): [True: 0, False: 1.03k]
  ------------------
 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|  1.03k|	}
 5842|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5843|  1.03k|			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|  1.03k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  380|  1.03k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  385|     97|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5846:6): [True: 97, False: 940]
  |  Branch (5846:51): [True: 0, False: 97]
  ------------------
 5847|      0|		r2 = piv_find_aid(card);
 5848|      0|	}
 5849|       |
 5850|       |	/* Read AID if needed for these cards types */
 5851|  1.03k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  380|  1.03k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5851:6): [True: 97, False: 940]
  ------------------
 5852|     97|		switch (card->type) {
  ------------------
  |  Branch (5852:11): [True: 23, False: 74]
  ------------------
 5853|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5853:3): [True: 0, False: 97]
  ------------------
 5854|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5854:3): [True: 0, False: 97]
  ------------------
 5855|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5855:3): [True: 0, False: 97]
  ------------------
 5856|     21|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5856:3): [True: 21, False: 76]
  ------------------
 5857|     23|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5857:3): [True: 2, False: 95]
  ------------------
 5858|     23|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5858:3): [True: 0, False: 97]
  ------------------
 5859|     23|			r2 = piv_find_aid(card);
 5860|     97|		}
 5861|     97|	}
 5862|       |
 5863|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5864|  1.03k|			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|  1.03k|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  609|  1.03k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  600|  1.03k|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  601|  1.03k|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  602|  1.03k|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  604|  1.03k|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  605|  1.03k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5867:6): [True: 1.03k, False: 2]
  ------------------
 5868|  1.03k|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  609|  1.03k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  600|  1.03k|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  601|  1.03k|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  602|  1.03k|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  604|  1.03k|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  605|  1.03k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 5869|  1.03k|	}
 5870|       |
 5871|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 5872|  1.03k|	switch (card->type) {
  ------------------
  |  Branch (5872:10): [True: 770, False: 267]
  ------------------
 5873|    770|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5873:2): [True: 770, False: 267]
  ------------------
 5874|    770|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5874:2): [True: 0, False: 1.03k]
  ------------------
 5875|    770|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  381|    770|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (5875:7): [True: 0, False: 770]
  ------------------
 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|    770|		break;
 5886|  1.03k|	}
 5887|       |
 5888|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5889|  1.03k|			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|  1.03k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5907|  1.03k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5908|  1.03k|	switch (card->type) {
 5909|     61|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5909:2): [True: 61, False: 976]
  ------------------
 5910|     61|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  596|     61|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 5911|     61|				     CI_VERIFY_630X |
  ------------------
  |  |  584|     61|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 5912|     61|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  593|     61|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5913|     61|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  589|     61|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5914|     61|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  594|     61|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 5915|     61|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5915:7): [True: 34, False: 27]
  ------------------
 5916|     34|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  585|     34|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5917|     61|		break;
 5918|       |
 5919|    156|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5919:2): [True: 156, False: 881]
  ------------------
 5920|    157|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5920:2): [True: 1, False: 1.03k]
  ------------------
 5921|    170|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5921:2): [True: 13, False: 1.02k]
  ------------------
 5922|    170|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  593|    170|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5923|    170|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  589|    170|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5924|    170|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5924:7): [True: 50, False: 120]
  ------------------
 5925|     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 */
  ------------------
 5926|    170|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (5926:7): [True: 103, False: 67]
  ------------------
 5927|    103|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  603|    103|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  606|    103|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  607|    103|#define AI_X25519			    0x00200000U
  ------------------
 5928|    170|		break;
 5929|       |
 5930|     21|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5930:2): [True: 21, False: 1.01k]
  ------------------
 5931|     21|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|     21|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5932|     21|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (5932:7): [True: 14, False: 7]
  ------------------
 5933|     14|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  603|     14|#define AI_RSA_4096			    0x00000008U
  ------------------
 5934|     21|		break;
 5935|       |
 5936|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5936:2): [True: 0, False: 1.03k]
  ------------------
 5937|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5937:2): [True: 0, False: 1.03k]
  ------------------
 5938|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5938:2): [True: 0, False: 1.03k]
  ------------------
 5939|      0|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5939:2): [True: 0, False: 1.03k]
  ------------------
 5940|      0|		priv->card_issues |= 0; /* could add others here */
 5941|      0|		break;
 5942|       |
 5943|    770|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5943:2): [True: 770, False: 267]
  ------------------
 5944|    771|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5944:2): [True: 1, False: 1.03k]
  ------------------
 5945|    772|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5945:2): [True: 1, False: 1.03k]
  ------------------
 5946|    772|		priv->card_issues |= 0; /* could add others here */
 5947|    772|		break;
 5948|       |
 5949|      4|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5949:2): [True: 4, False: 1.03k]
  ------------------
 5950|      4|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5950:2): [True: 0, False: 1.03k]
  ------------------
 5951|      4|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5951:2): [True: 0, False: 1.03k]
  ------------------
 5952|      4|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      4|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5953|      4|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  591|      4|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5954|      4|				     CI_NO_RANDOM |
  ------------------
  |  |  587|      4|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5955|      4|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      4|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5956|      4|		break;
 5957|       |
 5958|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5958:2): [True: 0, False: 1.03k]
  ------------------
 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|      9|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5963:2): [True: 9, False: 1.02k]
  ------------------
 5964|      9|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      9|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5965|      9|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  591|      9|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5966|      9|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  587|      9|#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|      9|		break;
 5969|       |
 5970|      0|	default:
  ------------------
  |  Branch (5970:2): [True: 0, False: 1.03k]
  ------------------
 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|  1.03k|	}
 5977|  1.03k|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|  1.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5978|  1.03k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5979|       |
 5980|  1.03k|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  590|  1.03k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
              	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  382|  1.03k|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (5980:6): [True: 1.03k, False: 4]
  |  Branch (5980:53): [True: 936, False: 97]
  ------------------
 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|    936|		r2 = piv_find_discovery(card);
 5989|       |
 5990|    936|		if (r2 < 0) {
  ------------------
  |  Branch (5990:7): [True: 935, False: 1]
  ------------------
 5991|    935|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|    935|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5992|    935|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  153|    935|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5993|    935|		}
 5994|    936|	}
 5995|       |
 5996|  1.03k|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|  1.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5997|  1.03k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5998|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 5999|  1.03k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.03k|	int _ret = r; \
  |  |  |  |  155|  1.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.03k|	return _ret; \
  |  |  |  |  163|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6000|       |
 6001|  4.68k|err:
 6002|  4.68k|	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.68k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6003|  4.68k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6004|       |	/* don't match. Does not have a PIV applet. */
 6005|  4.68k|	piv_finish(card);
 6006|  4.68k|	card->type = saved_type;
 6007|  4.68k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.68k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.68k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.68k|	int _ret = r; \
  |  |  |  |  155|  4.68k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.68k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.68k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.68k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.68k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.68k|	return _ret; \
  |  |  |  |  163|  4.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6008|  4.68k|}
card-piv.c:piv_find_discovery:
 5158|  1.51k|{
 5159|  1.51k|	int r = 0;
 5160|  1.51k|	size_t rbuflen;
 5161|  1.51k|	u8 *rbuf = NULL;
 5162|  1.51k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.51k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5163|       |
 5164|  1.51k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.51k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.51k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.51k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.51k]
  |  |  ------------------
  ------------------
 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|  1.51k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  1.51k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5171:6): [True: 0, False: 1.51k]
  ------------------
 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|  1.51k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  151|  1.51k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5177:6): [True: 1.28k, False: 234]
  ------------------
 5178|  1.28k|		r = piv_process_discovery(card);
 5179|  1.28k|	} else {
 5180|       |		/* if already in cache,force read */
 5181|    234|		rbuflen = 1;
 5182|    234|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5183|       |		/* if same response as last, no need to parse */
 5184|    234|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5184:7): [True: 0, False: 234]
  |  Branch (5184:17): [True: 0, False: 0]
  ------------------
 5185|      0|			goto end;
 5186|       |
 5187|    234|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5187:7): [True: 25, False: 209]
  |  Branch (5187:17): [True: 22, False: 3]
  ------------------
 5188|     22|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5188:5): [True: 22, False: 0]
  ------------------
 5189|     22|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5189:5): [True: 13, False: 9]
  ------------------
 5190|     13|			goto end;
 5191|     13|		}
 5192|       |		/* This should not happen  bad card */
 5193|    221|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|    221|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5194|    221|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    221|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5195|    221|		goto end;
 5196|    234|	}
 5197|       |
 5198|  1.51k|end:
 5199|  1.51k|	free(rbuf);
 5200|  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.50k, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.40k, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.50k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.50k|	} 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|  1.51k|	return _ret; \
  |  |  |  |  163|  1.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5201|  1.51k|}
card-piv.c:piv_process_discovery:
 5051|  1.28k|{
 5052|  1.28k|	int r;
 5053|  1.28k|	u8 *rbuf = NULL;
 5054|  1.28k|	size_t rbuflen = 0;
 5055|       |
 5056|  1.28k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5057|       |	/* Note rbuf and rbuflen are now pointers into cache */
 5058|  1.28k|	if (r < 0)
  ------------------
  |  Branch (5058:6): [True: 1.15k, False: 129]
  ------------------
 5059|  1.15k|		goto err;
 5060|       |
 5061|       |	/* the object is now cached, see what we have */
 5062|    129|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 5063|       |
 5064|  1.28k|err:
 5065|  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|  1.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.18k, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|  1.28k|}
card-piv.c:piv_get_cached_data:
 3201|  12.9k|{
 3202|       |
 3203|  12.9k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  12.9k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3204|  12.9k|	int r;
 3205|  12.9k|	u8 *rbuf = NULL;
 3206|  12.9k|	size_t rbuflen;
 3207|       |
 3208|  12.9k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  12.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  12.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  12.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12.9k]
  |  |  ------------------
  ------------------
 3209|       |
 3210|  12.9k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3210:6): [True: 0, False: 12.9k]
  |  Branch (3210:21): [True: 0, False: 12.9k]
  ------------------
 3211|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3212|       |
 3213|  12.9k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3214|       |
 3215|       |	/* see if we have it cached */
 3216|  12.9k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  151|  12.9k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3216:6): [True: 1.58k, False: 11.3k]
  ------------------
 3217|       |
 3218|  1.58k|		sc_log(card->ctx, "found #%d %p:%zu %p:%zu",
  ------------------
  |  |   71|  1.58k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3219|  1.58k|				enumtag,
 3220|  1.58k|				priv->obj_cache[enumtag].obj_data,
 3221|  1.58k|				priv->obj_cache[enumtag].obj_len,
 3222|  1.58k|				priv->obj_cache[enumtag].internal_obj_data,
 3223|  1.58k|				priv->obj_cache[enumtag].internal_obj_len);
 3224|       |
 3225|  1.58k|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3225:7): [True: 0, False: 1.58k]
  ------------------
 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|  1.58k|		*buf = priv->obj_cache[enumtag].obj_data;
 3231|  1.58k|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3232|  1.58k|		r = (int)*buf_len;
 3233|  1.58k|		goto ok;
 3234|  1.58k|	}
 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|  11.3k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  11.3k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3243:6): [True: 0, False: 11.3k]
  ------------------
 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|  11.3k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  11.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3251|  11.3k|	rbuflen = 1;
 3252|  11.3k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3253|  11.3k|	if (r > 0) {
  ------------------
  |  Branch (3253:6): [True: 2.26k, False: 9.06k]
  ------------------
 3254|  2.26k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  2.26k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3255|  2.26k|		priv->obj_cache[enumtag].obj_len = r;
 3256|  2.26k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3257|  2.26k|		*buf = rbuf;
 3258|  2.26k|		*buf_len = r;
 3259|       |
 3260|  2.26k|		sc_log(card->ctx, "added #%d  %p:%zu %p:%zu",
  ------------------
  |  |   71|  2.26k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3261|  2.26k|				enumtag,
 3262|  2.26k|				priv->obj_cache[enumtag].obj_data,
 3263|  2.26k|				priv->obj_cache[enumtag].obj_len,
 3264|  2.26k|				priv->obj_cache[enumtag].internal_obj_data,
 3265|  2.26k|				priv->obj_cache[enumtag].internal_obj_len);
 3266|       |
 3267|  9.06k|	} else {
 3268|  9.06k|		free(rbuf);
 3269|  9.06k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  9.06k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3269:7): [True: 0, False: 9.06k]
  |  Branch (3269:17): [True: 1.19k, False: 7.87k]
  ------------------
 3270|  1.19k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.19k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3271|  1.19k|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  1.19k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3272|  1.19k|			priv->obj_cache[enumtag].obj_len = 0;
 3273|  7.87k|		} else {
 3274|  7.87k|			goto err;
 3275|  7.87k|		}
 3276|  9.06k|	}
 3277|  5.03k|ok:
 3278|       |
 3279|  12.9k|err:
 3280|  12.9k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  12.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.9k|	int _ret = r; \
  |  |  |  |  155|  12.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.06k, False: 3.84k]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|  9.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.06k|	} else { \
  |  |  |  |  159|  3.84k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.84k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.84k|	} \
  |  |  |  |  162|  12.9k|	return _ret; \
  |  |  |  |  163|  12.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3281|  12.9k|}
card-piv.c:piv_parse_discovery:
 4995|    129|{
 4996|    129|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    129|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4997|    129|	int r = 0;
 4998|    129|	const u8 *body;
 4999|    129|	size_t bodylen;
 5000|    129|	const u8 *aid;
 5001|    129|	size_t aidlen;
 5002|    129|	const u8 *pinp;
 5003|    129|	size_t pinplen;
 5004|    129|	unsigned int cla_out, tag_out;
 5005|       |
 5006|    129|	if (rbuflen != 0) {
  ------------------
  |  Branch (5006:6): [True: 129, False: 0]
  ------------------
 5007|    129|		body = rbuf;
 5008|    129|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    258|#define SC_SUCCESS				0
  ------------------
  |  Branch (5008:7): [True: 0, False: 129]
  ------------------
 5009|    129|				body == NULL ||
  ------------------
  |  Branch (5009:5): [True: 0, False: 129]
  ------------------
 5010|    129|				bodylen == 0 ||
  ------------------
  |  Branch (5010:5): [True: 3, False: 126]
  ------------------
 5011|    126|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (5011:5): [True: 0, False: 126]
  ------------------
 5012|      3|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5013|      3|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5014|      3|			goto err;
 5015|      3|		}
 5016|       |
 5017|    126|		sc_log(card->ctx, "Discovery 0x%2.2x 0x%2.2x %p:%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5018|    126|				cla_out, tag_out, body, bodylen);
 5019|    126|		aidlen = 0;
 5020|    126|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 5021|    126|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (5021:7): [True: 6, False: 120]
  |  Branch (5021:22): [True: 1, False: 119]
  ------------------
 5022|    119|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (5022:5): [True: 21, False: 98]
  ------------------
 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|     98|		if (aid_only == 0) {
  ------------------
  |  Branch (5027:7): [True: 98, False: 0]
  ------------------
 5028|     98|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 5029|     98|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (5029:8): [True: 45, False: 53]
  |  Branch (5029:16): [True: 34, False: 11]
  ------------------
 5030|     34|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  383|     34|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 5031|     34|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 5032|     34|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5033|     34|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|     34|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|     34|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|     34|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|     34|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (5033:9): [True: 9, False: 25]
  ------------------
 5034|      9|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  377|      9|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (5034:7): [True: 1, False: 8]
  ------------------
 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|     34|			}
 5039|     98|		}
 5040|     98|		r = SC_SUCCESS;
  ------------------
  |  |   28|     98|#define SC_SUCCESS				0
  ------------------
 5041|     98|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  382|     98|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 5042|     98|	}
 5043|       |
 5044|    129|err:
 5045|    129|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    129|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    129|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    129|	int _ret = r; \
  |  |  |  |  155|    129|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 129, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    129|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  157|    129|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    129|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    129|	return _ret; \
  |  |  |  |  163|    129|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5046|    129|}
card-piv.c:piv_get_data:
 3091|  11.5k|{
 3092|  11.5k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  11.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3093|  11.5k|	u8 *p;
 3094|  11.5k|	u8 *tbuf;
 3095|  11.5k|	int r = 0;
 3096|  11.5k|	u8 tagbuf[8];
 3097|  11.5k|	size_t tag_len;
 3098|  11.5k|	int alloc_buf = 0;
 3099|       |
 3100|  11.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  11.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.5k]
  |  |  ------------------
  ------------------
 3101|       |
 3102|  11.5k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  11.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3103|       |
 3104|  11.5k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3105|  11.5k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3105:6): [True: 0, False: 11.5k]
  ------------------
 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|  11.5k|	tag_len = piv_objects[enumtag].tag_len;
 3111|       |
 3112|  11.5k|	p = tagbuf;
 3113|  11.5k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3114|  11.5k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3114:6): [True: 0, False: 11.5k]
  ------------------
 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|  11.5k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3119:6): [True: 11.5k, False: 15]
  |  Branch (3119:23): [True: 11.5k, False: 0]
  ------------------
 3120|  11.5k|		*buf_len = priv->max_object_size; /* will allocate below */
 3121|  11.5k|		alloc_buf = 1;
 3122|  11.5k|	}
 3123|       |
 3124|  11.5k|	sc_log(card->ctx, "buffer for #%d *buf=0x%p len=%zu", enumtag, *buf, *buf_len);
  ------------------
  |  |   71|  11.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3125|  11.5k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3125:6): [True: 11.5k, False: 15]
  |  Branch (3125:22): [True: 11.5k, False: 0]
  ------------------
 3126|  11.5k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  11.5k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3126:7): [True: 0, False: 11.5k]
  ------------------
 3127|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3128|      0|			goto err;
 3129|      0|		}
 3130|  11.5k|		*buf = malloc(*buf_len);
 3131|  11.5k|		if (*buf == NULL) {
  ------------------
  |  Branch (3131:7): [True: 0, False: 11.5k]
  ------------------
 3132|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3133|      0|			goto err;
 3134|      0|		}
 3135|  11.5k|	}
 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|  11.5k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3158|  11.5k|	if (r > 0) {
  ------------------
  |  Branch (3158:6): [True: 3.01k, False: 8.55k]
  ------------------
 3159|  3.01k|		int r_tag;
 3160|  3.01k|		unsigned int cla_out, tag_out;
 3161|  3.01k|		size_t bodylen = 0;
 3162|  3.01k|		const u8 *body = *buf;
 3163|  3.01k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3164|  3.01k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  6.03k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3164:7): [True: 195, False: 2.82k]
  |  Branch (3164:30): [True: 125, False: 2.69k]
  ------------------
 3165|  2.69k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3165:5): [True: 411, False: 2.28k]
  ------------------
 3166|    731|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|    731|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3167|    731|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    731|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3168|    731|			goto err;
 3169|    731|		}
 3170|  2.28k|		*buf_len = (body - *buf) + bodylen;
 3171|  8.55k|	} else if (r == 0) {
  ------------------
  |  Branch (3171:13): [True: 164, False: 8.39k]
  ------------------
 3172|    164|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    164|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3173|    164|		goto err;
 3174|  8.39k|	} else {
 3175|  8.39k|		goto err;
 3176|  8.39k|	}
 3177|       |
 3178|  2.28k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3178:6): [True: 2.28k, False: 1]
  |  Branch (3178:19): [True: 2.28k, False: 0]
  ------------------
 3179|  2.28k|		tbuf = malloc(r);
 3180|  2.28k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3180:7): [True: 0, False: 2.28k]
  ------------------
 3181|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3182|      0|			goto err;
 3183|      0|		}
 3184|  2.28k|		memcpy(tbuf, *buf, r);
 3185|  2.28k|		free(*buf);
 3186|  2.28k|		alloc_buf = 0;
 3187|  2.28k|		*buf = tbuf;
 3188|  2.28k|	}
 3189|       |
 3190|  11.5k|err:
 3191|  11.5k|	if (alloc_buf) {
  ------------------
  |  Branch (3191:6): [True: 9.27k, False: 2.30k]
  ------------------
 3192|  9.27k|		free(*buf);
 3193|  9.27k|		*buf = NULL;
 3194|  9.27k|	}
 3195|  11.5k|	sc_unlock(card);
 3196|  11.5k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  11.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.5k|	int _ret = r; \
  |  |  |  |  155|  11.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.28k, False: 2.28k]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.28k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.28k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.28k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.28k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.28k|	} else { \
  |  |  |  |  159|  2.28k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.28k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.28k|	} \
  |  |  |  |  162|  11.5k|	return _ret; \
  |  |  |  |  163|  11.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3197|  11.5k|}
card-piv.c:piv_general_io:
 1794|  12.0k|{
 1795|  12.0k|	int r;
 1796|  12.0k|	sc_apdu_t apdu;
 1797|       |
 1798|  12.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  12.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  12.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  12.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12.0k]
  |  |  ------------------
  ------------------
 1799|       |
 1800|  12.0k|	r = sc_lock(card);
 1801|  12.0k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  12.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1801:6): [True: 0, False: 12.0k]
  ------------------
 1802|  12.0k|		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|  12.0k|	sc_format_apdu(card, &apdu,
 1805|  12.0k|			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  294|  12.0k|#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: 12.0k, False: 0]
  ------------------
 1806|  12.0k|			ins, p1, p2);
 1807|  12.0k|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  12.0k|#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|  12.0k|	apdu.lc = sendbuflen;
 1815|  12.0k|	apdu.datalen = sendbuflen;
 1816|  12.0k|	apdu.data = sendbuf;
 1817|       |
 1818|  12.0k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1818:6): [True: 12.0k, False: 0]
  |  Branch (1818:17): [True: 12.0k, False: 0]
  ------------------
 1819|  12.0k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1819:13): [True: 12.0k, False: 15]
  ------------------
 1820|  12.0k|		apdu.resplen = recvbuflen;
 1821|  12.0k|	} else {
 1822|      0|		apdu.le = 0;
 1823|      0|		apdu.resplen = 0;
 1824|      0|	}
 1825|  12.0k|	apdu.resp = recvbuf;
 1826|       |
 1827|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1828|  12.0k|	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|  12.0k|	if (r < 0) {
  ------------------
  |  Branch (1831:6): [True: 225, False: 11.8k]
  ------------------
 1832|    225|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    225|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1833|    225|		goto err;
 1834|    225|	}
 1835|       |
 1836|  11.8k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1836:6): [True: 114, False: 11.7k]
  |  Branch (1836:26): [True: 34, False: 80]
  ------------------
 1837|     34|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     34|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1838|  11.8k|	else
 1839|  11.8k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1840|       |
 1841|  11.8k|	if (r < 0) {
  ------------------
  |  Branch (1841:6): [True: 8.40k, False: 3.46k]
  ------------------
 1842|  8.40k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
 1843|  8.40k|		goto err;
 1844|  8.40k|	}
 1845|       |
 1846|  3.46k|	r = (int)apdu.resplen;
 1847|       |
 1848|  12.0k|err:
 1849|  12.0k|	sc_unlock(card);
 1850|  12.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  12.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.0k|	int _ret = r; \
  |  |  |  |  155|  12.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.79k, False: 3.29k]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.79k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.62k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.62k, False: 166]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.79k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.79k|	} else { \
  |  |  |  |  159|  3.29k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.29k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.29k|	} \
  |  |  |  |  162|  12.0k|	return _ret; \
  |  |  |  |  163|  12.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|  12.0k|}
card-piv.c:piv_obj_cache_free_entry:
 5455|   344k|{
 5456|   344k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|   344k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5457|       |
 5458|   344k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5458:6): [True: 2.26k, False: 342k]
  ------------------
 5459|  2.26k|		free(priv->obj_cache[enumtag].obj_data);
 5460|   344k|	priv->obj_cache[enumtag].obj_data = NULL;
 5461|   344k|	priv->obj_cache[enumtag].obj_len = 0;
 5462|       |
 5463|   344k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5463:6): [True: 1.58k, False: 342k]
  ------------------
 5464|  1.58k|		free(priv->obj_cache[enumtag].internal_obj_data);
 5465|   344k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5466|   344k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5467|   344k|	priv->obj_cache[enumtag].flags = flags;
 5468|       |
 5469|   344k|	return SC_SUCCESS;
  ------------------
  |  |   28|   344k|#define SC_SUCCESS				0
  ------------------
 5470|   344k|}
card-piv.c:piv_find_aid:
 2903|  5.85k|{
 2904|  5.85k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  5.85k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2905|  5.85k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2906|  5.85k|	int r, i, j;
 2907|  5.85k|	const u8 *tag;
 2908|  5.85k|	size_t taglen;
 2909|  5.85k|	const u8 *nextac;
 2910|  5.85k|	const u8 *next80;
 2911|  5.85k|	const u8 *pix;
 2912|  5.85k|	size_t pixlen;
 2913|  5.85k|	const u8 *al_label;
 2914|  5.85k|	size_t al_labellen;
 2915|  5.85k|	const u8 *actag; /* Cipher Suite */
 2916|  5.85k|	size_t actaglen;
 2917|  5.85k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2918|  5.85k|	size_t csailen;
 2919|  5.85k|	size_t resplen = sizeof(rbuf);
 2920|       |#ifdef ENABLE_PIV_SM
 2921|       |	int found_csai = 0;
 2922|       |#endif
 2923|       |
 2924|  5.85k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.85k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.85k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.85k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.85k]
  |  |  ------------------
  ------------------
 2925|       |
 2926|       |	/* first  see if the default application will return a template
 2927|       |	 * that we know about.
 2928|       |	 */
 2929|       |
 2930|  5.85k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2931|  5.85k|	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.85k]
  |  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.85k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2935:6): [True: 1.12k, False: 4.73k]
  |  Branch (2935:16): [True: 1.08k, False: 40]
  ------------------
 2936|  1.08k|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2937|  1.08k|		if (tag != NULL) {
  ------------------
  |  Branch (2937:7): [True: 1.03k, False: 51]
  ------------------
 2938|  1.03k|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  380|  1.03k|#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|  1.03k|			nextac = tag;
 2947|  1.15k|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2947:11): [True: 120, False: 1.03k]
  ------------------
 2948|  1.15k|						0xAC, &actaglen)) != NULL) {
 2949|    120|				nextac = actag + actaglen;
 2950|       |
 2951|    120|				next80 = actag;
 2952|    248|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2952:12): [True: 128, False: 120]
  ------------------
 2953|    248|							0x80, &csailen)) != NULL) {
 2954|    128|					next80 = csai + csailen;
 2955|    128|					if (csailen == 1) {
  ------------------
  |  Branch (2955:10): [True: 76, False: 52]
  ------------------
 2956|     76|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2957|     76|						j = piv_ai_map_find_by_id(card, *csai);
 2958|     76|						if (j >= 0) {
  ------------------
  |  Branch (2958:11): [True: 46, False: 30]
  ------------------
 2959|     46|							priv->alg_ids |= ai_map[j].ai_flag;
 2960|     46|							continue;
 2961|     46|						}
 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|     76|					}
 2978|    128|				}
 2979|    120|			}
 2980|       |
 2981|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2982|  1.03k|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2983|  1.03k|			if (al_label != NULL) {
  ------------------
  |  Branch (2983:8): [True: 6, False: 1.02k]
  ------------------
 2984|      6|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  129|      6|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      6|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2985|      6|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2985:9): [True: 0, False: 6]
  ------------------
 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|      6|				memcpy(priv->al_label, al_label, al_labellen);
 2989|      6|				priv->al_labellen = (int)al_labellen;
 2990|      6|			}
 2991|       |
 2992|  1.03k|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 2993|  1.03k|			if (pix != NULL) {
  ------------------
  |  Branch (2993:8): [True: 978, False: 56]
  ------------------
 2994|    978|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    978|#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|  1.05k|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (2997:17): [True: 1.02k, False: 31]
  ------------------
 2998|  1.02k|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (2998:11): [True: 1.01k, False: 8]
  ------------------
 2999|  1.01k|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (2999:12): [True: 944, False: 71]
  ------------------
 3000|     79|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (3000:10): [True: 45, False: 34]
  |  Branch (3000:45): [True: 3, False: 42]
  ------------------
 3001|    947|													     piv_aids[i].len_short) == 0))) {
 3002|    947|						free(priv->aid_der.value); /* free previous value if any */
 3003|    947|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (3003:11): [True: 0, False: 947]
  ------------------
 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|    947|						memcpy(priv->aid_der.value, rbuf, resplen);
 3007|    947|						priv->aid_der.len = resplen;
 3008|    947|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    947|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    947|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    947|	int _ret = r; \
  |  |  |  |  155|    947|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 933, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  156|    933|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 933]
  |  |  |  |  ------------------
  |  |  |  |  157|    933|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    933|	} 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|    947|	return _ret; \
  |  |  |  |  163|    947|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3009|    947|					}
 3010|  1.02k|				}
 3011|    978|			}
 3012|  1.03k|		}
 3013|  1.08k|	}
 3014|       |
 3015|  4.90k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  4.90k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.90k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.90k|	int _ret = r; \
  |  |  |  |  155|  4.90k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.90k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.90k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.90k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.90k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.90k|	return _ret; \
  |  |  |  |  163|  4.90k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3016|  4.90k|}
card-piv.c:piv_ai_map_find_by_id:
 2886|     76|{
 2887|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2888|     76|	int i;
 2889|       |
 2890|    385|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2890:14): [True: 355, False: 30]
  ------------------
 2891|    355|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2891:7): [True: 46, False: 309]
  ------------------
 2892|     46|			return i;
 2893|    355|	}
 2894|     30|	return -1;
 2895|     76|}
card-piv.c:piv_process_ccc:
 5139|    775|{
 5140|    775|	int r = 0;
 5141|    775|	u8 *rbuf = NULL;
 5142|    775|	size_t rbuflen = 0;
 5143|       |
 5144|    775|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    775|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    775|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    775|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 775]
  |  |  ------------------
  ------------------
 5145|    775|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5146|       |
 5147|    775|	if (r < 0)
  ------------------
  |  Branch (5147:6): [True: 716, False: 59]
  ------------------
 5148|    716|		goto err;
 5149|       |
 5150|       |	/* the object is now cached, see what we have */
 5151|     59|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5152|    775|err:
 5153|    775|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    775|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    775|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    775|	int _ret = r; \
  |  |  |  |  155|    775|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 775, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    775|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    759|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 759, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|    775|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    775|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    775|	return _ret; \
  |  |  |  |  163|    775|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5154|    775|}
card-piv.c:piv_parse_ccc:
 5075|     59|{
 5076|     59|	int r = 0;
 5077|     59|	const u8 *body;
 5078|     59|	size_t bodylen;
 5079|     59|	unsigned int cla_out, tag_out;
 5080|       |
 5081|     59|	u8 tag;
 5082|     59|	const u8 *end;
 5083|     59|	size_t len;
 5084|       |
 5085|     59|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     59|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5086|       |
 5087|     59|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     59|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     59|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     59|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 59]
  |  |  ------------------
  ------------------
 5088|       |
 5089|     59|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (5089:6): [True: 0, False: 59]
  |  Branch (5089:22): [True: 0, False: 59]
  ------------------
 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|     59|	body = rbuf;
 5096|     59|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    118|#define SC_SUCCESS				0
  ------------------
  |  Branch (5096:6): [True: 0, False: 59]
  ------------------
 5097|     59|			body == NULL ||
  ------------------
  |  Branch (5097:4): [True: 0, False: 59]
  ------------------
 5098|     59|			bodylen == 0 ||
  ------------------
  |  Branch (5098:4): [True: 2, False: 57]
  ------------------
 5099|     57|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5099:4): [True: 0, False: 57]
  ------------------
 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|     57|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  170|     57|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5106|       |
 5107|       |	/* CCC  entries are simple tlv */
 5108|     57|	end = body + bodylen;
 5109|    903|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5109:9): [True: 887, False: 16]
  ------------------
 5110|    887|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5111|    887|		if (r < 0)
  ------------------
  |  Branch (5111:7): [True: 41, False: 846]
  ------------------
 5112|     41|			goto err;
 5113|    846|		switch (tag) {
  ------------------
  |  Branch (5113:11): [True: 162, False: 684]
  ------------------
 5114|    112|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  176|    112|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5114:3): [True: 112, False: 734]
  ------------------
 5115|    112|			if (len == 0x15) {
  ------------------
  |  Branch (5115:8): [True: 40, False: 72]
  ------------------
 5116|     40|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5116:9): [True: 3, False: 37]
  ------------------
 5117|      3|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  171|      3|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5118|     37|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5118:14): [True: 16, False: 21]
  ------------------
 5119|     16|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  172|     16|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5120|     40|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5120:9): [True: 16, False: 24]
  ------------------
 5121|     16|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  173|     16|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5122|     40|			}
 5123|    112|			break;
 5124|     50|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  177|     50|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5124:3): [True: 50, False: 796]
  ------------------
 5125|     50|			if (len == 0x10) {
  ------------------
  |  Branch (5125:8): [True: 31, False: 19]
  ------------------
 5126|     31|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5126:9): [True: 10, False: 21]
  ------------------
 5127|     10|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  174|     10|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5128|     31|			}
 5129|     50|			break;
 5130|    846|		}
 5131|    846|	}
 5132|       |
 5133|     59|err:
 5134|     59|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     59|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     59|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     59|	int _ret = r; \
  |  |  |  |  155|     59|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 59, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     59|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     43|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 43, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|     59|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     59|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     59|	return _ret; \
  |  |  |  |  163|     59|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5135|     59|}
card-piv.c:piv_init:
 6012|  1.03k|{
 6013|  1.03k|	int r = 0;
 6014|  1.03k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.03k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6015|  1.03k|	unsigned long flags;
 6016|  1.03k|	unsigned long flags_eddsa;
 6017|  1.03k|	unsigned long flags_xeddsa;
 6018|  1.03k|	unsigned long ext_flags;
 6019|       |
 6020|  1.03k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.03k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.03k]
  |  |  ------------------
  ------------------
 6021|       |
 6022|  1.03k|	r = sc_lock(card); /* hold until match or init is complete */
 6023|  1.03k|	LOG_TEST_RET(card->ctx, r, "sc_lock failed");
  ------------------
  |  |  174|  1.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.03k|	int _ret = (r); \
  |  |  |  |  168|  1.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6024|       |
 6025|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 6026|  1.03k|	if (priv == NULL) {
  ------------------
  |  Branch (6026:6): [True: 0, False: 1.03k]
  ------------------
 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|  1.03k|	piv_load_options(card);
 6040|       |
 6041|  1.03k|	priv->pstate = PIV_STATE_INIT;
 6042|       |
 6043|  1.03k|	sc_log(card->ctx, "Max send = %zu recv = %zu card->type:%d, CI:%08x AI:%08x",
  ------------------
  |  |   71|  1.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6044|  1.03k|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 6045|  1.03k|	card->cla = 0x00;
 6046|  1.03k|	if (card->name == NULL)
  ------------------
  |  Branch (6046:6): [True: 1.03k, False: 0]
  ------------------
 6047|  1.03k|		card->name = card->driver->name;
 6048|       |
 6049|  1.03k|	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|  1.03k|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|  1.03k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 6057|       |
 6058|  1.03k|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (6058:6): [True: 0, False: 1.03k]
  ------------------
 6059|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 6060|      0|	}
 6061|       |
 6062|  1.03k|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  600|  1.03k|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (6062:6): [True: 1.03k, False: 1]
  ------------------
 6063|  1.03k|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 6064|       |
 6065|  1.03k|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  601|  1.03k|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (6065:6): [True: 1.03k, False: 1]
  ------------------
 6066|  1.03k|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 6067|       |
 6068|  1.03k|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  602|  1.03k|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (6068:6): [True: 1.03k, False: 2]
  ------------------
 6069|  1.03k|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 6070|       |
 6071|  1.03k|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  603|  1.03k|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (6071:6): [True: 117, False: 920]
  ------------------
 6072|    117|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 6073|       |
 6074|  1.03k|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  597|  1.03k|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (6074:6): [True: 1.03k, False: 0]
  ------------------
 6075|  1.03k|		int i;
 6076|  1.03k|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|  1.03k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|  1.03k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|  1.03k|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|  1.03k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 6077|  1.03k|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|  1.03k|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|  1.03k|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 6078|  1.03k|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|  1.03k|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 6079|  1.03k|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  189|  1.03k|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|  1.03k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 6080|       |
 6081|  5.18k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (6081:15): [True: 4.14k, False: 1.03k]
  ------------------
 6082|  4.14k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  4.14k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6082:8): [True: 2.07k, False: 2.07k]
  ------------------
 6083|  2.07k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  596|  4.14k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (6083:11): [True: 122, False: 1.95k]
  |  Branch (6083:46): [True: 61, False: 61]
  ------------------
 6084|  2.01k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 6085|  2.07k|			}
 6086|       |
 6087|  2.07k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  606|  4.14k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    208|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6087:13): [True: 208, False: 1.86k]
  |  Branch (6087:41): [True: 104, False: 104]
  ------------------
 6088|    104|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 6089|       |
 6090|  1.97k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  607|  3.94k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|    105|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6090:13): [True: 105, False: 1.86k]
  |  Branch (6090:42): [True: 104, False: 1]
  ------------------
 6091|    104|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 6092|  4.14k|		}
 6093|  1.03k|	}
 6094|       |
 6095|  1.03k|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  587|  1.03k|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6095:6): [True: 1.02k, False: 13]
  ------------------
 6096|  1.02k|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|  1.02k|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6097|       |
 6098|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6099|  1.03k|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|  1.03k|#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|  1.03k|	piv_process_history(card);
 6159|       |
 6160|  1.03k|	priv->pstate = PIV_STATE_NORMAL;
 6161|  1.03k|	sc_unlock(card);
 6162|  1.03k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.03k|	int _ret = r; \
  |  |  |  |  155|  1.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.03k|	return _ret; \
  |  |  |  |  163|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6163|  1.03k|}
card-piv.c:piv_load_options:
 1686|  1.03k|{
 1687|  1.03k|	int r;
 1688|  1.03k|	size_t i, j;
 1689|  1.03k|	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|  2.07k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1720:14): [True: 1.03k, False: 1.03k]
  ------------------
 1721|  1.03k|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1722|  1.03k|				"card_driver", "PIV-II");
 1723|  1.03k|		if (!found_blocks)
  ------------------
  |  Branch (1723:7): [True: 0, False: 1.03k]
  ------------------
 1724|      0|			continue;
 1725|       |
 1726|  1.03k|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1726:40): [True: 0, False: 1.03k]
  ------------------
 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|  1.03k|		free(found_blocks);
 1763|  1.03k|	}
 1764|  1.03k|	r = SC_SUCCESS;
  ------------------
  |  |   28|  1.03k|#define SC_SUCCESS				0
  ------------------
 1765|  1.03k|	return r;
 1766|  1.03k|}
card-piv.c:piv_process_history:
 5211|  1.03k|{
 5212|  1.03k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.03k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5213|  1.03k|	int r;
 5214|  1.03k|	int i, tmplen, tmplen2, tmplen3;
 5215|  1.03k|	int enumtag;
 5216|  1.03k|	u8 *rbuf = NULL;
 5217|  1.03k|	size_t rbuflen = 0;
 5218|  1.03k|	const u8 *body;
 5219|  1.03k|	size_t bodylen;
 5220|  1.03k|	const u8 *num;
 5221|  1.03k|	size_t numlen;
 5222|  1.03k|	const u8 *url = NULL;
 5223|  1.03k|	size_t urllen;
 5224|  1.03k|	u8 *ocfhfbuf = NULL;
 5225|  1.03k|	unsigned int cla_out, tag_out;
 5226|  1.03k|	size_t ocfhflen;
 5227|  1.03k|	const u8 *seq;
 5228|  1.03k|	const u8 *seqtag;
 5229|  1.03k|	size_t seqlen;
 5230|  1.03k|	const u8 *keyref;
 5231|  1.03k|	size_t keyreflen;
 5232|  1.03k|	const u8 *cert;
 5233|  1.03k|	size_t certlen;
 5234|  1.03k|	size_t certobjlen, i2;
 5235|  1.03k|	u8 *certobj;
 5236|  1.03k|	u8 *cp;
 5237|       |
 5238|  1.03k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.03k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.03k]
  |  |  ------------------
  ------------------
 5239|       |
 5240|  1.03k|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5241|  1.03k|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  1.03k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5241:6): [True: 221, False: 816]
  ------------------
 5242|    221|		r = 0; /* OK if not found */
 5243|  1.03k|	if (r <= 0) {
  ------------------
  |  Branch (5243:6): [True: 854, False: 183]
  ------------------
 5244|    854|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    854|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5245|    854|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5246|    854|	}
 5247|       |
 5248|       |	/* the object is now cached, see what we have */
 5249|    183|	if (rbuflen != 0) {
  ------------------
  |  Branch (5249:6): [True: 183, False: 0]
  ------------------
 5250|    183|		body = rbuf;
 5251|    183|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    366|#define SC_SUCCESS				0
  ------------------
  |  Branch (5251:7): [True: 0, False: 183]
  ------------------
 5252|    183|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5252:5): [True: 0, False: 183]
  ------------------
 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|    183|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5258:7): [True: 183, False: 0]
  |  Branch (5258:23): [True: 181, False: 2]
  ------------------
 5259|    181|			numlen = 0;
 5260|    181|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5261|    181|			if (num) {
  ------------------
  |  Branch (5261:8): [True: 111, False: 70]
  ------------------
 5262|    111|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5262:9): [True: 2, False: 109]
  |  Branch (5262:24): [True: 1, False: 108]
  ------------------
 5263|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5264|      3|					goto err;
 5265|      3|				}
 5266|       |
 5267|    108|				priv->keysWithOnCardCerts = *num;
 5268|    108|			}
 5269|       |
 5270|    178|			numlen = 0;
 5271|    178|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5272|    178|			if (num) {
  ------------------
  |  Branch (5272:8): [True: 3, False: 175]
  ------------------
 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|    176|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5282|    176|			if (url) {
  ------------------
  |  Branch (5282:8): [True: 61, False: 115]
  ------------------
 5283|     61|				if (urllen > 118) {
  ------------------
  |  Branch (5283:9): [True: 0, False: 61]
  ------------------
 5284|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5285|      0|					goto err;
 5286|      0|				}
 5287|     61|				priv->offCardCertURL = calloc(1, urllen + 1);
 5288|     61|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5288:9): [True: 0, False: 61]
  ------------------
 5289|     61|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|     61|				memcpy(priv->offCardCertURL, url, urllen);
 5291|     61|			}
 5292|    176|		} else {
 5293|      2|			sc_log(card->ctx, "Problem with History object\n");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5294|      2|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 5295|      2|			goto err;
 5296|      2|		}
 5297|    183|	}
 5298|    176|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   71|    352|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 61, False: 115]
  |  |  ------------------
  ------------------
 5299|    176|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5300|    176|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5301|       |
 5302|       |	/* now mark what objects are on the card */
 5303|  2.18k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5303:14): [True: 2.00k, False: 176]
  ------------------
 5304|  2.00k|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|  2.18k|#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|    176|	r = 0;
 5318|    176|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5318:6): [True: 61, False: 115]
  ------------------
 5319|     61|		char *fp;
 5320|     61|		char filename[PATH_MAX];
 5321|       |
 5322|     61|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5322:7): [True: 55, False: 6]
  ------------------
 5323|     55|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     55|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5324|     55|			goto err;
 5325|     55|		}
 5326|       |		/* find the last /  so we have the filename part */
 5327|      6|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5328|      6|		if (fp == NULL) {
  ------------------
  |  Branch (5328:7): [True: 4, False: 2]
  ------------------
 5329|      4|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5330|      4|			goto err;
 5331|      4|		}
 5332|      2|		fp++;
 5333|      2|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5333:7): [True: 2, False: 0]
  ------------------
 5334|      2|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5335|      2|			goto err;
 5336|      2|		}
 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|  1.03k|err:
 5448|  1.03k|	if (ocfhfbuf)
  ------------------
  |  Branch (5448:6): [True: 0, False: 1.03k]
  ------------------
 5449|      0|		free(ocfhfbuf);
 5450|  1.03k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.03k|	int _ret = r; \
  |  |  |  |  155|  1.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    699|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 699, False: 338]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.03k|	return _ret; \
  |  |  |  |  163|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5451|  1.03k|}
card-piv.c:piv_cache_internal_data:
 3285|  3.34k|{
 3286|  3.34k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  3.34k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3287|  3.34k|	const u8 *tag;
 3288|  3.34k|	const u8 *body;
 3289|  3.34k|	size_t taglen;
 3290|  3.34k|	size_t bodylen;
 3291|  3.34k|	int compressed = 0;
 3292|  3.34k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.34k|#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|  3.34k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3299:6): [True: 1.58k, False: 1.76k]
  |  Branch (3299:52): [True: 1.58k, False: 0]
  ------------------
 3300|  1.58k|		sc_log(card->ctx, "#%d found internal %p:%zu",
  ------------------
  |  |   71|  1.58k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3301|  1.58k|				enumtag,
 3302|  1.58k|				priv->obj_cache[enumtag].internal_obj_data,
 3303|  1.58k|				priv->obj_cache[enumtag].internal_obj_len);
 3304|  1.58k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.58k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.58k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.58k|	int _ret = r; \
  |  |  |  |  155|  1.58k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3305|  1.58k|	}
 3306|       |
 3307|  1.76k|	body = sc_asn1_find_tag(card->ctx,
 3308|  1.76k|			priv->obj_cache[enumtag].obj_data,
 3309|  1.76k|			priv->obj_cache[enumtag].obj_len,
 3310|  1.76k|			0x53, &bodylen);
 3311|       |
 3312|  1.76k|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3312:6): [True: 0, False: 1.76k]
  |  Branch (3312:22): [True: 0, False: 1.76k]
  ------------------
 3313|  1.76k|		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|  1.76k|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  644|  1.76k|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3316:6): [True: 1.76k, False: 0]
  ------------------
 3317|       |
 3318|  1.76k|		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|  1.76k|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3321:7): [True: 1.06k, False: 702]
  |  Branch (3321:14): [True: 1.01k, False: 42]
  |  Branch (3321:29): [True: 30, False: 988]
  |  Branch (3321:48): [True: 23, False: 965]
  ------------------
 3322|     53|			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|  1.76k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3329|  1.76k|		if (tag == NULL)
  ------------------
  |  Branch (3329:7): [True: 171, False: 1.59k]
  ------------------
 3330|  1.76k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|    171|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    171|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    171|	int _ret = r; \
  |  |  |  |  155|    171|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 171, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    171|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    171|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 171, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    171|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    171|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    171|	return _ret; \
  |  |  |  |  163|    171|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3331|       |
 3332|  1.59k|		if (taglen == 0)
  ------------------
  |  Branch (3332:7): [True: 11, False: 1.58k]
  ------------------
 3333|  1.59k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3334|       |
 3335|  1.58k|		if (compressed) {
  ------------------
  |  Branch (3335:7): [True: 16, False: 1.56k]
  ------------------
 3336|     16|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  152|     16|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3337|     16|		}
 3338|       |		/* internal certificate remains compressed */
 3339|  1.58k|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3339:7): [True: 0, False: 1.58k]
  ------------------
 3340|  1.58k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|  1.58k|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3343|  1.58k|		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|  1.58k|	} 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|  1.58k|	sc_log(card->ctx, "added #%d internal %p:%zu",
  ------------------
  |  |   71|  1.58k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3387|  1.58k|			enumtag,
 3388|  1.58k|			priv->obj_cache[enumtag].internal_obj_data,
 3389|  1.58k|			priv->obj_cache[enumtag].internal_obj_len);
 3390|       |
 3391|  1.58k|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3392|  1.58k|}
card-piv.c:piv_finish:
 5474|  10.4k|{
 5475|  10.4k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  10.4k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5476|  10.4k|	int i;
 5477|       |
 5478|  10.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.4k]
  |  |  ------------------
  ------------------
 5479|  10.4k|	if (priv) {
  ------------------
  |  Branch (5479:6): [True: 5.71k, False: 4.68k]
  ------------------
 5480|  5.71k|		if (priv->context_specific) {
  ------------------
  |  Branch (5480:7): [True: 1, False: 5.71k]
  ------------------
 5481|      1|			sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5482|      1|			priv->context_specific = 0;
 5483|      1|			sc_unlock(card);
 5484|      1|		}
 5485|  5.71k|		free(priv->aid_der.value);
 5486|  5.71k|		free(priv->al_label);
 5487|  5.71k|		if (priv->w_buf)
  ------------------
  |  Branch (5487:7): [True: 0, False: 5.71k]
  ------------------
 5488|      0|			free(priv->w_buf);
 5489|  5.71k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5489:7): [True: 61, False: 5.65k]
  ------------------
 5490|     61|			free(priv->offCardCertURL);
 5491|   348k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5491:15): [True: 343k, False: 5.71k]
  ------------------
 5492|   343k|			piv_obj_cache_free_entry(card, i, 0);
 5493|   343k|		}
 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.71k|		free(priv);
 5501|       |		card->drv_data = NULL; /* priv */
 5502|  5.71k|	}
 5503|  10.4k|	return 0;
 5504|  10.4k|}
card-piv.c:piv_select_file:
 4908|  9.89k|{
 4909|  9.89k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  9.89k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4910|  9.89k|	int r;
 4911|  9.89k|	int i;
 4912|  9.89k|	const u8 *path;
 4913|  9.89k|	size_t pathlen;
 4914|  9.89k|	sc_file_t *file = NULL;
 4915|  9.89k|	u8 *rbuf = NULL;
 4916|  9.89k|	size_t rbuflen = 0;
 4917|       |
 4918|  9.89k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.89k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.89k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.89k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.89k]
  |  |  ------------------
  ------------------
 4919|       |
 4920|  9.89k|	path = in_path->value;
 4921|  9.89k|	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|  9.89k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (4932:6): [True: 2.67k, False: 7.21k]
  ------------------
 4933|  2.67k|		if (pathlen > 2) {
  ------------------
  |  Branch (4933:7): [True: 2.67k, False: 0]
  ------------------
 4934|  2.67k|			path += 2;
 4935|  2.67k|			pathlen -= 2;
 4936|  2.67k|		}
 4937|  2.67k|	}
 4938|       |
 4939|  9.89k|	i = piv_find_obj_by_containerid(card, path);
 4940|       |
 4941|  9.89k|	if (i < 0)
  ------------------
  |  Branch (4941:6): [True: 2.70k, False: 7.19k]
  ------------------
 4942|  9.89k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  2.70k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.70k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.70k|	int _ret = r; \
  |  |  |  |  155|  2.70k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.70k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.70k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.70k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.70k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.70k|	return _ret; \
  |  |  |  |  163|  2.70k|} 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|  7.19k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (4949:28): [True: 7.19k, False: 0]
  |  Branch (4949:44): [True: 7.19k, False: 0]
  |  Branch (4949:63): [True: 7.19k, False: 0]
  ------------------
 4950|       |
 4951|  7.19k|	priv->selected_obj = i;
 4952|  7.19k|	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|  7.19k|	if (file_out) {
  ------------------
  |  Branch (4957:6): [True: 7.19k, False: 0]
  ------------------
 4958|       |		/* we need to read it now, to get length into cache */
 4959|  7.19k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 4960|       |
 4961|  7.19k|		if (r < 0)
  ------------------
  |  Branch (4961:7): [True: 5.43k, False: 1.76k]
  ------------------
 4962|  7.19k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  5.43k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.43k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.43k|	int _ret = r; \
  |  |  |  |  155|  5.43k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.43k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.43k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.43k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.43k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.43k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.43k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.43k|	return _ret; \
  |  |  |  |  163|  5.43k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4963|       |
 4964|       |		/* get the cert or the pub key out and into the cache too */
 4965|  1.76k|		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: 1.76k, False: 0]
  |  Branch (4965:33): [True: 0, False: 0]
  ------------------
 4966|  1.76k|			r = piv_cache_internal_data(card, i);
 4967|  1.76k|			if (r < 0)
  ------------------
  |  Branch (4967:8): [True: 182, False: 1.58k]
  ------------------
 4968|  1.76k|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    182|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    182|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    182|	int _ret = r; \
  |  |  |  |  155|    182|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 182, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    182|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    182|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 182, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    182|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    182|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    182|	return _ret; \
  |  |  |  |  163|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4969|  1.76k|		}
 4970|       |
 4971|  1.58k|		file = sc_file_new();
 4972|  1.58k|		if (file == NULL)
  ------------------
  |  Branch (4972:7): [True: 0, False: 1.58k]
  ------------------
 4973|  1.58k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|  1.58k|		file->path = *in_path;
 4976|       |		/* this could be like the FCI */
 4977|  1.58k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  1.58k|#define SC_FILE_TYPE_DF			0x04
  ------------------
 4978|  1.58k|		file->shareable = 0;
 4979|  1.58k|		file->ef_structure = 0;
 4980|  1.58k|		if (priv->return_only_cert)
  ------------------
  |  Branch (4980:7): [True: 1.58k, False: 0]
  ------------------
 4981|  1.58k|			file->size = priv->obj_cache[i].internal_obj_len;
 4982|      0|		else
 4983|      0|			file->size = priv->obj_cache[i].obj_len;
 4984|       |
 4985|  1.58k|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 4986|       |
 4987|  1.58k|		*file_out = file;
 4988|  1.58k|	}
 4989|       |
 4990|  1.58k|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4991|  1.58k|}
card-piv.c:piv_find_obj_by_containerid:
 1770|  74.1k|{
 1771|  74.1k|	int i;
 1772|       |
 1773|  74.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  74.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  74.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  74.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  74.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 74.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1774|  74.1k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  74.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__
  |  |  ------------------
  ------------------
 1775|       |
 1776|  1.56M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1776:14): [True: 1.55M, False: 3.74k]
  ------------------
 1777|  1.55M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1777:7): [True: 636k, False: 922k]
  |  Branch (1777:50): [True: 70.4k, False: 566k]
  ------------------
 1778|  1.55M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  70.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  70.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  70.4k|	int _ret = r; \
  |  |  |  |  155|  70.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.03k, False: 69.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  69.4k|	} else { \
  |  |  |  |  159|  69.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  69.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  69.4k|	} \
  |  |  |  |  162|  70.4k|	return _ret; \
  |  |  |  |  163|  70.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|  1.55M|	}
 1780|       |
 1781|  3.74k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  3.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.74k|	int _ret = r; \
  |  |  |  |  155|  3.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.74k|	return _ret; \
  |  |  |  |  163|  3.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|  3.74k|}
card-piv.c:piv_get_challenge:
 4611|    420|{
 4612|       |	/* Dynamic Authentication Template (Challenge) */
 4613|    420|	u8 sbuf[] = {0x7c, 0x02, 0x81, 0x00};
 4614|    420|	u8 rbuf[4096];
 4615|    420|	const u8 *p;
 4616|    420|	size_t out_len = 0;
 4617|    420|	int r;
 4618|    420|	unsigned int tag_out = 0, cla_out = 0;
 4619|    420|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    420|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4620|       |
 4621|    420|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    420|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    420|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    420|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    420|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 420]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4622|       |
 4623|    420|	if (priv->card_issues & CI_NO_RANDOM) {
  ------------------
  |  |  587|    420|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (4623:6): [True: 5, False: 415]
  ------------------
 4624|      5|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      5|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4625|      5|		LOG_TEST_GOTO_ERR(card->ctx, r, "No support for random data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4626|      5|	}
 4627|       |
 4628|       |	/* NIST 800-73-3 says use 9B, previous versions used 00 */
 4629|    415|	r = piv_general_io(card, 0x87, 0x00, 0x9B, sbuf, sizeof sbuf, rbuf, sizeof rbuf);
 4630|       |	/*
 4631|       |	 * piv_get_challenge is called in a loop.
 4632|       |	 * some cards may allow 1 challenge expecting it to be part of
 4633|       |	 * NIST 800-73-3 part 2 "Authentication of PIV Card Application Administrator"
 4634|       |	 * and return "6A 80" if last command was a get_challenge.
 4635|       |	 * Now that the card returned error, we can try one more time.
 4636|       |	 */
 4637|    415|	if (r == SC_ERROR_INCORRECT_PARAMETERS) {
  ------------------
  |  |   55|    415|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (4637:6): [True: 78, False: 337]
  ------------------
 4638|     78|		r = piv_general_io(card, 0x87, 0x00, 0x9B, sbuf, sizeof sbuf, rbuf, sizeof rbuf);
 4639|     78|		if (r == SC_ERROR_INCORRECT_PARAMETERS) {
  ------------------
  |  |   55|     78|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (4639:7): [True: 1, False: 77]
  ------------------
 4640|      1|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4641|      1|		}
 4642|     78|	}
 4643|    415|	LOG_TEST_GOTO_ERR(card->ctx, r, "GENERAL AUTHENTICATE failed");
  ------------------
  |  |  184|    415|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    415|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    415|	int _ret = (r); \
  |  |  |  |  178|    415|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 148, False: 267]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    148|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    148|		goto err; \
  |  |  |  |  182|    148|	} \
  |  |  |  |  183|    415|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 267]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4644|       |
 4645|    267|	p = rbuf;
 4646|    267|	r = sc_asn1_read_tag(&p, r, &cla_out, &tag_out, &out_len);
 4647|    267|	if (r < 0 || (cla_out | tag_out) != 0x7C) {
  ------------------
  |  Branch (4647:6): [True: 7, False: 260]
  |  Branch (4647:15): [True: 6, False: 254]
  ------------------
 4648|     13|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find Dynamic Authentication Template");
  ------------------
  |  |  184|     13|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     13|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     13|	int _ret = (r); \
  |  |  |  |  178|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     13|		goto err; \
  |  |  |  |  182|     13|	} \
  |  |  |  |  183|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4649|     13|	}
 4650|       |
 4651|    254|	r = sc_asn1_read_tag(&p, out_len, &cla_out, &tag_out, &out_len);
 4652|    254|	if (r < 0 || (cla_out | tag_out) != 0x81) {
  ------------------
  |  Branch (4652:6): [True: 1, False: 253]
  |  Branch (4652:15): [True: 7, False: 246]
  ------------------
 4653|      8|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find Challenge");
  ------------------
  |  |  184|      8|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      8|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      8|	int _ret = (r); \
  |  |  |  |  178|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      8|		goto err; \
  |  |  |  |  182|      8|	} \
  |  |  |  |  183|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4654|      8|	}
 4655|       |
 4656|    246|	if (len < out_len) {
  ------------------
  |  Branch (4656:6): [True: 2, False: 244]
  ------------------
 4657|      2|		out_len = len;
 4658|      2|	}
 4659|    246|	memcpy(rnd, p, out_len);
 4660|       |
 4661|    246|	r = (int)out_len;
 4662|       |
 4663|    420|err:
 4664|    420|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    420|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    420|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    420|	int _ret = r; \
  |  |  |  |  155|    420|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 174, False: 246]
  |  |  |  |  ------------------
  |  |  |  |  156|    174|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    161|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 161, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|    174|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    246|	} else { \
  |  |  |  |  159|    246|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    246|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    246|	} \
  |  |  |  |  162|    420|	return _ret; \
  |  |  |  |  163|    420|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4665|    420|}
card-piv.c:piv_read_binary:
 3401|  3.23k|{
 3402|  3.23k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  3.23k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3403|  3.23k|	int enumtag;
 3404|  3.23k|	int r;
 3405|  3.23k|	u8 *rbuf = NULL;
 3406|  3.23k|	size_t rbuflen = 0;
 3407|  3.23k|	const u8 *body;
 3408|  3.23k|	size_t bodylen;
 3409|       |
 3410|  3.23k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.23k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.23k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.23k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.23k]
  |  |  ------------------
  ------------------
 3411|  3.23k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3411:6): [True: 0, False: 3.23k]
  ------------------
 3412|  3.23k|		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|  3.23k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3414|       |
 3415|  3.23k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3415:6): [True: 1.58k, False: 1.65k]
  ------------------
 3416|  1.58k|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3417|       |
 3418|  1.58k|		if (r >= 0) {
  ------------------
  |  Branch (3418:7): [True: 1.58k, False: 0]
  ------------------
 3419|       |			/* an object with no data will be considered not found */
 3420|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3421|  1.58k|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3421:8): [True: 0, False: 1.58k]
  |  Branch (3421:17): [True: 0, False: 1.58k]
  |  Branch (3421:37): [True: 1.58k, False: 0]
  |  Branch (3421:65): [True: 0, False: 1.58k]
  ------------------
 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|  1.58k|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3427|  1.58k|			if (body == NULL) {
  ------------------
  |  Branch (3427:8): [True: 0, False: 1.58k]
  ------------------
 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|  1.58k|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3434:8): [True: 0, False: 1.58k]
  ------------------
 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|  1.58k|			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: 1.58k, False: 0]
  |  Branch (3441:34): [True: 0, False: 0]
  ------------------
 3442|  1.58k|				r = piv_cache_internal_data(card, enumtag);
 3443|  1.58k|				if (r < 0)
  ------------------
  |  Branch (3443:9): [True: 0, False: 1.58k]
  ------------------
 3444|      0|					goto err;
 3445|  1.58k|			}
 3446|  1.58k|		}
 3447|  1.58k|		priv->rwb_state = 0;
 3448|  1.58k|	}
 3449|       |
 3450|  3.23k|	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: 3.23k, False: 0]
  |  Branch (3450:32): [True: 0, False: 0]
  ------------------
 3451|  3.23k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3452|  3.23k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3453|  3.23k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  152|  3.23k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3453:7): [True: 56, False: 3.18k]
  |  Branch (3453:70): [True: 56, False: 0]
  ------------------
 3454|     56|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     56|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3455|     56|		}
 3456|  3.23k|	} 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|  3.23k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3462:6): [True: 0, False: 3.23k]
  ------------------
 3463|      0|		count = rbuflen - idx;
 3464|  3.23k|	if (count <= 0) {
  ------------------
  |  Branch (3464:6): [True: 0, False: 3.23k]
  ------------------
 3465|      0|		r = 0;
 3466|      0|		priv->rwb_state = 1;
 3467|  3.23k|	} else {
 3468|  3.23k|		memcpy(buf, rbuf + idx, count);
 3469|  3.23k|		r = (int)count;
 3470|  3.23k|	}
 3471|       |
 3472|  3.23k|err:
 3473|  3.23k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.23k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.23k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.23k|	int _ret = r; \
  |  |  |  |  155|  3.23k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 3.23k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.23k|	} else { \
  |  |  |  |  159|  3.23k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.23k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.23k|	} \
  |  |  |  |  162|  3.23k|	return _ret; \
  |  |  |  |  163|  3.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3474|  3.23k|}
card-piv.c:piv_set_security_env:
 4669|     24|{
 4670|     24|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     24|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4671|     24|	int r = 0;
 4672|       |
 4673|     24|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     24|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     24|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     24|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24]
  |  |  ------------------
  ------------------
 4674|       |
 4675|     24|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4676|     24|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4677|     24|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4678|       |
 4679|     24|	priv->operation = env->operation;
 4680|     24|	priv->algorithm = env->algorithm;
 4681|       |
 4682|     24|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|     24|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4682:6): [True: 0, False: 24]
  ------------------
 4683|      0|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4684|     24|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|     24|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4684:13): [True: 24, False: 0]
  ------------------
 4685|     24|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|     24|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4685:7): [True: 24, False: 0]
  ------------------
 4686|     24|			switch (env->algorithm_ref) {
 4687|     24|			case 256:
  ------------------
  |  Branch (4687:4): [True: 24, False: 0]
  ------------------
 4688|     24|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4689|     24|				priv->key_size = 256;
 4690|     24|				break;
 4691|      0|			case 384:
  ------------------
  |  Branch (4691:4): [True: 0, False: 24]
  ------------------
 4692|      0|				priv->alg_id = 0x14;
 4693|      0|				priv->key_size = 384;
 4694|      0|				break;
 4695|      0|			default:
  ------------------
  |  Branch (4695:4): [True: 0, False: 24]
  ------------------
 4696|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4697|     24|			}
 4698|     24|		} else
 4699|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4700|     24|	} 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|     24|	priv->key_ref = env->key_ref[0];
 4709|       |
 4710|     24|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     24|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4711|     24|}
card-piv.c:piv_compute_signature:
 4839|     24|{
 4840|     24|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     24|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4841|     24|	int r;
 4842|     24|	size_t nLen;
 4843|     24|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4844|       |
 4845|     24|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     24|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     24|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     24|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24]
  |  |  ------------------
  ------------------
 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|     24|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4854:6): [True: 24, False: 0]
  |  Branch (4854:30): [True: 0, False: 0]
  ------------------
 4855|     24|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|     24|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4856|     24|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4856:7): [True: 0, False: 24]
  ------------------
 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|     24|		r = piv_validate_general_authentication(card, data, datalen, rbuf, sizeof rbuf);
 4864|     24|		if (r < 0)
  ------------------
  |  Branch (4864:7): [True: 12, False: 12]
  ------------------
 4865|     12|			goto err;
 4866|       |
 4867|     12|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4868|       |		/* Yubikey 5.7.x supports ED25519 */
 4869|     12|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4869:13): [True: 0, False: 0]
  ------------------
 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|      0|	} else { /* RSA is all set */
 4880|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4881|      0|	}
 4882|       |
 4883|     24|err:
 4884|     24|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
 4885|     24|}
card-piv.c:piv_validate_general_authentication:
 4742|     24|{
 4743|     24|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     24|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4744|     24|	int r, tmplen, tmplen2;
 4745|     24|	u8 *p;
 4746|     24|	const unsigned char *p2;
 4747|     24|	size_t taglen;
 4748|     24|	size_t bodylen;
 4749|     24|	unsigned int cla, tag;
 4750|     24|	unsigned int real_alg_id, op_tag;
 4751|       |
 4752|     24|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4753|     24|	size_t sbuflen = sizeof(sbuf);
 4754|     24|	u8 rbuf[4096];
 4755|       |
 4756|     24|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     24|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     24|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     24|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24]
  |  |  ------------------
  ------------------
 4757|       |
 4758|       |	/* should assume large send data */
 4759|     24|	p = sbuf;
 4760|     24|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4761|     24|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4762|     24|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4762:6): [True: 0, False: 24]
  |  Branch (4762:21): [True: 0, False: 24]
  ------------------
 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|     24|	tmplen += tmplen2;
 4766|     24|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|     48|#define SC_SUCCESS				0
  ------------------
  |  Branch (4766:6): [True: 0, False: 24]
  ------------------
 4767|     24|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
  |  Branch (4767:4): [True: 0, False: 24]
  ------------------
 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|     24|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   50|     48|#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: 24]
  |  Branch (4770:53): [True: 0, False: 0]
  |  Branch (4770:91): [True: 0, False: 0]
  ------------------
 4771|      0|		op_tag = 0x85;
 4772|     24|	} else {
 4773|     24|		op_tag = 0x81;
 4774|     24|	}
 4775|     24|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4776|     24|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
  |  Branch (4776:6): [True: 0, False: 24]
  ------------------
 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|     24|	real_alg_id = priv->alg_id;
 4788|     24|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4788:6): [True: 0, False: 24]
  ------------------
 4789|      0|		switch (datalen) {
 4790|      0|		case 128:
  ------------------
  |  Branch (4790:3): [True: 0, False: 0]
  ------------------
 4791|      0|			real_alg_id = 0x06;
 4792|      0|			break;
 4793|      0|		case 256:
  ------------------
  |  Branch (4793:3): [True: 0, False: 0]
  ------------------
 4794|      0|			real_alg_id = 0x07;
 4795|      0|			break;
 4796|      0|		case 384:
  ------------------
  |  Branch (4796:3): [True: 0, False: 0]
  ------------------
 4797|      0|			real_alg_id = 0x05;
 4798|      0|			break;
 4799|      0|		case 512:
  ------------------
  |  Branch (4799:3): [True: 0, False: 0]
  ------------------
 4800|      0|			real_alg_id = 0x16;
 4801|      0|			break;
 4802|      0|		default:
  ------------------
  |  Branch (4802:3): [True: 0, False: 0]
  ------------------
 4803|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4804|      0|		}
 4805|      0|	}
 4806|       |	/* EC and ED alg_id was already set */
 4807|       |
 4808|     24|	piv_yk_notify_touch_policy(card, priv->key_ref);
 4809|     24|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4810|     24|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4811|     24|	if (r < 0)
  ------------------
  |  Branch (4811:6): [True: 9, False: 15]
  ------------------
 4812|      9|		goto err;
 4813|       |
 4814|     15|	p2 = rbuf;
 4815|     15|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4816|     15|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4816:6): [True: 1, False: 14]
  |  Branch (4816:20): [True: 1, False: 13]
  |  Branch (4816:29): [True: 1, False: 12]
  |  Branch (4816:45): [True: 5, False: 7]
  ------------------
 4817|      8|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x7C");
  ------------------
  |  |  184|      8|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      8|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      8|	int _ret = (r); \
  |  |  |  |  178|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      8|		goto err; \
  |  |  |  |  182|      8|	} \
  |  |  |  |  183|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4818|      8|	}
 4819|       |
 4820|      7|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4821|      7|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4821:6): [True: 1, False: 6]
  |  Branch (4821:20): [True: 1, False: 5]
  |  Branch (4821:29): [True: 1, False: 4]
  |  Branch (4821:44): [True: 1, False: 3]
  ------------------
 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|      3|	if (taglen > outlen) {
  ------------------
  |  Branch (4825:6): [True: 0, False: 3]
  ------------------
 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|      3|	memcpy(out, p2, taglen);
 4830|      3|	r = (int)taglen;
 4831|       |
 4832|     24|err:
 4833|     24|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} 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|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4834|     24|}
card-piv.c:piv_yk_notify_touch_policy:
 4723|     24|{
 4724|     24|	u8 touch_policy;
 4725|     24|	const char *title = "Touch your Yubikey to continue";
 4726|       |
 4727|     24|	piv_yk_get_metadata(card, key_ref, NULL, &touch_policy);
 4728|     24|	switch (touch_policy) {
  ------------------
  |  Branch (4728:10): [True: 2, False: 22]
  ------------------
 4729|      1|	case 0x02:
  ------------------
  |  Branch (4729:2): [True: 1, False: 23]
  ------------------
 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: 23]
  ------------------
 4733|      1|		sc_notify(title, "Touching the token is required unlocking the key (needed again after 15 seconds)");
 4734|      1|		break;
 4735|     24|	}
 4736|     24|}
card-piv.c:piv_yk_get_metadata:
 4504|  1.52k|{
 4505|  1.52k|	sc_apdu_t apdu;
 4506|  1.52k|	u8 resp[100];
 4507|  1.52k|	size_t i;
 4508|  1.52k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.52k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4509|       |
 4510|       |	/* initialize with the default behaviour */
 4511|  1.52k|	if (pin_policy)
  ------------------
  |  Branch (4511:6): [True: 1.50k, False: 24]
  ------------------
 4512|  1.50k|		*pin_policy = 0x00;
 4513|  1.52k|	if (touch_policy)
  ------------------
  |  Branch (4513:6): [True: 24, False: 1.50k]
  ------------------
 4514|     24|		*touch_policy = 0x00;
 4515|       |
 4516|  1.52k|	if (priv->yubico_version < 0x00050300) {
  ------------------
  |  Branch (4516:6): [True: 1.13k, False: 390]
  ------------------
 4517|  1.13k|		if (priv->yubico_version != 0)
  ------------------
  |  Branch (4517:7): [True: 54, False: 1.08k]
  ------------------
 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|  1.13k|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  1.13k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4520|  1.13k|	}
 4521|       |
 4522|    396|	for (i = 0; i < (sizeof(priv->yk_pin) / sizeof(*priv->yk_pin) - 1); i++) {
  ------------------
  |  Branch (4522:14): [True: 396, False: 0]
  ------------------
 4523|    396|		if (priv->yk_pin[i].slot == 0x00)
  ------------------
  |  Branch (4523:7): [True: 388, False: 8]
  ------------------
 4524|       |			/* reached the last initialized entry */
 4525|    388|			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|    390|	if (priv->yk_pin[i].slot == 0x00) {
  ------------------
  |  Branch (4532:6): [True: 388, False: 2]
  ------------------
 4533|       |		/* initialize this entry */
 4534|    388|		sc_format_apdu_ex(&apdu, 0x00, 0xF7, 0x00, slot, NULL, 0, resp, sizeof resp);
 4535|    388|		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|    388|#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|    377|#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|     36|#define SC_SUCCESS				0
  ------------------
  |  Branch (4535:7): [True: 377, False: 11]
  |  Branch (4535:54): [True: 36, False: 341]
  |  Branch (4535:109): [True: 11, False: 25]
  ------------------
 4536|     11|			sc_log(card->ctx, "PIN policy for slot 0x%02X: 0x%02X (touch 0x%02X)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4537|     11|					slot, priv->yk_pin[i].policy, priv->yk_pin[i].touch);
 4538|     11|			priv->yk_pin[i].slot = slot;
 4539|    377|		} else {
 4540|    377|			sc_log(card->ctx, "Could not get Yubikey's PIN and touch policy");
  ------------------
  |  |   71|    377|#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|    377|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    377|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4542|    377|		}
 4543|    388|	} 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|     13|	if (pin_policy)
  ------------------
  |  Branch (4548:6): [True: 11, False: 2]
  ------------------
 4549|     11|		*pin_policy = priv->yk_pin[i].policy;
 4550|     13|	if (touch_policy)
  ------------------
  |  Branch (4550:6): [True: 2, False: 11]
  ------------------
 4551|      2|		*touch_policy = priv->yk_pin[i].touch;
 4552|       |
 4553|     13|	return SC_SUCCESS;
  ------------------
  |  |   28|     13|#define SC_SUCCESS				0
  ------------------
 4554|    390|}
card-piv.c:piv_yk_metadata_get_policy:
 4489|     36|{
 4490|     36|	size_t policylen;
 4491|     36|	const u8 *policy = sc_asn1_find_tag(ctx, buf, buflen, 0x02, &policylen);
 4492|     36|	if (policy && policylen == 2) {
  ------------------
  |  Branch (4492:6): [True: 14, False: 22]
  |  Branch (4492:16): [True: 11, False: 3]
  ------------------
 4493|     11|		*pin = policy[0];
 4494|     11|		*touch = policy[1];
 4495|     11|		return SC_SUCCESS;
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
 4496|     25|	} else {
 4497|     25|		sc_log(ctx, "Yubikey PIN policy not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4498|     25|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     25|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4499|     25|	}
 4500|     36|}
card-piv.c:piv_check_sw:
 6167|  20.5k|{
 6168|  20.5k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6169|       |
 6170|  20.5k|	int r;
 6171|       |#ifdef ENABLE_PIV_SM
 6172|       |	int i;
 6173|       |#endif
 6174|  20.5k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  20.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6175|       |
 6176|  20.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  20.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  20.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  20.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 20.5k]
  |  |  ------------------
  ------------------
 6177|       |
 6178|       |	/* may be called before piv_init has allocated priv */
 6179|  20.5k|	if (priv) {
  ------------------
  |  Branch (6179:6): [True: 20.5k, False: 0]
  ------------------
 6180|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6181|       |
 6182|  20.5k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6182:7): [True: 628, False: 19.9k]
  ------------------
 6183|    628|			priv->pin_cmd_verify_sw1 = sw1;
 6184|    628|			priv->pin_cmd_verify_sw2 = sw2;
 6185|  19.9k|		} 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|  19.9k|			if (priv->context_specific) {
  ------------------
  |  Branch (6190:8): [True: 1, False: 19.9k]
  ------------------
 6191|      1|				sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6192|      1|				priv->context_specific = 0;
 6193|      1|				sc_unlock(card);
 6194|      1|			}
 6195|  19.9k|		}
 6196|       |
 6197|  20.5k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  584|  20.5k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6197:7): [True: 945, False: 19.5k]
  ------------------
 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|    945|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6203:8): [True: 75, False: 870]
  |  Branch (6203:32): [True: 13, False: 62]
  ------------------
 6204|     13|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6205|     13|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6205:9): [True: 3, False: 10]
  ------------------
 6206|      3|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6207|      3|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      3|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6208|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6209|      3|				}
 6210|     13|			}
 6211|    945|		}
 6212|  20.5k|	}
 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|  20.5k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6226|  20.5k|	return r;
 6227|  20.5k|}
card-piv.c:piv_card_ctl:
 4565|  68.8k|{
 4566|  68.8k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  68.8k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4567|  68.8k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4568|       |
 4569|  68.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  68.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  68.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  68.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  68.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 68.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4570|       |
 4571|  68.8k|	if (priv == NULL) {
  ------------------
  |  Branch (4571:6): [True: 0, False: 68.8k]
  ------------------
 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|  68.8k|	switch (cmd) {
  ------------------
  |  Branch (4574:10): [True: 67.8k, False: 1.02k]
  ------------------
 4575|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4575:2): [True: 0, False: 68.8k]
  ------------------
 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: 68.8k]
  ------------------
 4589|      0|		return piv_generate_key(card,
 4590|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4591|      0|		break;
 4592|  1.03k|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4592:2): [True: 1.03k, False: 67.8k]
  ------------------
 4593|  1.03k|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4594|      0|		break;
 4595|  1.03k|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4595:2): [True: 1.03k, False: 67.8k]
  ------------------
 4596|  1.03k|		return piv_get_pin_preference(card, ptr);
 4597|      0|		break;
 4598|  64.2k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4598:2): [True: 64.2k, False: 4.60k]
  ------------------
 4599|  64.2k|		return piv_is_object_present(card, ptr);
 4600|      0|		break;
 4601|  1.50k|	case SC_CARDCTL_PIV_YK_PIN_POLICY:
  ------------------
  |  Branch (4601:2): [True: 1.50k, False: 67.3k]
  ------------------
 4602|  1.50k|		return piv_yk_pin_policy(card, ptr);
 4603|      0|		break;
 4604|  68.8k|	}
 4605|       |
 4606|  1.02k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  1.02k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.02k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.02k|	int _ret = r; \
  |  |  |  |  155|  1.02k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.02k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.02k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.02k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.02k|	return _ret; \
  |  |  |  |  163|  1.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4607|  1.02k|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4369|  1.03k|{
 4370|  1.03k|	int r;
 4371|  1.03k|	int i;
 4372|  1.03k|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4373|  1.03k|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4374|  1.03k|	u8 *rbuf = NULL;
 4375|  1.03k|	const u8 *body;
 4376|  1.03k|	const u8 *fascn;
 4377|  1.03k|	const u8 *guid;
 4378|  1.03k|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4379|       |
 4380|  1.03k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.03k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.03k]
  |  |  ------------------
  ------------------
 4381|  1.03k|	if (card->serialnr.len) {
  ------------------
  |  Branch (4381:6): [True: 0, False: 1.03k]
  ------------------
 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|  1.03k|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4394|  1.03k|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|  1.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.03k|	int _ret = (r); \
  |  |  |  |  168|  1.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 909, False: 128]
  |  |  |  |  ------------------
  |  |  |  |  169|    909|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    909|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    909|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    909|		return _ret; \
  |  |  |  |  172|    909|	} \
  |  |  |  |  173|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 128]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4395|       |
 4396|    128|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    128|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4397|    128|	if (rbuflen != 0) {
  ------------------
  |  Branch (4397:6): [True: 128, False: 0]
  ------------------
 4398|    128|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4399|    128|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4399:7): [True: 128, False: 0]
  |  Branch (4399:23): [True: 126, False: 2]
  |  Branch (4399:39): [True: 126, False: 0]
  ------------------
 4400|    126|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4401|       |
 4402|    126|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4402:8): [True: 45, False: 81]
  |  Branch (4402:17): [True: 32, False: 13]
  ------------------
 4403|    832|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4403:17): [True: 800, False: 32]
  ------------------
 4404|    800|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4404:14): [True: 639, False: 161]
  |  Branch (4404:23): [True: 31, False: 130]
  ------------------
 4405|    800|				}
 4406|     32|			}
 4407|       |
 4408|    126|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4409|       |
 4410|    126|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4410:8): [True: 18, False: 108]
  |  Branch (4410:16): [True: 14, False: 4]
  ------------------
 4411|    238|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4411:17): [True: 224, False: 14]
  ------------------
 4412|    224|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4413|    224|				}
 4414|     14|			}
 4415|    126|			sc_log(card->ctx, "fascn=%p,fascnlen=%zu,guid=%p,guidlen=%zu,gbits=%2.2x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4416|    126|					fascn, fascnlen, guid, guidlen, gbits);
 4417|       |
 4418|    126|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4418:8): [True: 45, False: 81]
  |  Branch (4418:17): [True: 32, False: 13]
  |  Branch (4418:35): [True: 31, 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|     31|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4421:11): [True: 13, False: 18]
  |  Branch (4421:20): [True: 10, False: 3]
  |  Branch (4421:40): [True: 8, False: 2]
  ------------------
 4422|     30|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4422:11): [True: 2, False: 6]
  |  Branch (4422:31): [True: 1, False: 1]
  ------------------
 4423|       |					/* fascnlen is 25 */
 4424|     30|					serial->len = fascnlen;
 4425|     30|					memcpy(serial->value, fascn, serial->len);
 4426|     30|					r = SC_SUCCESS;
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
 4427|     30|					gbits = 0; /* set to skip using guid below */
 4428|     30|				}
 4429|     31|			}
 4430|    126|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4430:8): [True: 18, False: 108]
  |  Branch (4430:16): [True: 14, False: 4]
  |  Branch (4430:33): [True: 2, False: 12]
  ------------------
 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|    126|		}
 4436|    128|	}
 4437|       |
 4438|    128|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4438:6): [True: 97, False: 31]
  |  Branch (4438:20): [True: 96, False: 1]
  ------------------
 4439|     96|		serial->len = 16;
 4440|     96|		memset(serial->value, 0x00, serial->len);
 4441|     96|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     96|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4442|     96|	}
 4443|       |
 4444|    128|	card->serialnr = *serial;
 4445|    128|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    128|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    128|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    128|	int _ret = r; \
  |  |  |  |  155|    128|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 128, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    128|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 96, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|    128|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    128|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    128|	return _ret; \
  |  |  |  |  163|    128|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4446|    128|}
card-piv.c:piv_get_pin_preference:
 4480|  1.03k|{
 4481|  1.03k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.03k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4482|       |
 4483|  1.03k|	*pin_ref = priv->pin_preference;
 4484|  1.03k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.03k|	int _ret = r; \
  |  |  |  |  155|  1.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.03k|	return _ret; \
  |  |  |  |  163|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4485|  1.03k|}
card-piv.c:piv_is_object_present:
 4461|  64.2k|{
 4462|  64.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  64.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4463|  64.2k|	int r = 0;
 4464|  64.2k|	int enumtag;
 4465|       |
 4466|  64.2k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4467|  64.2k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  153|  63.2k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4467:6): [True: 63.2k, False: 1.03k]
  |  Branch (4467:22): [True: 39.2k, False: 23.9k]
  ------------------
 4468|  39.2k|		r = 1;
 4469|       |
 4470|  64.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  64.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  64.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  64.2k|	int _ret = r; \
  |  |  |  |  155|  64.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25.0k, False: 39.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|  25.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 25.0k]
  |  |  |  |  ------------------
  |  |  |  |  157|  25.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  39.2k|	} else { \
  |  |  |  |  159|  39.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  39.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  39.2k|	} \
  |  |  |  |  162|  64.2k|	return _ret; \
  |  |  |  |  163|  64.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4471|  64.2k|}
card-piv.c:piv_yk_pin_policy:
 4558|  1.50k|{
 4559|  1.50k|	u8 slot = *ptr;
 4560|  1.50k|	LOG_FUNC_RETURN(card->ctx, piv_yk_get_metadata(card, slot, ptr, NULL));
  ------------------
  |  |  164|  1.50k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.50k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.50k|	int _ret = r; \
  |  |  |  |  155|  1.50k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.50k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.49k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.49k, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.50k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.50k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.50k|	return _ret; \
  |  |  |  |  163|  1.50k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4561|  1.50k|}
card-piv.c:piv_pin_cmd:
 6300|    435|{
 6301|    435|	int r = 0;
 6302|    435|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    435|#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|    435|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6309|       |
 6310|    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]
  |  |  ------------------
  ------------------
 6311|    435|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|    435|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6312|    435|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|    435|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6312:6): [True: 32, False: 403]
  ------------------
 6313|     32|		size_t i = 0;
 6314|     32|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6314:7): [True: 7, False: 25]
  ------------------
 6315|      7|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      7|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6316|      7|		}
 6317|    170|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6317:15): [True: 148, False: 22]
  ------------------
 6318|    148|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6318:8): [True: 3, False: 145]
  ------------------
 6319|      3|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6320|      3|			}
 6321|    148|		}
 6322|     25|	}
 6323|       |
 6324|    425|	priv->pin_cmd_verify_sw1 = 0x00U;
 6325|       |
 6326|    425|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  418|    425|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6326:6): [True: 257, False: 168]
  ------------------
 6327|    257|		data->pin1.logged_in = priv->logged_in;
 6328|    257|		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|    257|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    257|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6334:7): [True: 0, False: 257]
  ------------------
 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|    257|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  432|    257|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6339:7): [True: 0, False: 257]
  ------------------
 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|    257|	}
 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|    425|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  415|    850|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    146|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6359:6): [True: 146, False: 279]
  |  Branch (6359:40): [True: 5, False: 141]
  ------------------
 6360|      5|		priv->context_specific = 1;
 6361|      5|		sc_log(card->ctx, "Starting CONTEXT_SPECIFIC verify");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6362|      5|		r = sc_lock(card);
 6363|      5|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
  |  Branch (6363:7): [True: 0, False: 5]
  ------------------
 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|      5|	}
 6368|       |
 6369|    425|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6370|    425|	r = iso_drv->ops->pin_cmd(card, data);
 6371|    425|	priv->pin_cmd_verify = 0;
 6372|       |
 6373|       |	/* tell user verify not supported on contactless without VCI */
 6374|    425|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6374:6): [True: 11, False: 414]
  |  Branch (6374:42): [True: 1, False: 10]
  ------------------
 6375|      1|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  385|    426|#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|    425|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  415|    850|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6382:6): [True: 146, False: 279]
  |  Branch (6382:40): [True: 97, False: 49]
  |  Branch (6382:49): [True: 3, False: 94]
  ------------------
 6383|      3|		sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6384|      3|		priv->context_specific = 0;
 6385|      3|		sc_unlock(card);
 6386|      3|	}
 6387|       |
 6388|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6389|    425|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  593|    850|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6389:6): [True: 291, False: 134]
  |  Branch (6389:53): [True: 210, False: 81]
  ------------------
 6390|    210|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   71|    210|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6391|    210|		piv_find_aid(card);
 6392|       |
 6393|    210|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6394|    210|		r = iso_drv->ops->pin_cmd(card, data);
 6395|    210|		priv->pin_cmd_verify = 0;
 6396|    210|	}
 6397|       |
 6398|       |	/* If verify worked, we are logged_in */
 6399|    425|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|    425|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6399:6): [True: 146, False: 279]
  ------------------
 6400|    146|		if (r >= 0)
  ------------------
  |  Branch (6400:7): [True: 50, False: 96]
  ------------------
 6401|     50|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|     50|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6402|     96|		else
 6403|     96|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     96|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6404|    146|	}
 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|    425|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|    425|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6409:6): [True: 257, False: 168]
  ------------------
 6410|    257|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  588|    257|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6410:7): [True: 0, False: 257]
  ------------------
 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|    257|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  585|    514|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6413:14): [True: 63, False: 194]
  ------------------
 6414|     63|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6414:5): [True: 6, False: 57]
  ------------------
 6415|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6416|      6|			r = piv_check_protected_objects(card);
 6417|      6|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
  |  Branch (6417:8): [True: 1, False: 5]
  ------------------
 6418|      1|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      1|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6419|      5|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|      5|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6419:13): [True: 5, False: 0]
  ------------------
 6420|      5|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  588|      5|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6420:9): [True: 2, False: 3]
  ------------------
 6421|       |
 6422|      2|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6423|      3|				} else {
 6424|      3|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      3|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6425|      3|				}
 6426|      5|				r = SC_SUCCESS;
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
 6427|      5|			}
 6428|      6|		}
 6429|    257|		priv->logged_in = data->pin1.logged_in;
 6430|    257|		priv->tries_left = data->pin1.tries_left;
 6431|    257|	}
 6432|       |
 6433|    425|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|    425|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6434|    425|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    425|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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|    356|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 356, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6435|    425|}
card-piv.c:piv_check_protected_objects:
 6231|      6|{
 6232|      6|	int r = 0;
 6233|      6|	int i;
 6234|      6|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|      6|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6235|      6|	u8 buf[8]; /* tag of 53 with 82 xx xx  will fit in 4 */
 6236|      6|	u8 *rbuf;
 6237|      6|	size_t buf_len;
 6238|      6|	static int protected_objects[] = {PIV_OBJ_PI, PIV_OBJ_CHF, PIV_OBJ_IRIS_IMAGE};
 6239|       |
 6240|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6241|       |	/*
 6242|       |	 * routine only called from piv_pin_cmd after verify lc=0 did not return 90 00
 6243|       |	 * We will test for a protected object using GET DATA.
 6244|       |	 *
 6245|       |	 * Based on observations, of cards using the GET DATA APDU,
 6246|       |	 * SC_ERROR_SECURITY_STATUS_NOT_SATISFIED  means the PIN not verified,
 6247|       |	 * SC_SUCCESS means PIN has been verified even if it has length 0
 6248|       |	 * SC_ERROR_FILE_NOT_FOUND (which is the bug) does not tell us anything
 6249|       |	 * about the state of the PIN and we will try the next object.
 6250|       |	 *
 6251|       |	 * If we can't determine the security state from this process,
 6252|       |	 * set card_issues CI_CANT_USE_GETDATA_FOR_STATE
 6253|       |	 * and return SC_ERROR_PIN_CODE_INCORRECT
 6254|       |	 * The circumvention is to add a dummy Printed Info object in the card.
 6255|       |	 * so we will have an object to test.
 6256|       |	 *
 6257|       |	 * We save the object's number to use in the future.
 6258|       |	 *
 6259|       |	 */
 6260|      6|	if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6260:6): [True: 6, False: 0]
  ------------------
 6261|     17|		for (i = 0; i < (int)(sizeof(protected_objects) / sizeof(int)); i++) {
  ------------------
  |  Branch (6261:15): [True: 15, False: 2]
  ------------------
 6262|     15|			buf_len = sizeof(buf);
 6263|     15|			rbuf = buf;
 6264|     15|			r = piv_get_data(card, protected_objects[i], &rbuf, &buf_len);
 6265|     15|			if (r >= 0 || r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|     14|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6265:8): [True: 1, False: 14]
  |  Branch (6265:18): [True: 3, False: 11]
  ------------------
 6266|       |
 6267|       |				/* we can use this object next time if needed */
 6268|      4|				priv->object_test_verify = protected_objects[i];
 6269|      4|				break;
 6270|      4|			}
 6271|     15|		}
 6272|      6|		if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6272:7): [True: 2, False: 4]
  ------------------
 6273|       |			/*
 6274|       |			 * none of the objects returned acceptable sw1, sw2
 6275|       |			 */
 6276|      2|			sc_log(card->ctx, "No protected objects found, setting CI_CANT_USE_GETDATA_FOR_STATE");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6277|      2|			priv->card_issues |= CI_CANT_USE_GETDATA_FOR_STATE;
  ------------------
  |  |  588|      2|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
 6278|      2|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      2|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6279|      2|		}
 6280|      6|	} else {
 6281|       |		/* use the one object we found earlier. Test is security status has changed */
 6282|      0|		buf_len = sizeof(buf);
 6283|      0|		rbuf = buf;
 6284|      0|		r = piv_get_data(card, priv->object_test_verify, &rbuf, &buf_len);
 6285|      0|	}
 6286|      6|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|      6|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (6286:6): [True: 0, False: 6]
  ------------------
 6287|      0|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6288|      6|	else if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|      6|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6288:11): [True: 3, False: 3]
  ------------------
 6289|      3|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      3|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6290|      3|	else if (r > 0)
  ------------------
  |  Branch (6290:11): [True: 1, False: 2]
  ------------------
 6291|      1|		r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 6292|       |
 6293|      6|	sc_log(card->ctx, "card->type:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6294|      6|			card->type, priv->card_issues, r, priv->alg_ids);
 6295|      6|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6296|      6|}
card-piv.c:piv_card_reader_lock_obtained:
 6474|  8.43k|{
 6475|  8.43k|	int r = 0;
 6476|  8.43k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6477|  8.43k|	size_t templen = sizeof(temp);
 6478|  8.43k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  440|  8.43k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6479|       |
 6480|  8.43k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  8.43k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  8.43k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  8.43k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8.43k]
  |  |  ------------------
  ------------------
 6481|       |
 6482|       |	/* We have a PCSC transaction and sc_lock */
 6483|  8.43k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6483:6): [True: 5.71k, False: 2.71k]
  |  Branch (6483:22): [True: 1.03k, False: 1.67k]
  ------------------
 6484|  6.75k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  13.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:103): [True: 1.03k, False: 5.71k]
  |  |  ------------------
  ------------------
 6485|  6.75k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6486|  6.75k|		r = 0; /* do nothing, piv_match will take care of it */
 6487|  6.75k|		goto err;
 6488|  6.75k|	}
 6489|       |
 6490|  1.67k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  1.67k|#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|  1.67k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  590|  1.67k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6498:6): [True: 1.44k, False: 234]
  ------------------
 6499|  1.44k|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  1.44k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6500|  1.44k|	} else {
 6501|    234|		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|    234|	}
 6517|       |
 6518|  1.67k|	if (r < 0) {
  ------------------
  |  Branch (6518:6): [True: 1.66k, False: 13]
  ------------------
 6519|  1.66k|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  591|  1.66k|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6519:7): [True: 0, False: 1.66k]
  |  Branch (6519:24): [True: 1.63k, False: 24]
  ------------------
 6520|  1.63k|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6521|  1.63k|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  1.63k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6522|  1.63k|		} else {
 6523|     24|			r = 0; /* can't do anything with this card, hope there was no interference */
 6524|     24|		}
 6525|  1.66k|	}
 6526|       |
 6527|  1.67k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6527:6): [True: 1.46k, False: 208]
  ------------------
 6528|  1.46k|		goto err;
 6529|       |
 6530|    208|	if (was_reset > 0)
  ------------------
  |  Branch (6530:6): [True: 0, False: 208]
  ------------------
 6531|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6532|       |
 6533|    208|	r = 0;
 6534|       |
 6535|  8.43k|err:
 6536|  8.43k|	if (priv)
  ------------------
  |  Branch (6536:6): [True: 2.71k, False: 5.71k]
  ------------------
 6537|  2.71k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  2.71k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6538|  8.43k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  8.43k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.43k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.43k|	int _ret = r; \
  |  |  |  |  155|  8.43k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.43k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.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|  1.46k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.46k, False: 6.96k]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.43k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.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|  8.43k|	return _ret; \
  |  |  |  |  163|  8.43k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6539|  8.43k|}

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

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

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

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

sc_get_skeid_driver:
  179|  15.7k|{
  180|  15.7k|	if (iso_ops == NULL) iso_ops = sc_get_iso7816_driver()->ops;
  ------------------
  |  Branch (180:6): [True: 1, False: 15.7k]
  ------------------
  181|  15.7k|	skeid_ops = *iso_ops;
  182|  15.7k|	skeid_ops.match_card = skeid_match_card;
  183|  15.7k|	skeid_ops.init = skeid_init;
  184|  15.7k|	skeid_ops.set_security_env = skeid_set_security_env;
  185|  15.7k|	skeid_ops.logout = skeid_logout;
  186|  15.7k|	return &skeid_drv;
  187|  15.7k|}
card-skeid.c:skeid_match_card:
   73|  15.2k|{
   74|  15.2k|	if (_sc_match_atr(card, skeid_atrs, &card->type) < 0 || skeid_known_url(card) != SC_SUCCESS)
  ------------------
  |  |   28|     61|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 15.1k, False: 61]
  |  Branch (74:58): [True: 49, False: 12]
  ------------------
   75|  15.2k|		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|  15.2k|}
card-skeid.c:skeid_known_url:
   53|     61|{
   54|     61|	const struct sc_aid skeid_aid_eid = {{0xE8, 0x07, 0x04, 0x00, 0x7F, 0x00, 0x07, 0x03, 0x02}, 9};
   55|     61|	const char *known_url = "\x80\x01\x00\x5F\x50\x28http://www.minv.sk/cif/cif-sk-eid-v3.xml";
   56|     61|	u8 buf[SKEID_KNOWN_URL_LEN];
   57|       |
   58|     61|	sc_path_t url_path;
   59|       |
   60|     61|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     61|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   61|       |
   62|     61|	sc_path_set(&url_path, SC_PATH_TYPE_DF_NAME, skeid_aid_eid.value, skeid_aid_eid.len, 0, 0);
  ------------------
  |  |  118|     61|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|       |
   64|     61|	if (sc_select_file(card, &url_path, NULL) == SC_SUCCESS
  ------------------
  |  |   28|    122|#define SC_SUCCESS				0
  ------------------
  |  Branch (64:6): [True: 32, False: 29]
  ------------------
   65|     32|		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|     32|#define SKEID_KNOWN_URL_LEN 46
  ------------------
              		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|     93|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (65:6): [True: 25, False: 7]
  ------------------
   66|     25|		&& !memcmp(buf, known_url, SKEID_KNOWN_URL_LEN))
  ------------------
  |  |   30|     25|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (66:6): [True: 12, False: 13]
  ------------------
   67|     12|		r = SC_SUCCESS;
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
   68|       |
   69|     61|	return r;
   70|     61|}
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: 8, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|      4|	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|      4|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|      4|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  123|       |
  124|      4|	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|      4|	card->max_send_size = sc_get_max_send_size(card); /* see card-cardos.c */
  135|      4|	card->max_recv_size = data_field_length - 2;
  136|      4|	card->max_recv_size = sc_get_max_recv_size(card);
  137|       |
  138|      4|	r = _sc_card_add_rsa_alg(card, 3072, flags, 0);
  139|       |
  140|      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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|      4|}
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: 1, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|     11|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (94:6): [True: 4, False: 7]
  |  Branch (94:26): [True: 1, False: 6]
  ------------------
   95|      5|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
   96|      6|	if (apdu.resplen == 8) {
  ------------------
  |  Branch (96:6): [True: 4, False: 2]
  ------------------
   97|       |		/* cache serial number */
   98|      4|		memcpy(card->serialnr.value, rbuf, 8);
   99|      4|		card->serialnr.len = 8;
  100|      4|	} else {
  101|      2|		sc_log(card->ctx, "unexpected response to GET DATA serial number");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  102|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
  103|      2|	}
  104|      4|	return SC_SUCCESS;
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
  105|      6|}
card-skeid.c:skeid_set_security_env:
  146|      3|{
  147|      3|	int key_id;
  148|      3|	int r;
  149|       |
  150|      3|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (150:6): [True: 0, False: 3]
  |  Branch (150:22): [True: 0, False: 3]
  ------------------
  151|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  152|       |
  153|      3|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || env->key_ref_len != 1) {
  ------------------
  |  |   58|      3|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (153:6): [True: 0, False: 3]
  |  Branch (153:52): [True: 0, False: 3]
  ------------------
  154|      0|		sc_log(card->ctx, "No or invalid key reference");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  155|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  156|      0|	}
  157|       |
  158|       |	/* here we follow the behaviour of the proprietary driver accompanying the card
  159|       |	 * where security operations are preceded by MSE RESTORE rather than MSE SET
  160|       |	 */
  161|      3|	key_id = env->key_ref[0];
  162|      3|	r = sc_restore_security_env(card, key_id);
  163|       |
  164|      3|	return r;
  165|      3|}

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

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

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

sc_check_sw:
   45|   417k|{
   46|   417k|	if (card == NULL)
  ------------------
  |  Branch (46:6): [True: 0, False: 417k]
  ------------------
   47|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   48|   417k|	if (card->ops->check_sw == NULL)
  ------------------
  |  Branch (48:6): [True: 0, False: 417k]
  ------------------
   49|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
   50|   417k|	return card->ops->check_sw(card, sw1, sw2);
   51|   417k|}
sc_format_apdu:
   55|   545k|{
   56|   545k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (56:6): [True: 0, False: 545k]
  |  Branch (56:22): [True: 0, False: 545k]
  ------------------
   57|      0|		return;
   58|      0|	}
   59|   545k|	memset(apdu, 0, sizeof(*apdu));
   60|   545k|	apdu->cla = (u8) card->cla;
   61|   545k|	apdu->cse = cse;
   62|   545k|	apdu->ins = (u8) ins;
   63|   545k|	apdu->p1 = (u8) p1;
   64|   545k|	apdu->p2 = (u8) p2;
   65|   545k|}
sc_format_apdu_cse_lc_le:
   68|  5.14k|{
   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|  5.14k|	if (!apdu)
  ------------------
  |  Branch (73:6): [True: 0, False: 5.14k]
  ------------------
   74|      0|		return;
   75|  5.14k|	if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
  ------------------
  |  |   35|  10.2k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (75:6): [True: 17, False: 5.12k]
  ------------------
   76|  5.12k|			|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|  5.12k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (76:7): [True: 273, False: 4.85k]
  ------------------
   77|       |		/* extended length  or data chaining and/or get response */
   78|    290|		if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
  ------------------
  |  |   38|    290|#define SC_MAX_EXT_APDU_DATA_SIZE		0xFFFF
  ------------------
  |  Branch (78:7): [True: 290, False: 0]
  ------------------
   79|    290|			apdu->lc = apdu->datalen;
   80|    290|		if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
  ------------------
  |  |   39|    290|#define SC_MAX_EXT_APDU_RESP_SIZE		(0xFFFF+1)
  ------------------
  |  Branch (80:7): [True: 290, False: 0]
  ------------------
   81|    290|			apdu->le = apdu->resplen;
   82|    290|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (82:7): [True: 290, False: 0]
  |  Branch (82:24): [True: 239, False: 51]
  ------------------
   83|    239|			apdu->cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    239|#define SC_APDU_CASE_2			0x22
  ------------------
   84|    290|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (84:7): [True: 0, False: 290]
  |  Branch (84:25): [True: 0, False: 0]
  ------------------
   85|      0|			apdu->cse = SC_APDU_CASE_3;
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
   86|    290|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (86:7): [True: 290, False: 0]
  |  Branch (86:24): [True: 51, False: 239]
  ------------------
   87|     51|			apdu->cse = SC_APDU_CASE_4;
  ------------------
  |  |  303|     51|#define SC_APDU_CASE_4			0x24
  ------------------
   88|  4.85k|	} else {
   89|       |		/* short length */
   90|  4.85k|		if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
  ------------------
  |  |   35|  4.85k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (90:7): [True: 4.85k, False: 0]
  ------------------
   91|  4.85k|			apdu->lc = apdu->datalen;
   92|  4.85k|		if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
  ------------------
  |  |   36|  4.85k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (92:7): [True: 4.85k, False: 0]
  ------------------
   93|  4.85k|			apdu->le = apdu->resplen;
   94|  4.85k|		if (!apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (94:7): [True: 2.66k, False: 2.18k]
  |  Branch (94:25): [True: 0, False: 2.66k]
  ------------------
   95|      0|			apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
   96|  4.85k|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (96:7): [True: 2.18k, False: 2.66k]
  |  Branch (96:24): [True: 2.12k, False: 68]
  ------------------
   97|  2.12k|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  2.12k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   98|  4.85k|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (98:7): [True: 2.66k, False: 2.18k]
  |  Branch (98:25): [True: 2.66k, False: 0]
  ------------------
   99|  2.66k|			apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  2.66k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  100|  4.85k|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (100:7): [True: 2.18k, False: 2.66k]
  |  Branch (100:24): [True: 68, False: 2.12k]
  ------------------
  101|     68|			apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|     68|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  102|  4.85k|	}
  103|  5.14k|}
sc_format_apdu_ex:
  109|  5.14k|{
  110|  5.14k|	if (!apdu) {
  ------------------
  |  Branch (110:6): [True: 0, False: 5.14k]
  ------------------
  111|      0|		return;
  112|      0|	}
  113|       |
  114|  5.14k|	memset(apdu, 0, sizeof(*apdu));
  115|  5.14k|	apdu->cla = cla;
  116|  5.14k|	apdu->ins = ins;
  117|  5.14k|	apdu->p1 = p1;
  118|  5.14k|	apdu->p2 = p2;
  119|  5.14k|	apdu->resp = resp;
  120|  5.14k|	apdu->resplen = resplen;
  121|  5.14k|	apdu->data = data;
  122|  5.14k|	apdu->datalen = datalen;
  123|  5.14k|	sc_format_apdu_cse_lc_le(apdu);
  124|  5.14k|}
sc_get_max_recv_size:
  188|   336k|{
  189|   336k|	size_t max_recv_size;
  190|   336k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (190:6): [True: 0, False: 336k]
  |  Branch (190:22): [True: 0, False: 336k]
  ------------------
  191|      0|		return 0;
  192|      0|	}
  193|   336k|	max_recv_size = card->max_recv_size;
  194|       |
  195|       |	/* initialize max_recv_size to a meaningful value */
  196|   336k|	if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  547|   336k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (196:6): [True: 31.2k, False: 305k]
  ------------------
  197|  31.2k|		if (!max_recv_size)
  ------------------
  |  Branch (197:7): [True: 2.09k, False: 29.1k]
  ------------------
  198|  2.09k|			max_recv_size = 65536;
  199|   305k|	} else {
  200|   305k|		if (!max_recv_size)
  ------------------
  |  Branch (200:7): [True: 158k, False: 146k]
  ------------------
  201|   158k|			max_recv_size = 256;
  202|   305k|	}
  203|       |
  204|       |	/*  Override card limitations with reader limitations. */
  205|   336k|	if (card->reader->max_recv_size != 0
  ------------------
  |  Branch (205:6): [True: 8.74k, False: 327k]
  ------------------
  206|  8.74k|			&& (card->reader->max_recv_size < card->max_recv_size))
  ------------------
  |  Branch (206:7): [True: 0, False: 8.74k]
  ------------------
  207|      0|		max_recv_size = card->reader->max_recv_size;
  208|       |
  209|   336k|	return max_recv_size;
  210|   336k|}
sc_get_max_send_size:
  213|  63.6k|{
  214|  63.6k|	size_t max_send_size;
  215|       |
  216|  63.6k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (216:6): [True: 0, False: 63.6k]
  |  Branch (216:22): [True: 0, False: 63.6k]
  ------------------
  217|      0|		return 0;
  218|      0|	}
  219|       |
  220|  63.6k|	max_send_size = card->max_send_size;
  221|       |
  222|       |	/* initialize max_send_size to a meaningful value */
  223|  63.6k|	if (card->caps & SC_CARD_CAP_APDU_EXT
  ------------------
  |  |  547|   127k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (223:6): [True: 9.88k, False: 53.8k]
  ------------------
  224|  9.88k|			&& card->reader->active_protocol != SC_PROTO_T0) {
  ------------------
  |  |  352|  9.88k|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (224:7): [True: 9.88k, False: 0]
  ------------------
  225|  9.88k|		if (!max_send_size)
  ------------------
  |  Branch (225:7): [True: 727, False: 9.16k]
  ------------------
  226|    727|			max_send_size = 65535;
  227|  53.8k|	} else {
  228|  53.8k|		if (!max_send_size)
  ------------------
  |  Branch (228:7): [True: 12.2k, False: 41.5k]
  ------------------
  229|  12.2k|			max_send_size = 255;
  230|  53.8k|	}
  231|       |
  232|       |	/*  Override card limitations with reader limitations. */
  233|  63.6k|	if (card->reader->max_send_size != 0
  ------------------
  |  Branch (233:6): [True: 0, False: 63.6k]
  ------------------
  234|      0|			&& (card->reader->max_send_size < card->max_send_size))
  ------------------
  |  Branch (234:7): [True: 0, False: 0]
  ------------------
  235|      0|		max_send_size = card->reader->max_send_size;
  236|       |
  237|  63.6k|	return max_send_size;
  238|  63.6k|}
sc_connect_card:
  241|  15.7k|{
  242|  15.7k|	sc_card_t *card;
  243|  15.7k|	sc_context_t *ctx;
  244|  15.7k|	struct sc_card_driver *driver;
  245|  15.7k|	int i, r = 0, idx, connected = 0;
  246|       |
  247|  15.7k|	if (card_out == NULL || reader == NULL)
  ------------------
  |  Branch (247:6): [True: 0, False: 15.7k]
  |  Branch (247:26): [True: 0, False: 15.7k]
  ------------------
  248|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  249|  15.7k|	ctx = reader->ctx;
  250|  15.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.7k]
  |  |  ------------------
  ------------------
  251|  15.7k|	if (reader->ops->connect == NULL)
  ------------------
  |  Branch (251:6): [True: 0, False: 15.7k]
  ------------------
  252|  15.7k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  253|       |
  254|  15.7k|	card = sc_card_new(ctx);
  255|  15.7k|	if (card == NULL)
  ------------------
  |  Branch (255:6): [True: 0, False: 15.7k]
  ------------------
  256|  15.7k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|  15.7k|	r = reader->ops->connect(reader);
  258|  15.7k|	if (r)
  ------------------
  |  Branch (258:6): [True: 0, False: 15.7k]
  ------------------
  259|      0|		goto err;
  260|       |
  261|  15.7k|	connected = 1;
  262|  15.7k|	card->reader = reader;
  263|  15.7k|	card->ctx = ctx;
  264|       |
  265|  15.7k|	if (reader->flags & SC_READER_ENABLE_ESCAPE)
  ------------------
  |  |  372|  15.7k|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (265:6): [True: 0, False: 15.7k]
  ------------------
  266|      0|		sc_detect_escape_cmds(reader);
  267|       |
  268|  15.7k|	memcpy(&card->atr, &reader->atr, sizeof(card->atr));
  269|  15.7k|	memcpy(&card->uid, &reader->uid, sizeof(card->uid));
  270|       |
  271|  15.7k|	_sc_parse_atr(reader);
  272|       |
  273|       |	/* See if the ATR matches any ATR specified in the config file */
  274|  15.7k|	if ((driver = ctx->forced_driver) == NULL) {
  ------------------
  |  Branch (274:6): [True: 15.7k, False: 0]
  ------------------
  275|  15.7k|		sc_log(ctx, "matching configured ATRs");
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  276|   725k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (276:15): [True: 709k, False: 15.7k]
  ------------------
  277|   709k|			driver = ctx->card_drivers[i];
  278|       |
  279|   709k|			if (driver->atr_map == NULL ||
  ------------------
  |  Branch (279:8): [True: 709k, False: 0]
  ------------------
  280|   709k|			    !strcmp(driver->short_name, "default")) {
  ------------------
  |  Branch (280:8): [True: 0, False: 0]
  ------------------
  281|   709k|				driver = NULL;
  282|   709k|				continue;
  283|   709k|			}
  284|      0|			sc_log(ctx, "trying driver '%s'", driver->short_name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  285|      0|			idx = _sc_match_atr(card, driver->atr_map, NULL);
  286|      0|			if (idx >= 0) {
  ------------------
  |  Branch (286:8): [True: 0, False: 0]
  ------------------
  287|      0|				struct sc_atr_table *src = &driver->atr_map[idx];
  288|       |
  289|      0|				sc_log(ctx, "matched driver '%s'", driver->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  290|       |				/* It's up to card driver to notice these correctly */
  291|      0|				card->name = src->name;
  292|      0|				card->type = src->type;
  293|      0|				card->flags = src->flags;
  294|      0|				break;
  295|      0|			}
  296|      0|			driver = NULL;
  297|      0|		}
  298|  15.7k|	}
  299|       |
  300|  15.7k|	if (driver != NULL) {
  ------------------
  |  Branch (300:6): [True: 0, False: 15.7k]
  ------------------
  301|       |		/* Forced driver, or matched via ATR mapping from config file */
  302|      0|		card->driver = driver;
  303|       |
  304|      0|		memcpy(card->ops, card->driver->ops, sizeof(struct sc_card_operations));
  305|      0|		if (card->ops->match_card != NULL)
  ------------------
  |  Branch (305:7): [True: 0, False: 0]
  ------------------
  306|      0|			if (card->ops->match_card(card) != 1)
  ------------------
  |  Branch (306:8): [True: 0, False: 0]
  ------------------
  307|      0|				sc_log(ctx, "driver '%s' match_card() failed: %s (will continue anyway)", card->driver->name, sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  308|       |
  309|      0|		if (card->ops->init != NULL) {
  ------------------
  |  Branch (309:7): [True: 0, False: 0]
  ------------------
  310|      0|			r = card->ops->init(card);
  311|      0|			if (r) {
  ------------------
  |  Branch (311:8): [True: 0, False: 0]
  ------------------
  312|      0|				sc_log(ctx, "driver '%s' init() failed: %s", card->driver->name, sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  313|      0|				goto err;
  314|      0|			}
  315|      0|		}
  316|      0|	}
  317|  15.7k|	else {
  318|  15.7k|		sc_card_t uninitialized = *card;
  319|  15.7k|		sc_log(ctx, "matching built-in ATRs");
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|   403k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (320:15): [True: 401k, False: 2.29k]
  ------------------
  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|   401k|			*card = uninitialized;
  333|       |
  334|   401k|			struct sc_card_driver *drv = ctx->card_drivers[i];
  335|   401k|			const struct sc_card_operations *ops = drv->ops;
  336|       |
  337|   401k|			sc_log(ctx, "trying driver '%s'", drv->short_name);
  ------------------
  |  |   71|   401k|#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|   401k|			if (ops == NULL || ops->match_card == NULL)   {
  ------------------
  |  Branch (338:8): [True: 0, False: 401k]
  |  Branch (338:23): [True: 0, False: 401k]
  ------------------
  339|      0|				continue;
  340|      0|			}
  341|   401k|			else if (!(ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER)
  ------------------
  |  |  860|   401k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  |  Branch (341:13): [True: 401k, False: 0]
  ------------------
  342|   401k|				   	&& !strcmp("default", drv->short_name))   {
  ------------------
  |  Branch (342:12): [True: 2.29k, False: 399k]
  ------------------
  343|  2.29k|				sc_log(ctx , "ignore 'default' card driver");
  ------------------
  |  |   71|  2.29k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  344|  2.29k|				continue;
  345|  2.29k|			}
  346|       |
  347|       |			/* Needed if match_card() needs to talk with the card (e.g. card-muscle) */
  348|   399k|			*card->ops = *ops;
  349|   399k|			if (ops->match_card(card) != 1)
  ------------------
  |  Branch (349:8): [True: 384k, False: 14.3k]
  ------------------
  350|   384k|				continue;
  351|  14.3k|			sc_log(ctx, "matched: %s", drv->name);
  ------------------
  |  |   71|  14.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__
  |  |  ------------------
  ------------------
  352|  14.3k|			memcpy(card->ops, ops, sizeof(struct sc_card_operations));
  353|  14.3k|			card->driver = drv;
  354|  14.3k|			r = ops->init(card);
  355|  14.3k|			if (r) {
  ------------------
  |  Branch (355:8): [True: 1.55k, False: 12.7k]
  ------------------
  356|  1.55k|				sc_log(ctx, "driver '%s' init() failed: %s", drv->name, sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  357|  1.55k|				if (r == SC_ERROR_INVALID_CARD) {
  ------------------
  |  |   60|  1.55k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (357:9): [True: 829, False: 726]
  ------------------
  358|    829|					card->driver = NULL;
  359|    829|					continue;
  360|    829|				}
  361|    726|				goto err;
  362|  1.55k|			}
  363|  12.7k|			break;
  364|  14.3k|		}
  365|  15.7k|	}
  366|  15.0k|	if (card->driver == NULL) {
  ------------------
  |  Branch (366:6): [True: 2.29k, False: 12.7k]
  ------------------
  367|  2.29k|		sc_log(ctx, "unable to find driver for inserted card");
  ------------------
  |  |   71|  2.29k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  368|  2.29k|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  2.29k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  369|  2.29k|		goto err;
  370|  2.29k|	}
  371|  12.7k|	if (card->name == NULL)
  ------------------
  |  Branch (371:6): [True: 2.85k, False: 9.89k]
  ------------------
  372|  2.85k|		card->name = card->driver->name;
  373|       |
  374|       |	/* initialize max_send_size/max_recv_size to a meaningful value */
  375|  12.7k|	card->max_recv_size = sc_get_max_recv_size(card);
  376|  12.7k|	card->max_send_size = sc_get_max_send_size(card);
  377|       |
  378|  12.7k|	sc_log(ctx, "card info name:'%s', type:%i, flags:0x%lX, max_send/recv_size:%zu/%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  379|  12.7k|			card->name, card->type, card->flags, card->max_send_size, card->max_recv_size);
  380|       |
  381|  12.7k|#ifdef ENABLE_SM
  382|       |	/* Check, if secure messaging module present. */
  383|  12.7k|	r = sc_card_sm_check(card);
  384|  12.7k|	if (r)   {
  ------------------
  |  Branch (384:6): [True: 0, False: 12.7k]
  ------------------
  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|  12.7k|#endif
  389|  12.7k|	*card_out = card;
  390|       |
  391|  12.7k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.7k|	int _ret = r; \
  |  |  |  |  155|  12.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.7k|	return _ret; \
  |  |  |  |  163|  12.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|  3.02k|err:
  393|  3.02k|	if (connected)
  ------------------
  |  Branch (393:6): [True: 3.02k, False: 0]
  ------------------
  394|  3.02k|		reader->ops->disconnect(reader);
  395|  3.02k|	if (card != NULL)
  ------------------
  |  Branch (395:6): [True: 3.02k, False: 0]
  ------------------
  396|  3.02k|		sc_card_free(card);
  397|  3.02k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  3.02k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.02k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.02k|	int _ret = r; \
  |  |  |  |  155|  3.02k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.02k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.02k|	return _ret; \
  |  |  |  |  163|  3.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|  3.02k|}
sc_disconnect_card:
  401|  15.7k|{
  402|  15.7k|	sc_context_t *ctx;
  403|       |
  404|  15.7k|	if (!card)
  ------------------
  |  Branch (404:6): [True: 3.02k, False: 12.7k]
  ------------------
  405|  3.02k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  3.02k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  406|       |
  407|  12.7k|	ctx = card->ctx;
  408|  12.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  409|       |
  410|  12.7k|	if (card->ops->finish) {
  ------------------
  |  Branch (410:6): [True: 11.8k, False: 944]
  ------------------
  411|  11.8k|		int r = card->ops->finish(card);
  412|  11.8k|		if (r)
  ------------------
  |  Branch (412:7): [True: 552, False: 11.2k]
  ------------------
  413|    552|			sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|    552|#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|  11.8k|	}
  415|       |
  416|  12.7k|	if (card->reader->ops->disconnect) {
  ------------------
  |  Branch (416:6): [True: 12.7k, False: 0]
  ------------------
  417|  12.7k|		int r = card->reader->ops->disconnect(card->reader);
  418|  12.7k|		if (r)
  ------------------
  |  Branch (418:7): [True: 0, False: 12.7k]
  ------------------
  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|  12.7k|	}
  421|       |
  422|  12.7k|#ifdef ENABLE_SM
  423|       |	/* release SM related resources */
  424|  12.7k|	sc_card_sm_unload(card);
  425|  12.7k|#endif
  426|       |
  427|  12.7k|	sc_card_free(card);
  428|  12.7k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.7k|	int _ret = r; \
  |  |  |  |  155|  12.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.7k|	return _ret; \
  |  |  |  |  163|  12.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|  12.7k|}
sc_lock:
  456|   636k|{
  457|   636k|	int r = 0, r2 = 0;
  458|   636k|	int was_reset = 0;
  459|   636k|	int reader_lock_obtained  = 0;
  460|       |
  461|   636k|	if (card == NULL)
  ------------------
  |  Branch (461:6): [True: 0, False: 636k]
  ------------------
  462|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  463|       |
  464|   636k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   636k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   636k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   636k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   636k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 636k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|       |
  466|   636k|	r = sc_mutex_lock(card->ctx, card->mutex);
  467|   636k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   636k|#define SC_SUCCESS				0
  ------------------
  |  Branch (467:6): [True: 0, False: 636k]
  ------------------
  468|      0|		return r;
  469|   636k|	if (card->lock_count == 0) {
  ------------------
  |  Branch (469:6): [True: 281k, False: 354k]
  ------------------
  470|   281k|		if (card->reader->ops->lock != NULL) {
  ------------------
  |  Branch (470:7): [True: 281k, False: 0]
  ------------------
  471|   281k|			r = card->reader->ops->lock(card->reader);
  472|   281k|			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   563k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   281k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (472:11): [True: 0, False: 281k]
  |  Branch (472:39): [True: 0, False: 281k]
  ------------------
  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|   281k|			if (r == 0)
  ------------------
  |  Branch (477:8): [True: 281k, False: 0]
  ------------------
  478|   281k|				reader_lock_obtained = 1;
  479|   281k|		}
  480|   281k|	}
  481|   636k|	if (r == 0)
  ------------------
  |  Branch (481:6): [True: 636k, False: 0]
  ------------------
  482|   636k|		card->lock_count++;
  483|       |
  484|   636k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  485|   636k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   636k|#define SC_SUCCESS				0
  ------------------
  |  Branch (485:6): [True: 0, False: 636k]
  ------------------
  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|   636k|	if (r == 0 && was_reset > 0) {
  ------------------
  |  Branch (490:6): [True: 636k, False: 0]
  |  Branch (490:16): [True: 0, False: 636k]
  ------------------
  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|   636k|	if (r == 0 && reader_lock_obtained == 1  && card->ops->card_reader_lock_obtained) {
  ------------------
  |  Branch (498:6): [True: 636k, False: 0]
  |  Branch (498:16): [True: 281k, False: 354k]
  |  Branch (498:46): [True: 89.7k, False: 191k]
  ------------------
  499|  89.7k|		if (SC_SUCCESS != card->ops->card_reader_lock_obtained(card, was_reset))
  ------------------
  |  |   28|  89.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (499:7): [True: 1.46k, False: 88.3k]
  ------------------
  500|  1.46k|			sc_log(card->ctx, "card_reader_lock_obtained failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  501|  89.7k|	}
  502|       |
  503|   636k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   636k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   636k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   636k|	int _ret = r; \
  |  |  |  |  155|   636k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 636k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   636k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 636k]
  |  |  |  |  ------------------
  |  |  |  |  157|   636k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   636k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   636k|	return _ret; \
  |  |  |  |  163|   636k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  504|   636k|}
sc_unlock:
  507|   636k|{
  508|   636k|	int r, r2;
  509|       |
  510|   636k|	if (!card)
  ------------------
  |  Branch (510:6): [True: 0, False: 636k]
  ------------------
  511|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  512|       |
  513|   636k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   636k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   636k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   636k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   636k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 636k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|   636k|	r = sc_mutex_lock(card->ctx, card->mutex);
  516|   636k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   636k|#define SC_SUCCESS				0
  ------------------
  |  Branch (516:6): [True: 0, False: 636k]
  ------------------
  517|   636k|		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|   636k|	if (card->lock_count < 1) {
  ------------------
  |  Branch (519:6): [True: 0, False: 636k]
  ------------------
  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|   636k|	if (--card->lock_count == 0) {
  ------------------
  |  Branch (522:6): [True: 281k, False: 354k]
  ------------------
  523|       |		/* release reader lock */
  524|   281k|		if (card->reader->ops->unlock != NULL)
  ------------------
  |  Branch (524:7): [True: 281k, False: 0]
  ------------------
  525|   281k|			r = card->reader->ops->unlock(card->reader);
  526|   281k|	}
  527|   636k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  528|   636k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   636k|#define SC_SUCCESS				0
  ------------------
  |  Branch (528:6): [True: 0, False: 636k]
  ------------------
  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|   636k|	return r;
  534|   636k|}
sc_read_binary:
  604|  12.4k|{
  605|  12.4k|	size_t max_le = sc_get_max_recv_size(card);
  606|  12.4k|	size_t todo = count;
  607|  12.4k|	int r;
  608|       |
  609|  12.4k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (609:6): [True: 0, False: 12.4k]
  |  Branch (609:22): [True: 0, False: 12.4k]
  |  Branch (609:43): [True: 0, False: 12.4k]
  ------------------
  610|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  611|      0|	}
  612|  12.4k|	sc_log(card->ctx, "called; %zu bytes at index %d", count, idx);
  ------------------
  |  |   71|  12.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__
  |  |  ------------------
  ------------------
  613|  12.4k|	if (count == 0)
  ------------------
  |  Branch (613:6): [True: 179, False: 12.2k]
  ------------------
  614|  12.4k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    179|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    179|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    179|	int _ret = r; \
  |  |  |  |  155|    179|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 179, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    179|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 179]
  |  |  |  |  ------------------
  |  |  |  |  157|    179|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    179|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    179|	return _ret; \
  |  |  |  |  163|    179|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|       |
  616|  12.2k|#ifdef ENABLE_SM
  617|  12.2k|	if (card->sm_ctx.ops.read_binary)   {
  ------------------
  |  Branch (617:6): [True: 194, False: 12.0k]
  ------------------
  618|    194|		r = card->sm_ctx.ops.read_binary(card, idx, buf, count);
  619|    194|		if (r)
  ------------------
  |  Branch (619:7): [True: 162, False: 32]
  ------------------
  620|    194|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    162|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    162|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    162|	int _ret = r; \
  |  |  |  |  155|    162|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 162, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    162|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    162|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 162, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    162|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    162|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    162|	return _ret; \
  |  |  |  |  163|    162|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|    194|	}
  622|  12.1k|#endif
  623|       |
  624|  12.1k|	if (card->ops->read_binary == NULL)
  ------------------
  |  Branch (624:6): [True: 0, False: 12.1k]
  ------------------
  625|  12.1k|		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|  12.1k|	r = sc_lock(card);
  629|  12.1k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  12.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  12.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  12.1k|	int _ret = (r); \
  |  |  |  |  168|  12.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 12.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  12.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|       |
  631|  37.6k|	while (todo > 0) {
  ------------------
  |  Branch (631:9): [True: 34.3k, False: 3.29k]
  ------------------
  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: 14.2k, False: 20.1k]
  |  |  ------------------
  ------------------
  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|  30.9k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (635:7): [True: 3.44k, False: 30.9k]
  |  Branch (635:17): [True: 41, False: 30.8k]
  ------------------
  636|  3.48k|			break;
  637|  30.8k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (637:7): [True: 5.34k, False: 25.5k]
  |  Branch (637:16): [True: 3.47k, False: 1.86k]
  ------------------
  638|       |			/* the last command failed, but previous ones succeeded.
  639|       |			 * Let's just return what we've successfully read. */
  640|  3.47k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  3.47k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  641|  3.47k|			break;
  642|  3.47k|		}
  643|  27.3k|		if (r < 0) {
  ------------------
  |  Branch (643:7): [True: 1.86k, False: 25.5k]
  ------------------
  644|  1.86k|			sc_unlock(card);
  645|  1.86k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.86k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.86k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.86k|	int _ret = r; \
  |  |  |  |  155|  1.86k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.86k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.86k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.86k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.86k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.86k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.86k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.86k|	return _ret; \
  |  |  |  |  163|  1.86k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  646|  1.86k|		}
  647|  25.5k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (647:7): [True: 0, False: 25.5k]
  |  Branch (647:40): [True: 0, False: 25.5k]
  ------------------
  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|  25.5k|		todo -= (size_t) r;
  654|  25.5k|		buf  += (size_t) r;
  655|  25.5k|		idx  += (size_t) r;
  656|  25.5k|	}
  657|       |
  658|  10.2k|	sc_unlock(card);
  659|       |
  660|  10.2k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  10.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.2k|	int _ret = r; \
  |  |  |  |  155|  10.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.25k, False: 9.01k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.25k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.25k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.01k|	} else { \
  |  |  |  |  159|  9.01k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  9.01k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  9.01k|	} \
  |  |  |  |  162|  10.2k|	return _ret; \
  |  |  |  |  163|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  661|  10.2k|}
sc_select_file:
  810|  99.3k|{
  811|  99.3k|	int r;
  812|  99.3k|	char pbuf[SC_MAX_PATH_STRING_SIZE];
  813|       |
  814|  99.3k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (814:6): [True: 0, False: 99.3k]
  |  Branch (814:22): [True: 0, False: 99.3k]
  ------------------
  815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  816|      0|	}
  817|       |
  818|  99.3k|	r = sc_path_print(pbuf, sizeof(pbuf), in_path);
  819|  99.3k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  99.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (819:6): [True: 1.60k, False: 97.7k]
  ------------------
  820|  1.60k|		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|  99.3k|	if (file != NULL)
  ------------------
  |  Branch (825:6): [True: 50.5k, False: 48.7k]
  ------------------
  826|  50.5k|		*file = NULL;
  827|       |
  828|  99.3k|	sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
  ------------------
  |  |   71|  99.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__
  |  |  ------------------
  ------------------
  829|  99.3k|	if (in_path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  99.3k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (829:6): [True: 0, False: 99.3k]
  ------------------
  830|  99.3k|		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|  99.3k|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|  99.3k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (832:6): [True: 69.7k, False: 29.6k]
  ------------------
  833|       |		/* Perform a sanity check */
  834|  69.7k|		size_t i;
  835|       |
  836|  69.7k|		if ((in_path->len & 1) != 0)
  ------------------
  |  Branch (836:7): [True: 47, False: 69.6k]
  ------------------
  837|  69.7k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     47|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     47|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     47|	int _ret = r; \
  |  |  |  |  155|     47|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     47|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 47, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     47|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     47|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     47|	return _ret; \
  |  |  |  |  163|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  838|       |
  839|   207k|		for (i = 0; i < in_path->len/2; i++) {
  ------------------
  |  Branch (839:15): [True: 138k, False: 69.6k]
  ------------------
  840|   138k|			u8 p1 = in_path->value[2*i],
  841|   138k|			   p2 = in_path->value[2*i+1];
  842|       |
  843|   138k|			if ((p1 == 0x3F && p2 == 0x00) && i != 0)
  ------------------
  |  Branch (843:9): [True: 50.9k, False: 87.0k]
  |  Branch (843:23): [True: 50.6k, False: 365]
  |  Branch (843:38): [True: 27, False: 50.5k]
  ------------------
  844|   138k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     27|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     27|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     27|	int _ret = r; \
  |  |  |  |  155|     27|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     27|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     27|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     27|	return _ret; \
  |  |  |  |  163|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  845|   138k|		}
  846|  69.6k|	}
  847|  99.2k|	if (card->ops->select_file == NULL)
  ------------------
  |  Branch (847:6): [True: 0, False: 99.2k]
  ------------------
  848|  99.2k|		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|  99.2k|	r = card->ops->select_file(card, in_path, file);
  850|  99.2k|	LOG_TEST_RET(card->ctx, r, "'SELECT' error");
  ------------------
  |  |  174|  99.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  99.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  99.2k|	int _ret = (r); \
  |  |  |  |  168|  99.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 74.9k, False: 24.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|  74.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|  74.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  74.9k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  74.9k|		return _ret; \
  |  |  |  |  172|  74.9k|	} \
  |  |  |  |  173|  99.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|       |
  852|  24.3k|	if (file) {
  ------------------
  |  Branch (852:6): [True: 12.7k, False: 11.5k]
  ------------------
  853|  12.7k|		if (*file)
  ------------------
  |  Branch (853:7): [True: 12.6k, False: 164]
  ------------------
  854|       |			/* Remember file path */
  855|  12.6k|			(*file)->path = *in_path;
  856|    164|		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|    164|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    164|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  861|  12.7k|	}
  862|       |
  863|  24.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  24.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  24.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  24.3k|	int _ret = r; \
  |  |  |  |  155|  24.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  24.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    164|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 164, False: 24.1k]
  |  |  |  |  ------------------
  |  |  |  |  157|  24.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  24.3k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  24.3k|	return _ret; \
  |  |  |  |  163|  24.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  864|  24.3k|}
sc_get_data:
  868|  4.95k|{
  869|  4.95k|	int	r;
  870|       |
  871|  4.95k|	sc_log(card->ctx, "called, tag=%04x", tag);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
  872|  4.95k|	if (card->ops->get_data == NULL)
  ------------------
  |  Branch (872:6): [True: 0, False: 4.95k]
  ------------------
  873|  4.95k|		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|  4.95k|	r = card->ops->get_data(card, tag, buf, len);
  875|       |
  876|  4.95k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.95k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.95k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.95k|	int _ret = r; \
  |  |  |  |  155|  4.95k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.46k, False: 1.48k]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.13k, False: 329]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.46k|	} else { \
  |  |  |  |  159|  1.48k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.48k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.48k|	} \
  |  |  |  |  162|  4.95k|	return _ret; \
  |  |  |  |  163|  4.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  877|  4.95k|}
sc_get_challenge:
  893|  2.60k|{
  894|  2.60k|	int r;
  895|       |
  896|  2.60k|	if (len == 0)
  ------------------
  |  Branch (896:6): [True: 451, False: 2.14k]
  ------------------
  897|    451|		return SC_SUCCESS;
  ------------------
  |  |   28|    451|#define SC_SUCCESS				0
  ------------------
  898|       |
  899|  2.14k|	if (card == NULL || rnd == NULL) {
  ------------------
  |  Branch (899:6): [True: 0, False: 2.14k]
  |  Branch (899:22): [True: 0, False: 2.14k]
  ------------------
  900|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  901|      0|	}
  902|       |
  903|  2.14k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.14k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.14k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.14k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.14k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.14k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  904|       |
  905|  2.14k|	if (card->ops == NULL || card->ops->get_challenge == NULL)
  ------------------
  |  Branch (905:6): [True: 0, False: 2.14k]
  |  Branch (905:27): [True: 2, False: 2.14k]
  ------------------
  906|  2.14k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  907|       |
  908|  2.14k|	r = sc_lock(card);
  909|  2.14k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  2.14k|#define SC_SUCCESS				0
  ------------------
  |  Branch (909:6): [True: 0, False: 2.14k]
  ------------------
  910|  2.14k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  911|       |
  912|  6.35k|	while (len > 0) {
  ------------------
  |  Branch (912:9): [True: 6.33k, False: 21]
  ------------------
  913|  6.33k|		r = card->ops->get_challenge(card, rnd, len);
  914|  6.33k|		if (r == 0)
  ------------------
  |  Branch (914:7): [True: 48, False: 6.28k]
  ------------------
  915|     48|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     48|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  916|  6.33k|		if (r < 0) {
  ------------------
  |  Branch (916:7): [True: 2.12k, False: 4.20k]
  ------------------
  917|  2.12k|			sc_unlock(card);
  918|  2.12k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.12k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.12k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.12k|	int _ret = r; \
  |  |  |  |  155|  2.12k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.12k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  2.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.12k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.12k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.12k|	return _ret; \
  |  |  |  |  163|  2.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  919|  2.12k|		}
  920|       |
  921|  4.20k|		rnd += (size_t) r;
  922|  4.20k|		len -= (size_t) r;
  923|  4.20k|	}
  924|       |
  925|     21|	sc_unlock(card);
  926|       |
  927|     21|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  928|     21|}
sc_read_record:
  932|  7.36k|{
  933|  7.36k|	size_t max_le = sc_get_max_recv_size(card);
  934|  7.36k|	size_t todo = count;
  935|  7.36k|	int r;
  936|       |
  937|  7.36k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (937:6): [True: 0, False: 7.36k]
  |  Branch (937:22): [True: 0, False: 7.36k]
  |  Branch (937:43): [True: 0, False: 7.36k]
  ------------------
  938|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  939|      0|	}
  940|  7.36k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.36k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.36k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.36k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.36k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.36k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  941|  7.36k|	if (count == 0)
  ------------------
  |  Branch (941:6): [True: 2, False: 7.36k]
  ------------------
  942|  7.36k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  943|       |
  944|  7.36k|	if (card->ops->read_record == NULL)
  ------------------
  |  Branch (944:6): [True: 25, False: 7.33k]
  ------------------
  945|  7.36k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     25|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     25|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     25|	int _ret = r; \
  |  |  |  |  155|     25|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     25|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     25|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     25|	return _ret; \
  |  |  |  |  163|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  946|       |
  947|       |	/* lock the card now to avoid deselection of the file */
  948|  7.33k|	r = sc_lock(card);
  949|  7.33k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  7.33k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.33k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.33k|	int _ret = (r); \
  |  |  |  |  168|  7.33k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7.33k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  7.33k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7.33k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  950|       |
  951|  15.3k|	while (todo > 0) {
  ------------------
  |  Branch (951:9): [True: 14.7k, False: 646]
  ------------------
  952|  14.7k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  14.7k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 6.95k, False: 7.79k]
  |  |  ------------------
  ------------------
  953|       |
  954|  14.7k|		r = card->ops->read_record(card, rec_nr, idx, buf, chunk, flags);
  955|  14.7k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  14.4k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (955:7): [True: 340, False: 14.4k]
  |  Branch (955:17): [True: 25, False: 14.3k]
  ------------------
  956|    365|			break;
  957|  14.3k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (957:7): [True: 6.32k, False: 8.05k]
  |  Branch (957:16): [True: 5.14k, False: 1.18k]
  ------------------
  958|       |			/* the last command failed, but previous ones succeeded.
  959|       |			 * Let's just return what we've successfully read. */
  960|  5.14k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  961|  5.14k|			break;
  962|  5.14k|		}
  963|  9.24k|		if (r < 0) {
  ------------------
  |  Branch (963:7): [True: 1.18k, False: 8.05k]
  ------------------
  964|  1.18k|			sc_unlock(card);
  965|  1.18k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|  1.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.18k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  966|  1.18k|		}
  967|  8.05k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (967:7): [True: 0, False: 8.05k]
  |  Branch (967:40): [True: 0, False: 8.05k]
  ------------------
  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|  8.05k|		todo -= (size_t) r;
  974|  8.05k|		buf  += (size_t) r;
  975|  8.05k|		idx  += (size_t) r;
  976|  8.05k|	}
  977|       |
  978|  6.15k|	sc_unlock(card);
  979|       |
  980|  6.15k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  6.15k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.15k|	int _ret = r; \
  |  |  |  |  155|  6.15k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 345, False: 5.80k]
  |  |  |  |  ------------------
  |  |  |  |  156|    345|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 345]
  |  |  |  |  ------------------
  |  |  |  |  157|    345|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.80k|	} else { \
  |  |  |  |  159|  5.80k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  5.80k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  5.80k|	} \
  |  |  |  |  162|  6.15k|	return _ret; \
  |  |  |  |  163|  6.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  981|  6.15k|}
sc_card_ctl:
 1091|   132k|{
 1092|   132k|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|   132k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1093|       |
 1094|   132k|	if (card == NULL) {
  ------------------
  |  Branch (1094:6): [True: 0, False: 132k]
  ------------------
 1095|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1096|      0|	}
 1097|   132k|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called with cmd=%lu\n", cmd);
  ------------------
  |  |   70|   132k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1098|       |
 1099|   132k|	if (card->ops->card_ctl != NULL)
  ------------------
  |  Branch (1099:6): [True: 131k, False: 914]
  ------------------
 1100|   131k|		r = card->ops->card_ctl(card, cmd, args);
 1101|       |
 1102|       |	/* suppress "not supported" error messages */
 1103|   132k|	if (r == SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|   132k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (1103:6): [True: 10.0k, False: 122k]
  ------------------
 1104|  10.0k|		sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
  ------------------
  |  |   71|  10.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1105|  10.0k|		return r;
 1106|  10.0k|	}
 1107|   122k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   122k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   122k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   122k|	int _ret = r; \
  |  |  |  |  155|   122k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 83.5k, False: 39.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|  83.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|  30.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30.7k, False: 52.8k]
  |  |  |  |  ------------------
  |  |  |  |  157|  83.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  83.5k|	} else { \
  |  |  |  |  159|  39.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  39.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  39.2k|	} \
  |  |  |  |  162|   122k|	return _ret; \
  |  |  |  |  163|   122k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1108|   122k|}
_sc_card_add_algorithm:
 1111|  45.2k|{
 1112|  45.2k|	sc_algorithm_info_t *p;
 1113|       |
 1114|  45.2k|	if (info == NULL) {
  ------------------
  |  Branch (1114:6): [True: 0, False: 45.2k]
  ------------------
 1115|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1116|      0|	}
 1117|  45.2k|	p = (sc_algorithm_info_t *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info));
 1118|  45.2k|	if (!p) {
  ------------------
  |  Branch (1118:6): [True: 0, False: 45.2k]
  ------------------
 1119|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1120|      0|	}
 1121|  45.2k|	card->algorithms = p;
 1122|  45.2k|	p += card->algorithm_count;
 1123|  45.2k|	card->algorithm_count++;
 1124|  45.2k|	*p = *info;
 1125|  45.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  45.2k|#define SC_SUCCESS				0
  ------------------
 1126|  45.2k|}
_sc_card_add_symmetric_alg:
 1130|    157|{
 1131|    157|	sc_algorithm_info_t info;
 1132|       |
 1133|    157|	memset(&info, 0, sizeof(info));
 1134|    157|	info.algorithm = algorithm;
 1135|    157|	info.key_length = key_length;
 1136|    157|	info.flags = flags;
 1137|       |
 1138|    157|	return _sc_card_add_algorithm(card, &info);
 1139|    157|}
_sc_card_add_ec_alg:
 1176|  7.58k|{
 1177|  7.58k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1178|  7.58k|		curve_oid, SC_ALGORITHM_EC);
  ------------------
  |  |   70|  7.58k|#define SC_ALGORITHM_EC		2
  ------------------
 1179|  7.58k|}
_sc_card_add_eddsa_alg:
 1184|    110|{
 1185|       |	/* For simplicity, share the ec union with the curve information */
 1186|    110|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1187|    110|		curve_oid, SC_ALGORITHM_EDDSA);
  ------------------
  |  |   72|    110|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1188|    110|}
_sc_card_add_xeddsa_alg:
 1193|    110|{
 1194|       |	/* For simplicity, share the ec union with the curve information */
 1195|    110|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1196|    110|		curve_oid, SC_ALGORITHM_XEDDSA);
  ------------------
  |  |   73|    110|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1197|    110|}
sc_card_find_alg:
 1201|    420|{
 1202|    420|	int i;
 1203|       |
 1204|  1.40k|	for (i = 0; i < card->algorithm_count; i++) {
  ------------------
  |  Branch (1204:14): [True: 1.38k, False: 21]
  ------------------
 1205|  1.38k|		sc_algorithm_info_t *info = &card->algorithms[i];
 1206|       |
 1207|  1.38k|		if (param && (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1207:7): [True: 0, False: 1.38k]
  |  Branch (1207:17): [True: 0, False: 0]
  ------------------
 1208|      0|			info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1208:4): [True: 0, False: 0]
  ------------------
 1209|      0|			info->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1209:4): [True: 0, False: 0]
  ------------------
 1210|      0|			if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id))
  ------------------
  |  Branch (1210:8): [True: 0, False: 0]
  ------------------
 1211|      0|				return info;
 1212|  1.38k|		} else if (info->algorithm != algorithm) {
  ------------------
  |  Branch (1212:14): [True: 149, False: 1.23k]
  ------------------
 1213|    149|			continue;
 1214|  1.23k|		} else if (info->key_length == key_length)
  ------------------
  |  Branch (1214:14): [True: 399, False: 834]
  ------------------
 1215|    399|			return info;
 1216|  1.38k|	}
 1217|     21|	return NULL;
 1218|    420|}
sc_card_find_ec_alg:
 1222|     27|{
 1223|     27|	return sc_card_find_alg(card, SC_ALGORITHM_EC, key_length, curve_name);
  ------------------
  |  |   70|     27|#define SC_ALGORITHM_EC		2
  ------------------
 1224|     27|}
_sc_card_add_rsa_alg:
 1240|  37.1k|{
 1241|  37.1k|	sc_algorithm_info_t info;
 1242|       |
 1243|  37.1k|	memset(&info, 0, sizeof(info));
 1244|  37.1k|	info.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|  37.1k|#define SC_ALGORITHM_RSA		0
  ------------------
 1245|  37.1k|	info.key_length = key_length;
 1246|  37.1k|	info.flags = flags;
 1247|       |	/* disable particular PKCS1 v1.5 padding type if also RAW is supported on card */
 1248|  37.1k|	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  37.1k|#define SC_ALGORITHM_RSA_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.1k|#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.1k|#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|  37.1k|#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|  37.1k|#define SC_ALGORITHM_RSA_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.1k|#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.1k|#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|  37.1k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (1248:6): [True: 3.98k, False: 33.1k]
  ------------------
 1249|  3.98k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|  3.98k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1249:7): [True: 0, False: 3.98k]
  ------------------
 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|  3.98k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  110|  3.98k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1251:7): [True: 3.98k, False: 0]
  ------------------
 1252|  3.98k|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  3.98k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 1253|  3.98k|	}
 1254|  37.1k|	info.u._rsa.exponent = exponent;
 1255|       |
 1256|  37.1k|	return _sc_card_add_algorithm(card, &info);
 1257|  37.1k|}
sc_card_find_rsa_alg:
 1260|    393|{
 1261|    393|	return sc_card_find_alg(card, SC_ALGORITHM_RSA, key_length, NULL);
  ------------------
  |  |   69|    393|#define SC_ALGORITHM_RSA		0
  ------------------
 1262|    393|}
_sc_match_atr:
 1333|   347k|{
 1334|   347k|	int res;
 1335|       |
 1336|   347k|	if (card == NULL)
  ------------------
  |  Branch (1336:6): [True: 0, False: 347k]
  ------------------
 1337|      0|		return -1;
 1338|   347k|	res = match_atr_table(card->ctx, table, &card->atr);
 1339|   347k|	if (res < 0)
  ------------------
  |  Branch (1339:6): [True: 337k, False: 10.1k]
  ------------------
 1340|   337k|		return res;
 1341|  10.1k|	if (type_out != NULL)
  ------------------
  |  Branch (1341:6): [True: 9.78k, False: 353]
  ------------------
 1342|  9.78k|		*type_out = table[res].type;
 1343|  10.1k|	return res;
 1344|   347k|}
_sc_match_atr_block:
 1347|  29.2k|{
 1348|  29.2k|	struct sc_card_driver *drv;
 1349|  29.2k|	struct sc_atr_table *table;
 1350|  29.2k|	int res;
 1351|       |
 1352|  29.2k|	if (ctx == NULL)
  ------------------
  |  Branch (1352:6): [True: 0, False: 29.2k]
  ------------------
 1353|      0|		return NULL;
 1354|  29.2k|	if (driver) {
  ------------------
  |  Branch (1354:6): [True: 12.7k, False: 16.4k]
  ------------------
 1355|  12.7k|		drv = driver;
 1356|  12.7k|		table = drv->atr_map;
 1357|  12.7k|		res = match_atr_table(ctx, table, atr);
 1358|  12.7k|		if (res < 0)
  ------------------
  |  Branch (1358:7): [True: 12.7k, False: 0]
  ------------------
 1359|  12.7k|			return NULL;
 1360|      0|		return table[res].card_atr;
 1361|  16.4k|	} else {
 1362|  16.4k|		unsigned int i;
 1363|       |
 1364|   758k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (1364:15): [True: 742k, False: 16.4k]
  ------------------
 1365|   742k|			drv = ctx->card_drivers[i];
 1366|   742k|			table = drv->atr_map;
 1367|   742k|			res = match_atr_table(ctx, table, atr);
 1368|   742k|			if (res < 0)
  ------------------
  |  Branch (1368:8): [True: 742k, False: 0]
  ------------------
 1369|   742k|				continue;
 1370|      0|			return table[res].card_atr;
 1371|   742k|		}
 1372|  16.4k|	}
 1373|  16.4k|	return NULL;
 1374|  29.2k|}
sc_get_conf_block:
 1445|  92.5k|{
 1446|  92.5k|	int i;
 1447|  92.5k|	scconf_block *conf_block = NULL;
 1448|       |
 1449|   185k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (1449:14): [True: 92.5k, False: 92.5k]
  ------------------
 1450|  92.5k|		scconf_block **blocks;
 1451|       |
 1452|  92.5k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], name1, name2);
 1453|  92.5k|		if (blocks != NULL) {
  ------------------
  |  Branch (1453:7): [True: 92.5k, False: 0]
  ------------------
 1454|  92.5k|			conf_block = blocks[0];
 1455|  92.5k|			free(blocks);
 1456|  92.5k|		}
 1457|  92.5k|		if (conf_block != NULL && priority)
  ------------------
  |  Branch (1457:7): [True: 0, False: 92.5k]
  |  Branch (1457:29): [True: 0, False: 0]
  ------------------
 1458|      0|			break;
 1459|  92.5k|	}
 1460|  92.5k|	return conf_block;
 1461|  92.5k|}
sc_clear_ec_params:
 1465|  7.80k|{
 1466|  7.80k|	if (ecp) {
  ------------------
  |  Branch (1466:6): [True: 7.80k, False: 0]
  ------------------
 1467|  7.80k|		free(ecp->named_curve);
 1468|  7.80k|		free(ecp->der.value);
 1469|  7.80k|		memset(ecp, 0, sizeof(struct sc_ec_parameters));
 1470|  7.80k|	}
 1471|  7.80k|	return;
 1472|  7.80k|}
sc_match_atr_block:
 1504|  11.3k|{
 1505|  11.3k|	return _sc_match_atr_block(ctx, driver, atr);
 1506|  11.3k|}
card.c:sc_card_new:
  127|  15.7k|{
  128|  15.7k|	sc_card_t *card;
  129|       |
  130|  15.7k|	if (ctx == NULL)
  ------------------
  |  Branch (130:6): [True: 0, False: 15.7k]
  ------------------
  131|      0|		return NULL;
  132|       |
  133|  15.7k|	card = calloc(1, sizeof(struct sc_card));
  134|  15.7k|	if (card == NULL)
  ------------------
  |  Branch (134:6): [True: 0, False: 15.7k]
  ------------------
  135|      0|		return NULL;
  136|  15.7k|	card->ops = malloc(sizeof(struct sc_card_operations));
  137|  15.7k|	if (card->ops == NULL) {
  ------------------
  |  Branch (137:6): [True: 0, False: 15.7k]
  ------------------
  138|      0|		free(card);
  139|      0|		return NULL;
  140|      0|	}
  141|       |
  142|  15.7k|	card->ctx = ctx;
  143|  15.7k|	if (sc_mutex_create(ctx, &card->mutex) != SC_SUCCESS) {
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (143:6): [True: 0, False: 15.7k]
  ------------------
  144|      0|		free(card->ops);
  145|      0|		free(card);
  146|      0|		return NULL;
  147|      0|	}
  148|       |
  149|  15.7k|	card->type = -1;
  150|  15.7k|	card->app_count = -1;
  151|       |
  152|  15.7k|	return card;
  153|  15.7k|}
card.c:sc_card_free:
  156|  15.7k|{
  157|  15.7k|	sc_free_apps(card);
  158|  15.7k|	sc_free_ef_atr(card);
  159|       |
  160|  15.7k|	free(card->ops);
  161|       |
  162|  15.7k|	if (card->algorithms != NULL)   {
  ------------------
  |  Branch (162:6): [True: 11.4k, False: 4.33k]
  ------------------
  163|  11.4k|		int i;
  164|  56.6k|		for (i=0; i<card->algorithm_count; i++)   {
  ------------------
  |  Branch (164:13): [True: 45.2k, False: 11.4k]
  ------------------
  165|  45.2k|			struct sc_algorithm_info *info = (card->algorithms + i);
  166|  45.2k|			if (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   70|  90.4k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (166:8): [True: 7.58k, False: 37.6k]
  ------------------
  167|  37.6k|					info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|  82.8k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (167:6): [True: 110, False: 37.5k]
  ------------------
  168|  37.5k|					info->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|  37.5k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (168:6): [True: 110, False: 37.3k]
  ------------------
  169|  7.80k|				sc_clear_ec_params(&info->u._ec.params);
  170|  7.80k|			}
  171|  45.2k|		}
  172|  11.4k|		free(card->algorithms);
  173|       |
  174|  11.4k|		card->algorithms = NULL;
  175|  11.4k|		card->algorithm_count = 0;
  176|  11.4k|	}
  177|       |
  178|  15.7k|	if (card->mutex != NULL) {
  ------------------
  |  Branch (178:6): [True: 0, False: 15.7k]
  ------------------
  179|      0|		int r = sc_mutex_destroy(card->ctx, card->mutex);
  180|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (180:7): [True: 0, False: 0]
  ------------------
  181|      0|			sc_log(card->ctx, "unable to destroy mutex");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  182|      0|	}
  183|  15.7k|	sc_mem_clear(card, sizeof(*card));
  184|  15.7k|	free(card);
  185|  15.7k|}
card.c:_sc_card_add_ec_alg_int:
 1146|  7.80k|{
 1147|  7.80k|	sc_algorithm_info_t info;
 1148|  7.80k|	int r;
 1149|       |
 1150|  7.80k|	memset(&info, 0, sizeof(info));
 1151|  7.80k|	sc_init_oid(&info.u._ec.params.id);
 1152|       |
 1153|  7.80k|	info.algorithm = algorithm;
 1154|  7.80k|	info.key_length = key_length;
 1155|  7.80k|	info.flags = flags;
 1156|       |
 1157|  7.80k|	info.u._ec.ext_flags = ext_flags;
 1158|  7.80k|	if (curve_oid) {
  ------------------
  |  Branch (1158:6): [True: 3.01k, False: 4.78k]
  ------------------
 1159|  3.01k|		info.u._ec.params.id = *curve_oid;
 1160|  3.01k|		r = sc_encode_oid(card->ctx, &info.u._ec.params.id, &info.u._ec.params.der.value, &info.u._ec.params.der.len);
 1161|  3.01k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_encode_oid failed");
  ------------------
  |  |  184|  3.01k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  3.01k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  3.01k|	int _ret = (r); \
  |  |  |  |  178|  3.01k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 3.01k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1162|  3.01k|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &info.u._ec.params);
 1163|  3.01k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_pkcs15_fix_ec_parameters failed");
  ------------------
  |  |  184|  3.01k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  3.01k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  3.01k|	int _ret = (r); \
  |  |  |  |  178|  3.01k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 3.01k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|  3.01k|	}
 1165|       |
 1166|  7.80k|	r = _sc_card_add_algorithm(card, &info);
 1167|  7.80k|	return r;
 1168|      0|err:
 1169|      0|	sc_clear_ec_params(&info.u._ec.params);
 1170|      0|	return r;
 1171|  7.80k|}
card.c:match_atr_table:
 1270|  1.10M|{
 1271|  1.10M|	u8 *card_atr_bin;
 1272|  1.10M|	size_t card_atr_bin_len;
 1273|  1.10M|	char card_atr_hex[3 * SC_MAX_ATR_SIZE];
 1274|  1.10M|	size_t card_atr_hex_len;
 1275|  1.10M|	unsigned int i = 0;
 1276|       |
 1277|  1.10M|	if (ctx == NULL || table == NULL || atr == NULL)
  ------------------
  |  Branch (1277:6): [True: 0, False: 1.10M]
  |  Branch (1277:21): [True: 754k, False: 347k]
  |  Branch (1277:38): [True: 0, False: 347k]
  ------------------
 1278|   754k|		return -1;
 1279|   347k|	card_atr_bin = atr->value;
 1280|   347k|	card_atr_bin_len = atr->len;
 1281|   347k|	sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
 1282|   347k|	card_atr_hex_len = strlen(card_atr_hex);
 1283|       |
 1284|   347k|	sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR     : %s", card_atr_hex);
  ------------------
  |  |   70|   347k|#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.93M|	for (i = 0; table[i].atr != NULL; i++) {
  ------------------
  |  Branch (1286:14): [True: 2.59M, False: 337k]
  ------------------
 1287|  2.59M|		const char *tatr = table[i].atr;
 1288|  2.59M|		const char *matr = table[i].atrmask;
 1289|  2.59M|		size_t tatr_len = strlen(tatr);
 1290|  2.59M|		u8 mbin[SC_MAX_ATR_SIZE], tbin[SC_MAX_ATR_SIZE];
 1291|  2.59M|		size_t mbin_len, tbin_len, s, matr_len;
 1292|  2.59M|		size_t fix_hex_len = card_atr_hex_len;
 1293|  2.59M|		size_t fix_bin_len = card_atr_bin_len;
 1294|       |
 1295|  2.59M|		sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR try : %s", tatr);
  ------------------
  |  |   70|  2.59M|#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.59M|		if (tatr_len != fix_hex_len) {
  ------------------
  |  Branch (1297:7): [True: 2.51M, False: 78.6k]
  ------------------
 1298|  2.51M|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ignored - wrong length");
  ------------------
  |  |   70|  2.51M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1299|  2.51M|			continue;
 1300|  2.51M|		}
 1301|  78.6k|		if (matr != NULL) {
  ------------------
  |  Branch (1301:7): [True: 19.6k, False: 58.9k]
  ------------------
 1302|  19.6k|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR mask: %s", matr);
  ------------------
  |  |   70|  19.6k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1303|       |
 1304|  19.6k|			matr_len = strlen(matr);
 1305|  19.6k|			if (tatr_len != matr_len)
  ------------------
  |  Branch (1305:8): [True: 0, False: 19.6k]
  ------------------
 1306|      0|				continue;
 1307|  19.6k|			tbin_len = sizeof(tbin);
 1308|  19.6k|			sc_hex_to_bin(tatr, tbin, &tbin_len);
 1309|  19.6k|			mbin_len = sizeof(mbin);
 1310|  19.6k|			sc_hex_to_bin(matr, mbin, &mbin_len);
 1311|  19.6k|			if (mbin_len != fix_bin_len) {
  ------------------
  |  Branch (1311:8): [True: 0, False: 19.6k]
  ------------------
 1312|      0|				sc_debug(ctx, SC_LOG_DEBUG_MATCH, "length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1313|      0|				continue;
 1314|      0|			}
 1315|   394k|			for (s = 0; s < tbin_len; s++) {
  ------------------
  |  Branch (1315:16): [True: 374k, False: 19.6k]
  ------------------
 1316|       |				/* reduce tatr with mask */
 1317|   374k|				tbin[s] = (tbin[s] & mbin[s]);
 1318|       |				/* create copy of card_atr_bin masked) */
 1319|   374k|				mbin[s] = (card_atr_bin[s] & mbin[s]);
 1320|   374k|			}
 1321|  19.6k|			if (memcmp(tbin, mbin, tbin_len) != 0)
  ------------------
  |  Branch (1321:8): [True: 15.2k, False: 4.45k]
  ------------------
 1322|  15.2k|				continue;
 1323|  58.9k|		} else {
 1324|  58.9k|			if (strncasecmp(tatr, card_atr_hex, tatr_len) != 0)
  ------------------
  |  Branch (1324:8): [True: 53.3k, False: 5.68k]
  ------------------
 1325|  53.3k|				continue;
 1326|  58.9k|		}
 1327|  10.1k|		return i;
 1328|  78.6k|	}
 1329|   337k|	return -1;
 1330|   347k|}
card.c:sc_card_sm_unload:
 1511|  12.7k|{
 1512|  12.7k|	if (card->sm_ctx.module.ops.module_cleanup)
  ------------------
  |  Branch (1512:6): [True: 0, False: 12.7k]
  ------------------
 1513|      0|		card->sm_ctx.module.ops.module_cleanup(card->ctx);
 1514|       |
 1515|  12.7k|	if (card->sm_ctx.module.handle)
  ------------------
  |  Branch (1515:6): [True: 0, False: 12.7k]
  ------------------
 1516|      0|		sc_dlclose(card->sm_ctx.module.handle);
 1517|       |	card->sm_ctx.module.handle = NULL;
 1518|  12.7k|	return 0;
 1519|  12.7k|}
card.c:sc_card_sm_check:
 1614|  12.7k|{
 1615|  12.7k|	const char *sm = NULL, *module_name = NULL, *module_path = NULL, *module_data = NULL, *sm_mode = NULL;
 1616|  12.7k|	struct sc_context *ctx = card->ctx;
 1617|  12.7k|	scconf_block *atrblock = NULL, *sm_conf_block = NULL;
 1618|  12.7k|	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|  12.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1627|       |
 1628|       |	/* get the name of card specific SM configuration section */
 1629|  12.7k|	atrblock = _sc_match_atr_block(ctx, card->driver, &card->atr);
 1630|  12.7k|	if (atrblock == NULL)
  ------------------
  |  Branch (1630:6): [True: 12.7k, False: 0]
  ------------------
 1631|  12.7k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.7k|	int _ret = r; \
  |  |  |  |  155|  12.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.7k|	return _ret; \
  |  |  |  |  163|  12.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    161|{
  255|    161|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (255:6): [True: 0, False: 161]
  |  Branch (255:20): [True: 0, False: 161]
  ------------------
  256|      0|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      0|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  257|      0|	}
  258|       |
  259|    161|	if (method == COMPRESSION_AUTO) {
  ------------------
  |  |   26|    161|#define COMPRESSION_AUTO	0
  ------------------
  |  Branch (259:6): [True: 160, False: 1]
  ------------------
  260|    160|		method = detect_method(in, inLen);
  261|    160|		if (method == COMPRESSION_UNKNOWN) {
  ------------------
  |  |   29|    160|#define COMPRESSION_UNKNOWN (-1)
  ------------------
  |  Branch (261:7): [True: 68, False: 92]
  ------------------
  262|     68|			return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     68|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  263|     68|		}
  264|    160|	}
  265|       |
  266|     93|	switch (method) {
  267|     87|	case COMPRESSION_ZLIB:
  ------------------
  |  |   27|     87|#define COMPRESSION_ZLIB	1
  ------------------
  |  Branch (267:2): [True: 87, False: 6]
  ------------------
  268|     87|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 0);
  269|      6|	case COMPRESSION_GZIP:
  ------------------
  |  |   28|      6|#define COMPRESSION_GZIP	2
  ------------------
  |  Branch (269:2): [True: 6, False: 87]
  ------------------
  270|      6|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 1);
  271|      0|	default:
  ------------------
  |  Branch (271:2): [True: 0, False: 93]
  ------------------
  272|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  273|     93|	}
  274|     93|}
compression.c:zerr_to_opensc:
   34|     93|static int zerr_to_opensc(int err) {
   35|     93|	switch(err) {
   36|      0|	case Z_OK:
  ------------------
  |  Branch (36:2): [True: 0, False: 93]
  ------------------
   37|      0|	case Z_STREAM_END:
  ------------------
  |  Branch (37:2): [True: 0, False: 93]
  ------------------
   38|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
   39|     19|	case Z_UNKNOWN:
  ------------------
  |  Branch (39:2): [True: 19, False: 74]
  ------------------
   40|     19|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     19|#define SC_ERROR_UNKNOWN			-1900
  ------------------
   41|     52|	case Z_DATA_ERROR:
  ------------------
  |  Branch (41:2): [True: 52, False: 41]
  ------------------
   42|     74|	case Z_BUF_ERROR:
  ------------------
  |  Branch (42:2): [True: 22, False: 71]
  ------------------
   43|     74|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     74|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   44|      0|	case Z_MEM_ERROR:
  ------------------
  |  Branch (44:2): [True: 0, False: 93]
  ------------------
   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: 93]
  ------------------
   47|      0|	case Z_STREAM_ERROR:
  ------------------
  |  Branch (47:2): [True: 0, False: 93]
  ------------------
   48|       |	/* case Z_NEED_DICT: */
   49|      0|	default:
  ------------------
  |  Branch (49:2): [True: 0, False: 93]
  ------------------
   50|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   51|     93|	}
   52|     93|}
compression.c:detect_method:
   53|    160|static int detect_method(const u8* in, size_t inLen) {
   54|    160|	if (in != NULL && inLen > 1) {
  ------------------
  |  Branch (54:6): [True: 160, False: 0]
  |  Branch (54:20): [True: 135, False: 25]
  ------------------
   55|    135|		if (in[0] == 0x1f && in[1] == 0x8b)
  ------------------
  |  Branch (55:7): [True: 12, False: 123]
  |  Branch (55:24): [True: 6, False: 6]
  ------------------
   56|      6|			return COMPRESSION_GZIP;
  ------------------
  |  |   28|      6|#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|    129|		if ((((uint16_t) in[0])*256 + in[1]) % 31 == 0)
  ------------------
  |  Branch (75:7): [True: 86, False: 43]
  ------------------
   76|     86|			return COMPRESSION_ZLIB;
  ------------------
  |  |   27|     86|#define COMPRESSION_ZLIB	1
  ------------------
   77|    129|	}
   78|     68|	return COMPRESSION_UNKNOWN;
  ------------------
  |  |   29|     68|#define COMPRESSION_UNKNOWN (-1)
  ------------------
   79|    160|}
compression.c:sc_decompress_zlib_alloc:
  185|     93|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|     93|	z_stream gz;
  188|     93|	int err;
  189|     93|	int window_size = 15;
  190|     93|	const size_t startSize = inLen < 1024 ? 2048 : inLen * 2;
  ------------------
  |  Branch (190:27): [True: 67, False: 26]
  ------------------
  191|     93|	const size_t blockSize = inLen < 1024 ? 512 : inLen / 2;
  ------------------
  |  Branch (191:27): [True: 67, False: 26]
  ------------------
  192|     93|	size_t bufferSize = startSize;
  193|     93|	if (gzip)
  ------------------
  |  Branch (193:6): [True: 6, False: 87]
  ------------------
  194|      6|		window_size += 0x20;
  195|     93|	memset(&gz, 0, sizeof(gz));
  196|       |
  197|     93|	if (!out || !outLen)
  ------------------
  |  Branch (197:6): [True: 0, False: 93]
  |  Branch (197:14): [True: 0, False: 93]
  ------------------
  198|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  199|       |
  200|     93|	gz.next_in = (u8*)in;
  201|     93|	gz.avail_in = (unsigned)inLen;
  202|       |
  203|     93|	err = inflateInit2(&gz, window_size);
  204|     93|	if (err != Z_OK)
  ------------------
  |  Branch (204:6): [True: 0, False: 93]
  ------------------
  205|      0|		return zerr_to_opensc(err);
  206|       |
  207|     93|	*outLen = 0;
  208|       |
  209|    261|	while (1) {
  ------------------
  |  Branch (209:9): [True: 261, Folded]
  ------------------
  210|       |		/* Setup buffer... */
  211|    261|		size_t num;
  212|    261|		u8* buf = realloc(*out, bufferSize);
  213|    261|		if (!buf) {
  ------------------
  |  Branch (213:7): [True: 0, False: 261]
  ------------------
  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|    261|		*out = buf;
  220|    261|		gz.next_out = buf + *outLen;
  221|    261|		gz.avail_out = (unsigned)(bufferSize - *outLen);
  222|       |
  223|    261|		err = inflate(&gz, Z_FULL_FLUSH);
  224|    261|		if (err != Z_STREAM_END && err != Z_OK) {
  ------------------
  |  Branch (224:7): [True: 261, False: 0]
  |  Branch (224:30): [True: 93, False: 168]
  ------------------
  225|     93|			free(*out);
  226|     93|			*out = NULL;
  227|     93|			break;
  228|     93|		}
  229|    168|		num = *outLen + gz.avail_out;
  230|    168|		if (bufferSize > num) {
  ------------------
  |  Branch (230:7): [True: 166, False: 2]
  ------------------
  231|    166|			*outLen += bufferSize - num;
  232|    166|			bufferSize += bufferSize - num + blockSize;
  233|    166|		}
  234|    168|		if (err == Z_STREAM_END) {
  ------------------
  |  Branch (234:7): [True: 0, False: 168]
  ------------------
  235|      0|			if (*outLen > 0) {
  ------------------
  |  Branch (235:8): [True: 0, False: 0]
  ------------------
  236|       |				/* Shrink it down, if it fails, just use old data */
  237|      0|				buf = realloc(buf, *outLen);
  238|      0|				if (buf) {
  ------------------
  |  Branch (238:9): [True: 0, False: 0]
  ------------------
  239|      0|					*out = buf;
  240|      0|				}
  241|      0|			} else {
  242|      0|				free(*out);
  243|      0|				*out = NULL;
  244|      0|				err = Z_DATA_ERROR;
  245|      0|			}
  246|      0|			break;
  247|      0|		}
  248|    168|	}
  249|     93|	inflateEnd(&gz);
  250|     93|	return zerr_to_opensc(err);
  251|     93|}

_sc_delete_reader:
   86|  15.7k|{
   87|  15.7k|	if (reader == NULL) {
  ------------------
  |  Branch (87:6): [True: 0, False: 15.7k]
  ------------------
   88|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   89|      0|	}
   90|  15.7k|	if (reader->ops->release)
  ------------------
  |  Branch (90:6): [True: 15.7k, False: 0]
  ------------------
   91|  15.7k|			reader->ops->release(reader);
   92|  15.7k|	free(reader->name);
   93|  15.7k|	free(reader->vendor);
   94|  15.7k|	list_delete(&ctx->readers, reader);
   95|  15.7k|	free(reader);
   96|  15.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
   97|  15.7k|}
sc_ctx_detect_readers:
  782|  15.7k|{
  783|  15.7k|	int r = 0;
  784|  15.7k|	const struct sc_reader_driver *drv = ctx->reader_driver;
  785|       |
  786|  15.7k|	sc_mutex_lock(ctx, ctx->mutex);
  787|       |
  788|  15.7k|	if (drv->ops->detect_readers != NULL)
  ------------------
  |  Branch (788:6): [True: 0, False: 15.7k]
  ------------------
  789|      0|		r = drv->ops->detect_readers(ctx);
  790|       |
  791|  15.7k|	sc_mutex_unlock(ctx, ctx->mutex);
  792|       |
  793|  15.7k|	return r;
  794|  15.7k|}
sc_ctx_get_reader:
  797|  31.5k|{
  798|  31.5k|	return list_get_at(&ctx->readers, i);
  799|  31.5k|}
sc_ctx_get_reader_count:
  812|  47.3k|{
  813|  47.3k|	return list_size(&ctx->readers);
  814|  47.3k|}
sc_context_create:
  946|  15.7k|{
  947|  15.7k|	sc_context_t		*ctx;
  948|  15.7k|	struct _sc_ctx_options	opts;
  949|  15.7k|	int			r;
  950|  15.7k|	char			*driver;
  951|       |
  952|  15.7k|	if (ctx_out == NULL || parm == NULL)
  ------------------
  |  Branch (952:6): [True: 0, False: 15.7k]
  |  Branch (952:25): [True: 0, False: 15.7k]
  ------------------
  953|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  954|       |
  955|  15.7k|	ctx = calloc(1, sizeof(sc_context_t));
  956|  15.7k|	if (ctx == NULL)
  ------------------
  |  Branch (956:6): [True: 0, False: 15.7k]
  ------------------
  957|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  958|  15.7k|	memset(&opts, 0, sizeof(opts));
  959|       |
  960|       |	/* set the application name if set in the parameter options */
  961|  15.7k|	if (parm->app_name != NULL)
  ------------------
  |  Branch (961:6): [True: 15.7k, False: 0]
  ------------------
  962|  15.7k|		ctx->app_name = strdup(parm->app_name);
  963|      0|	else
  964|      0|		ctx->app_name = strdup("default");
  965|  15.7k|	if (ctx->app_name == NULL) {
  ------------------
  |  Branch (965:6): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	ctx->exe_path = get_exe_path();
  971|  15.7k|	if (ctx->exe_path == NULL) {
  ------------------
  |  Branch (971:6): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	ctx->flags = parm->flags;
  977|  15.7k|	set_defaults(ctx, &opts);
  978|       |
  979|  15.7k|	if (0 != list_init(&ctx->readers)) {
  ------------------
  |  Branch (979:6): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	list_attributes_seeker(&ctx->readers, reader_list_seeker);
  985|       |	/* set thread context and create mutex object (if specified) */
  986|  15.7k|	if (parm->thread_ctx != NULL)
  ------------------
  |  Branch (986:6): [True: 15.7k, False: 0]
  ------------------
  987|  15.7k|		ctx->thread_ctx = parm->thread_ctx;
  988|  15.7k|	r = sc_mutex_create(ctx, &ctx->mutex);
  989|  15.7k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (989:6): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	process_config_file(ctx, &opts);
 1002|       |
 1003|       |	/* overwrite with caller's parameters if explicitly given */
 1004|  15.7k|	if (parm->debug) {
  ------------------
  |  Branch (1004:6): [True: 0, False: 15.7k]
  ------------------
 1005|      0|		ctx->debug = parm->debug;
 1006|      0|	}
 1007|  15.7k|	if (parm->debug_file) {
  ------------------
  |  Branch (1007:6): [True: 0, False: 15.7k]
  ------------------
 1008|      0|		if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (1008:7): [True: 0, False: 0]
  |  Branch (1008:27): [True: 0, False: 0]
  |  Branch (1008:56): [True: 0, False: 0]
  ------------------
 1009|      0|			fclose(ctx->debug_file);
 1010|      0|		ctx->debug_file = parm->debug_file;
 1011|      0|	}
 1012|       |
 1013|  15.7k|	sc_log(ctx, "==================================="); /* first thing in the log */
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1014|  15.7k|	sc_log(ctx, "OpenSC version: %s", sc_get_version());
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1015|  15.7k|	sc_log(ctx, "Configured for %s (%s)", ctx->app_name, ctx->exe_path);
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 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|  15.7k|	r = ctx->reader_driver->ops->init(ctx);
 1039|  15.7k|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1039:6): [True: 0, False: 15.7k]
  ------------------
 1040|      0|		del_drvs(&opts);
 1041|      0|		sc_release_context(ctx);
 1042|      0|		return r;
 1043|      0|	}
 1044|       |
 1045|  15.7k|	driver = getenv("OPENSC_DRIVER");
 1046|  15.7k|	if (driver) {
  ------------------
  |  Branch (1046:6): [True: 0, False: 15.7k]
  ------------------
 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|  15.7k|	load_card_drivers(ctx, &opts);
 1054|  15.7k|	load_card_atrs(ctx);
 1055|       |
 1056|  15.7k|	del_drvs(&opts);
 1057|  15.7k|	sc_ctx_detect_readers(ctx);
 1058|  15.7k|	*ctx_out = ctx;
 1059|       |
 1060|  15.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
 1061|  15.7k|}
sc_cancel:
 1075|  15.7k|{
 1076|  15.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  15.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  15.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  15.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  15.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 15.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1077|  15.7k|	if (ctx->reader_driver->ops->cancel != NULL)
  ------------------
  |  Branch (1077:6): [True: 0, False: 15.7k]
  ------------------
 1078|      0|		return ctx->reader_driver->ops->cancel(ctx);
 1079|       |
 1080|  15.7k|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  15.7k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1081|  15.7k|}
sc_wait_for_event:
 1085|  31.5k|{
 1086|  31.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  31.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  31.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  31.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  31.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 31.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|  31.5k|	if (ctx->reader_driver->ops->wait_for_event != NULL)
  ------------------
  |  Branch (1087:6): [True: 0, False: 31.5k]
  ------------------
 1088|      0|		return ctx->reader_driver->ops->wait_for_event(ctx, event_mask, event_reader, event, timeout, reader_states);
 1089|       |
 1090|  31.5k|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  31.5k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1091|  31.5k|}
sc_release_context:
 1094|  15.7k|{
 1095|  15.7k|	unsigned int i;
 1096|       |
 1097|  15.7k|	if (ctx == NULL) {
  ------------------
  |  Branch (1097:6): [True: 0, False: 15.7k]
  ------------------
 1098|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1099|      0|	}
 1100|  15.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.7k]
  |  |  ------------------
  ------------------
 1101|  31.5k|	while (list_size(&ctx->readers)) {
  ------------------
  |  Branch (1101:9): [True: 15.7k, False: 15.7k]
  ------------------
 1102|  15.7k|		sc_reader_t *rdr = (sc_reader_t *) list_get_at(&ctx->readers, 0);
 1103|  15.7k|		_sc_delete_reader(ctx, rdr);
 1104|  15.7k|	}
 1105|       |
 1106|  15.7k|	if (ctx->reader_driver != NULL && ctx->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (1106:6): [True: 15.7k, False: 0]
  |  Branch (1106:36): [True: 0, False: 15.7k]
  ------------------
 1107|      0|		ctx->reader_driver->ops->finish(ctx);
 1108|       |
 1109|   725k|	for (i = 0; ctx->card_drivers[i]; i++) {
  ------------------
  |  Branch (1109:14): [True: 709k, False: 15.7k]
  ------------------
 1110|   709k|		struct sc_card_driver *drv = ctx->card_drivers[i];
 1111|       |
 1112|   709k|		if (drv->atr_map)
  ------------------
  |  Branch (1112:7): [True: 0, False: 709k]
  ------------------
 1113|      0|			_sc_free_atr(ctx, drv);
 1114|   709k|		if (drv->dll)
  ------------------
  |  Branch (1114:7): [True: 0, False: 709k]
  ------------------
 1115|      0|			sc_dlclose(drv->dll);
 1116|   709k|	}
 1117|       |#ifdef USE_OPENSSL3_LIBCTX
 1118|       |	sc_openssl3_deinit(ctx);
 1119|       |#endif
 1120|  15.7k|	if (ctx->preferred_language != NULL)
  ------------------
  |  Branch (1120:6): [True: 0, False: 15.7k]
  ------------------
 1121|      0|		free(ctx->preferred_language);
 1122|  15.7k|	if (ctx->mutex != NULL) {
  ------------------
  |  Branch (1122:6): [True: 0, False: 15.7k]
  ------------------
 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|  15.7k|	if (ctx->conf != NULL)
  ------------------
  |  Branch (1129:6): [True: 15.7k, False: 0]
  ------------------
 1130|  15.7k|		scconf_free(ctx->conf);
 1131|  15.7k|	if (ctx->debug_file && (ctx->debug_file != stdout && ctx->debug_file != stderr))
  ------------------
  |  Branch (1131:6): [True: 15.7k, False: 0]
  |  Branch (1131:26): [True: 15.7k, False: 0]
  |  Branch (1131:55): [True: 0, False: 15.7k]
  ------------------
 1132|      0|		fclose(ctx->debug_file);
 1133|  15.7k|	free(ctx->debug_filename);
 1134|  15.7k|	free(ctx->app_name);
 1135|  15.7k|	free(ctx->exe_path);
 1136|  15.7k|	list_destroy(&ctx->readers);
 1137|  15.7k|	sc_mem_clear(ctx, sizeof(*ctx));
 1138|  15.7k|	free(ctx);
 1139|  15.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
 1140|  15.7k|}
sc_get_cache_dir:
 1167|  2.68k|{
 1168|  2.68k|	char *homedir;
 1169|  2.68k|	const char *cache_dir;
 1170|  2.68k|        scconf_block *conf_block = NULL;
 1171|       |#ifdef _WIN32
 1172|       |	char temp_path[PATH_MAX];
 1173|       |#endif
 1174|  2.68k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1175|  2.68k|	cache_dir = scconf_get_str(conf_block, "file_cache_dir", NULL);
 1176|  2.68k|	if (cache_dir != NULL) {
  ------------------
  |  Branch (1176:6): [True: 0, False: 2.68k]
  ------------------
 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.68k|#ifndef _WIN32
 1182|       |#ifdef __APPLE__
 1183|       |	cache_dir = getenv("Caches");
 1184|       |#else
 1185|  2.68k|	cache_dir = getenv("XDG_CACHE_HOME");
 1186|  2.68k|#endif
 1187|  2.68k|	if (cache_dir != NULL && cache_dir[0] != '\0') {
  ------------------
  |  Branch (1187:6): [True: 0, False: 2.68k]
  |  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.68k|	cache_dir = ".cache/opensc";
 1192|  2.68k|	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.68k|	if (homedir == NULL || homedir[0] == '\0')
  ------------------
  |  Branch (1203:6): [True: 0, False: 2.68k]
  |  Branch (1203:25): [True: 0, False: 2.68k]
  ------------------
 1204|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1205|  2.68k|	if (snprintf(buf, bufsize, "%s/%s", homedir, cache_dir) < 0)
  ------------------
  |  Branch (1205:6): [True: 0, False: 2.68k]
  ------------------
 1206|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1207|  2.68k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.68k|#define SC_SUCCESS				0
  ------------------
 1208|  2.68k|}
sc_make_cache_dir:
 1211|     43|{
 1212|     43|	char dirname[PATH_MAX], *sp;
 1213|     43|	int    r, mkdir_checker;
 1214|     43|	size_t j, namelen;
 1215|       |
 1216|     43|	if ((r = sc_get_cache_dir(ctx, dirname, sizeof(dirname))) < 0)
  ------------------
  |  Branch (1216:6): [True: 0, False: 43]
  ------------------
 1217|      0|		return r;
 1218|     43|	namelen = strlen(dirname);
 1219|       |
 1220|     43|	while (1) {
  ------------------
  |  Branch (1220:9): [True: 43, Folded]
  ------------------
 1221|       |#ifdef _WIN32
 1222|       |		mkdir_checker = mkdir(dirname) >= 0;
 1223|       |#else
 1224|     43|		mkdir_checker = mkdir(dirname, 0700) >= 0;
 1225|     43|#endif
 1226|     43|		if (mkdir_checker)
  ------------------
  |  Branch (1226:7): [True: 0, False: 43]
  ------------------
 1227|      0|			break;
 1228|       |
 1229|     43|		if (errno != ENOENT || (sp = strrchr(dirname, '/')) == NULL
  ------------------
  |  Branch (1229:7): [True: 43, False: 0]
  |  Branch (1229:26): [True: 0, False: 0]
  ------------------
 1230|      0|				|| sp == dirname)
  ------------------
  |  Branch (1230:8): [True: 0, False: 0]
  ------------------
 1231|     43|			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|      0|	while (1) {
  ------------------
  |  Branch (1237:9): [True: 0, Folded]
  ------------------
 1238|      0|		j = strlen(dirname);
 1239|      0|		if (j >= namelen)
  ------------------
  |  Branch (1239:7): [True: 0, False: 0]
  ------------------
 1240|      0|			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|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1251|       |
 1252|       |	/* for lack of a better return code */
 1253|     43|failed:
 1254|     43|	sc_log(ctx, "failed to create cache directory");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1255|     43|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     43|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1256|      0|}
ctx.c:load_card_atrs:
  630|  15.7k|{
  631|  15.7k|	struct sc_card_driver *driver;
  632|  15.7k|	scconf_block **blocks;
  633|  15.7k|	int i, j, k;
  634|       |
  635|  31.5k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (635:14): [True: 15.7k, False: 15.7k]
  ------------------
  636|  15.7k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], "card_atr", NULL);
  637|  15.7k|		if (!blocks)
  ------------------
  |  Branch (637:7): [True: 0, False: 15.7k]
  ------------------
  638|      0|			continue;
  639|  15.7k|		for (j = 0; blocks[j] != NULL; j++) {
  ------------------
  |  Branch (639:15): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|		free(blocks);
  701|  15.7k|	}
  702|  15.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  703|  15.7k|}
ctx.c:get_exe_path:
  911|  15.7k|{
  912|       |	/* Find the executable's path which runs this code.
  913|       |	 * See https://github.com/gpakosz/whereami/ for
  914|       |	 * potentially more platforms */
  915|  15.7k|	char exe_path[PATH_MAX] = "unknown executable path";
  916|  15.7k|	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|  15.7k|	if (NULL != realpath("/proc/self/exe", exe_path))
  ------------------
  |  Branch (925:6): [True: 15.7k, False: 0]
  ------------------
  926|  15.7k|		path_found = 1;
  927|  15.7k|#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|  15.7k|	(void) path_found;
  940|  15.7k|#endif
  941|       |
  942|  15.7k|	return strdup(exe_path);
  943|  15.7k|}
ctx.c:set_defaults:
  322|  15.7k|{
  323|  15.7k|	ctx->debug = 0;
  324|  15.7k|	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (324:6): [True: 0, False: 15.7k]
  |  Branch (324:26): [True: 0, False: 0]
  |  Branch (324:55): [True: 0, False: 0]
  ------------------
  325|      0|		fclose(ctx->debug_file);
  326|  15.7k|	ctx->debug_file = stderr;
  327|  15.7k|	ctx->flags = 0;
  328|       |	ctx->forced_driver = NULL;
  329|  15.7k|	add_internal_drvs(opts);
  330|  15.7k|}
ctx.c:add_internal_drvs:
  296|  31.5k|{
  297|  31.5k|	const struct _sc_driver_entry *lst;
  298|  31.5k|	int i;
  299|       |
  300|  31.5k|	lst = internal_card_drivers;
  301|  31.5k|	i = 0;
  302|  1.29M|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (302:9): [True: 1.26M, False: 31.5k]
  ------------------
  303|  1.26M|		add_drv(opts, lst[i].name);
  304|  1.26M|		i++;
  305|  1.26M|	}
  306|  31.5k|}
ctx.c:add_drv:
  278|  1.34M|{
  279|  1.34M|	struct _sc_driver_entry *lst;
  280|  1.34M|	int *cp, max, i;
  281|       |
  282|  1.34M|	lst = opts->cdrv;
  283|  1.34M|	cp = &opts->ccount;
  284|  1.34M|	max = SC_MAX_CARD_DRIVERS;
  ------------------
  |  |   31|  1.34M|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  285|  1.34M|	if (*cp == max) /* No space for more drivers... */
  ------------------
  |  Branch (285:6): [True: 0, False: 1.34M]
  ------------------
  286|      0|		return;
  287|  29.2M|	for (i = 0; i < *cp; i++)
  ------------------
  |  Branch (287:14): [True: 27.9M, False: 1.34M]
  ------------------
  288|  27.9M|		if (strcmp(name, lst[i].name) == 0)
  ------------------
  |  Branch (288:7): [True: 0, False: 27.9M]
  ------------------
  289|      0|			return;
  290|  1.34M|	lst[*cp].name = strdup(name);
  291|       |
  292|  1.34M|	*cp = *cp + 1;
  293|  1.34M|}
ctx.c:del_drvs:
  264|  31.5k|{
  265|  31.5k|	struct _sc_driver_entry *lst;
  266|  31.5k|	int *cp, i;
  267|       |
  268|  31.5k|	lst = opts->cdrv;
  269|  31.5k|	cp = &opts->ccount;
  270|       |
  271|  1.37M|	for (i = 0; i < *cp; i++) {
  ------------------
  |  Branch (271:14): [True: 1.34M, False: 31.5k]
  ------------------
  272|  1.34M|		free((void *)lst[i].name);
  273|  1.34M|	}
  274|  31.5k|	*cp = 0;
  275|  31.5k|}
ctx.c:process_config_file:
  706|  15.7k|{
  707|  15.7k|	int i, r, count = 0;
  708|  15.7k|	scconf_block **blocks;
  709|  15.7k|	const char *conf_path = NULL;
  710|  15.7k|	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|  15.7k|	debug = getenv("OPENSC_DEBUG");
  718|  15.7k|	if (debug)
  ------------------
  |  Branch (718:6): [True: 0, False: 15.7k]
  ------------------
  719|      0|		ctx->debug = atoi(debug);
  720|       |
  721|  15.7k|	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|  15.7k|	conf_path = getenv("OPENSC_CONF");
  734|  15.7k|	if (!conf_path)
  ------------------
  |  Branch (734:6): [True: 15.7k, False: 0]
  ------------------
  735|  15.7k|		conf_path = OPENSC_CONF_PATH;
  736|  15.7k|#endif
  737|  15.7k|	ctx->conf = scconf_new(conf_path);
  738|  15.7k|	if (ctx->conf == NULL)
  ------------------
  |  Branch (738:6): [True: 0, False: 15.7k]
  ------------------
  739|      0|		return;
  740|  15.7k|	r = scconf_parse(ctx->conf);
  741|  15.7k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  742|  15.7k|#ifdef OPENSC_CONFIG_STRING
  743|       |	/* Parse the string if config file didn't exist */
  744|  15.7k|	if (r < 0)
  ------------------
  |  Branch (744:6): [True: 15.7k, False: 0]
  ------------------
  745|  15.7k|		r = scconf_parse_string(ctx->conf, OPENSC_CONFIG_STRING);
  ------------------
  |  |  741|  15.7k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  ------------------
  746|  15.7k|#endif
  747|  15.7k|	if (r < 1) {
  ------------------
  |  Branch (747:6): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	sc_log(ctx, "Used configuration file '%s'", conf_path);
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  761|  15.7k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->exe_path);
  762|  15.7k|	if (blocks && blocks[0])
  ------------------
  |  Branch (762:6): [True: 15.7k, False: 0]
  |  Branch (762:16): [True: 0, False: 15.7k]
  ------------------
  763|      0|		ctx->conf_blocks[count++] = blocks[0];
  764|  15.7k|	free(blocks);
  765|  15.7k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->app_name);
  766|  15.7k|	if (blocks && blocks[0])
  ------------------
  |  Branch (766:6): [True: 15.7k, False: 0]
  |  Branch (766:16): [True: 0, False: 15.7k]
  ------------------
  767|      0|		ctx->conf_blocks[count++] = blocks[0];
  768|  15.7k|	free(blocks);
  769|  15.7k|	if (strcmp(ctx->app_name, "default") != 0) {
  ------------------
  |  Branch (769:6): [True: 15.7k, False: 0]
  ------------------
  770|  15.7k|		blocks = scconf_find_blocks(ctx->conf, NULL, "app", "default");
  771|  15.7k|		if (blocks && blocks[0])
  ------------------
  |  Branch (771:7): [True: 15.7k, False: 0]
  |  Branch (771:17): [True: 15.7k, False: 0]
  ------------------
  772|  15.7k|			ctx->conf_blocks[count] = blocks[0];
  773|  15.7k|		free(blocks);
  774|  15.7k|	}
  775|       |	/* Above we add 3 blocks at most, but conf_blocks has 4 elements,
  776|       |	 * so at least one is NULL */
  777|  31.5k|	for (i = 0; ctx->conf_blocks[i]; i++)
  ------------------
  |  Branch (777:14): [True: 15.7k, False: 15.7k]
  ------------------
  778|  15.7k|		load_parameters(ctx, ctx->conf_blocks[i], opts);
  779|  15.7k|}
ctx.c:load_parameters:
  385|  15.7k|{
  386|  15.7k|	int err = 0;
  387|  15.7k|	const scconf_list *list;
  388|  15.7k|	const char *val;
  389|  15.7k|	int debug;
  390|  15.7k|	const char *disable_hw_pkcs1_padding;
  391|       |#ifdef _WIN32
  392|       |	char expanded_val[PATH_MAX];
  393|       |	DWORD expanded_len;
  394|       |#endif
  395|       |
  396|  15.7k|	debug = scconf_get_int(block, "debug", ctx->debug);
  397|  15.7k|	if (debug > ctx->debug)
  ------------------
  |  Branch (397:6): [True: 0, False: 15.7k]
  ------------------
  398|      0|		ctx->debug = debug;
  399|       |
  400|  15.7k|	val = scconf_get_str(block, "debug_file", NULL);
  401|  15.7k|	if (val)   {
  ------------------
  |  Branch (401:6): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	else if (ctx->debug)   {
  ------------------
  |  Branch (410:11): [True: 0, False: 15.7k]
  ------------------
  411|      0|		sc_ctx_log_to_file(ctx, NULL);
  412|      0|	}
  413|       |
  414|  15.7k|	if (scconf_get_bool (block, "disable_popups",
  ------------------
  |  Branch (414:6): [True: 0, False: 15.7k]
  ------------------
  415|  15.7k|				ctx->flags & SC_CTX_FLAG_DISABLE_POPUPS))
  ------------------
  |  |  861|  15.7k|#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|  15.7k|	if (scconf_get_bool (block, "disable_colors",
  ------------------
  |  Branch (418:6): [True: 0, False: 15.7k]
  ------------------
  419|  15.7k|				ctx->flags & SC_CTX_FLAG_DISABLE_COLORS))
  ------------------
  |  |  862|  15.7k|#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|  15.7k|	if (scconf_get_bool (block, "enable_default_driver",
  ------------------
  |  Branch (422:6): [True: 0, False: 15.7k]
  ------------------
  423|  15.7k|				ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER))
  ------------------
  |  |  860|  15.7k|#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|  15.7k|	list = scconf_find_list(block, "card_drivers");
  427|  15.7k|	set_drivers(opts, list);
  428|       |
  429|       |	/* Disable PKCS#1 v1.5 type 2 (for decryption) depadding on card by default */
  430|  15.7k|	disable_hw_pkcs1_padding = "decipher";
  431|  15.7k|	ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  15.7k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  432|  15.7k|	disable_hw_pkcs1_padding = scconf_get_str(block, "disable_hw_pkcs1_padding", disable_hw_pkcs1_padding);
  433|  15.7k|	if (0 == strcmp(disable_hw_pkcs1_padding, "no")) {
  ------------------
  |  Branch (433:6): [True: 0, False: 15.7k]
  ------------------
  434|      0|		ctx->disable_hw_pkcs1_padding = 0;
  435|  15.7k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "sign")) {
  ------------------
  |  Branch (435:13): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "decipher")) {
  ------------------
  |  Branch (437:13): [True: 15.7k, False: 0]
  ------------------
  438|  15.7k|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  15.7k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  439|  15.7k|	} 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|  15.7k|	return err;
  451|  15.7k|}
ctx.c:set_drivers:
  368|  15.7k|{
  369|  15.7k|	const char *s_internal = "internal", *s_old = "old";
  370|  15.7k|	if (list != NULL)
  ------------------
  |  Branch (370:6): [True: 15.7k, False: 0]
  ------------------
  371|  15.7k|		del_drvs(opts);
  372|  47.3k|	while (list != NULL) {
  ------------------
  |  Branch (372:9): [True: 31.5k, False: 15.7k]
  ------------------
  373|  31.5k|		if (strcmp(list->data, s_internal) == 0)
  ------------------
  |  Branch (373:7): [True: 15.7k, False: 15.7k]
  ------------------
  374|  15.7k|			add_internal_drvs(opts);
  375|  15.7k|		else if (strcmp(list->data, s_old) == 0)
  ------------------
  |  Branch (375:12): [True: 15.7k, False: 0]
  ------------------
  376|  15.7k|			add_old_drvs(opts);
  377|      0|		else
  378|      0|			add_drv(opts, list->data);
  379|  31.5k|		list = list->next;
  380|  31.5k|	}
  381|  15.7k|}
ctx.c:add_old_drvs:
  309|  15.7k|{
  310|  15.7k|	const struct _sc_driver_entry *lst;
  311|  15.7k|	int i;
  312|       |
  313|  15.7k|	lst = old_card_drivers;
  314|  15.7k|	i = 0;
  315|  94.6k|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (315:9): [True: 78.8k, False: 15.7k]
  ------------------
  316|  78.8k|		add_drv(opts, lst[i].name);
  317|  78.8k|		i++;
  318|  78.8k|	}
  319|  15.7k|}
ctx.c:load_card_drivers:
  564|  15.7k|{
  565|  15.7k|	const struct _sc_driver_entry *ent;
  566|  15.7k|	int drv_count;
  567|  15.7k|	int i;
  568|       |
  569|  15.7k|	for (drv_count = 0; ctx->card_drivers[drv_count] != NULL; drv_count++)
  ------------------
  |  Branch (569:22): [True: 0, False: 15.7k]
  ------------------
  570|      0|		;
  571|       |
  572|   725k|	for (i = 0; i < opts->ccount; i++) {
  ------------------
  |  Branch (572:14): [True: 709k, False: 15.7k]
  ------------------
  573|   709k|		struct sc_card_driver *(*func)(void) = NULL;
  574|   709k|		struct sc_card_driver *(**tfunc)(void) = &func;
  575|   709k|		void *dll = NULL;
  576|   709k|		int  j;
  577|       |
  578|   709k|		if (drv_count >= SC_MAX_CARD_DRIVERS - 1)   {
  ------------------
  |  |   31|   709k|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  |  Branch (578:7): [True: 0, False: 709k]
  ------------------
  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|   709k|		ent = &opts->cdrv[i];
  584|  16.1M|		for (j = 0; internal_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (584:15): [True: 16.0M, False: 78.8k]
  ------------------
  585|  16.0M|			if (strcmp(ent->name, internal_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (585:8): [True: 630k, False: 15.4M]
  ------------------
  586|   630k|				func = (struct sc_card_driver *(*)(void)) internal_card_drivers[j].func;
  587|   630k|				break;
  588|   630k|			}
  589|  16.0M|		}
  590|   709k|		if (func == NULL) {
  ------------------
  |  Branch (590:7): [True: 78.8k, False: 630k]
  ------------------
  591|   236k|			for (j = 0; old_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (591:16): [True: 236k, False: 0]
  ------------------
  592|   236k|				if (strcmp(ent->name, old_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (592:9): [True: 78.8k, False: 157k]
  ------------------
  593|  78.8k|					func = (struct sc_card_driver *(*)(void)) old_card_drivers[j].func;
  594|  78.8k|					break;
  595|  78.8k|				}
  596|   236k|			}
  597|  78.8k|		}
  598|       |		/* if not initialized assume external module */
  599|   709k|		if (func == NULL)
  ------------------
  |  Branch (599:7): [True: 0, False: 709k]
  ------------------
  600|      0|			*(void **)(tfunc) = load_dynamic_driver(ctx, &dll, ent->name);
  601|       |		/* if still null, assume driver not found */
  602|   709k|		if (func == NULL) {
  ------------------
  |  Branch (602:7): [True: 0, False: 709k]
  ------------------
  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|   709k|		ctx->card_drivers[drv_count] = func();
  610|   709k|		if (ctx->card_drivers[drv_count] == NULL) {
  ------------------
  |  Branch (610:7): [True: 0, False: 709k]
  ------------------
  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|   709k|		ctx->card_drivers[drv_count]->dll = dll;
  616|   709k|		ctx->card_drivers[drv_count]->atr_map = NULL;
  617|   709k|		ctx->card_drivers[drv_count]->natrs = 0;
  618|       |
  619|   709k|		load_card_driver_options(ctx, ctx->card_drivers[drv_count]);
  620|       |
  621|       |		/* Ensure that the list is always terminated by NULL */
  622|   709k|		ctx->card_drivers[drv_count + 1] = NULL;
  623|       |
  624|   709k|		drv_count++;
  625|   709k|	}
  626|  15.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  627|  15.7k|}
ctx.c:load_card_driver_options:
  543|   709k|{
  544|   709k|	scconf_block **blocks, *blk;
  545|   709k|	int i;
  546|       |
  547|  1.41M|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (547:14): [True: 709k, False: 709k]
  ------------------
  548|   709k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  549|   709k|				"card_driver", driver->short_name);
  550|   709k|		if (!blocks)
  ------------------
  |  Branch (550:7): [True: 0, False: 709k]
  ------------------
  551|      0|			continue;
  552|   709k|		blk = blocks[0];
  553|   709k|		free(blocks);
  554|       |
  555|   709k|		if (blk == NULL)
  ------------------
  |  Branch (555:7): [True: 709k, False: 0]
  ------------------
  556|   709k|			continue;
  557|       |
  558|       |		/* no options at the moment */
  559|   709k|	}
  560|   709k|	return SC_SUCCESS;
  ------------------
  |  |   28|   709k|#define SC_SUCCESS				0
  ------------------
  561|   709k|}

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

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

sc_enum_apps:
  163|  12.7k|{
  164|  12.7k|	struct sc_context *ctx = card->ctx;
  165|  12.7k|	sc_path_t path;
  166|  12.7k|	int ef_structure;
  167|  12.7k|	size_t file_size, jj;
  168|  12.7k|	int r, ii, idx;
  169|  12.7k|	struct sc_file *ef_dir = NULL;
  170|       |
  171|  12.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  172|       |
  173|  12.7k|	sc_free_apps(card);
  174|  12.7k|	card->app_count = 0;
  175|       |
  176|  12.7k|	sc_format_path("3F002F00", &path);
  177|  12.7k|	r = sc_select_file(card, &path, &ef_dir);
  178|  12.7k|	if (r < 0)
  ------------------
  |  Branch (178:6): [True: 9.50k, False: 3.24k]
  ------------------
  179|  9.50k|		sc_file_free(ef_dir);
  180|  12.7k|	LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file");
  ------------------
  |  |  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: 9.50k, False: 3.24k]
  |  |  |  |  ------------------
  |  |  |  |  169|  9.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  9.50k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  9.50k|		return _ret; \
  |  |  |  |  172|  9.50k|	} \
  |  |  |  |  173|  12.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.24k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|       |
  182|  3.24k|	if (ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
  ------------------
  |  |  216|  3.24k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (182:6): [True: 1.03k, False: 2.20k]
  ------------------
  183|  1.03k|		sc_file_free(ef_dir);
  184|  1.03k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_CARD, "EF(DIR) is not a working EF.");
  ------------------
  |  |  174|  1.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.03k|	int _ret = (r); \
  |  |  |  |  168|  1.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.03k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.03k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.03k|		return _ret; \
  |  |  |  |  172|  1.03k|	} \
  |  |  |  |  173|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  185|  1.03k|	}
  186|       |
  187|  2.20k|	ef_structure = ef_dir->ef_structure;
  188|  2.20k|	file_size = ef_dir->size;
  189|  2.20k|	sc_file_free(ef_dir);
  190|  2.20k|	if (ef_structure == SC_FILE_EF_TRANSPARENT) {
  ------------------
  |  |  221|  2.20k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (190:6): [True: 1.13k, False: 1.07k]
  ------------------
  191|  1.13k|		u8 *buf = NULL, *p;
  192|  1.13k|		size_t bufsize;
  193|       |
  194|  1.13k|		if (file_size == 0)
  ------------------
  |  Branch (194:7): [True: 34, False: 1.09k]
  ------------------
  195|  1.13k|			LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  1.09k|		if (file_size > MAX_FILE_SIZE)
  ------------------
  |  |  220|  1.09k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (196:7): [True: 17, False: 1.08k]
  ------------------
  197|  1.09k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|  1.08k|		buf = malloc(file_size);
  200|  1.08k|		if (buf == NULL)
  ------------------
  |  Branch (200:7): [True: 0, False: 1.08k]
  ------------------
  201|  1.08k|			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|  1.08k|		p = buf;
  203|  1.08k|		r = sc_read_binary(card, 0, buf, file_size, 0);
  204|  1.08k|		if (r < 0) {
  ------------------
  |  Branch (204:7): [True: 178, False: 902]
  ------------------
  205|    178|			free(buf);
  206|    178|			LOG_TEST_RET(ctx, r, "sc_read_binary() failed");
  ------------------
  |  |  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: 178, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    178|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|    178|		}
  208|    902|		bufsize = r;
  209|  2.47k|		while (bufsize > 0) {
  ------------------
  |  Branch (209:10): [True: 2.01k, False: 453]
  ------------------
  210|  2.01k|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|  2.01k|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (210:8): [True: 2, False: 2.01k]
  ------------------
  211|      2|				sc_log(ctx, "Too many applications on card");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  212|      2|				break;
  213|      2|			}
  214|  2.01k|			r = parse_dir_record(card, &p, &bufsize, -1);
  215|  2.01k|			if (r)
  ------------------
  |  Branch (215:8): [True: 447, False: 1.56k]
  ------------------
  216|    447|				break;
  217|  2.01k|		}
  218|    902|		if (buf)
  ------------------
  |  Branch (218:7): [True: 902, False: 0]
  ------------------
  219|    902|			free(buf);
  220|       |
  221|    902|	}
  222|  1.07k|	else {	/* record structure */
  223|  1.07k|		unsigned char buf[256], *p;
  224|  1.07k|		unsigned int rec_nr;
  225|  1.07k|		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|  4.29k|		for (rec_nr = 1; rec_nr < 16; rec_nr++) {
  ------------------
  |  Branch (229:20): [True: 4.28k, False: 11]
  ------------------
  230|  4.28k|			r = sc_read_record(card, rec_nr, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  4.28k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  231|  4.28k|			if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  4.28k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (231:8): [True: 1, False: 4.28k]
  ------------------
  232|      1|				break;
  233|  4.28k|			LOG_TEST_RET(ctx, r, "read_record() failed");
  ------------------
  |  |  174|  4.28k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.28k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.28k|	int _ret = (r); \
  |  |  |  |  168|  4.28k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.05k, False: 3.23k]
  |  |  |  |  ------------------
  |  |  |  |  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|  4.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|       |
  235|  3.23k|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|  3.23k|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (235:8): [True: 13, False: 3.22k]
  ------------------
  236|     13|				sc_log(ctx, "Too many applications on card");
  ------------------
  |  |   71|     13|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  237|     13|				break;
  238|     13|			}
  239|       |
  240|  3.22k|			rec_size = r;
  241|  3.22k|			p = buf;
  242|  3.22k|			parse_dir_record(card, &p, &rec_size, (int)rec_nr);
  243|  3.22k|		}
  244|  1.07k|	}
  245|       |
  246|       |	/* Move known PKCS#15 applications to the head of the list */
  247|  2.62k|	for (ii=0, idx=0; ii<card->app_count; ii++)   {
  ------------------
  |  Branch (247:20): [True: 1.69k, False: 927]
  ------------------
  248|  14.3k|		for (jj=0; jj < sizeof(apps)/sizeof(apps[0]); jj++) {
  ------------------
  |  Branch (248:14): [True: 12.8k, False: 1.51k]
  ------------------
  249|  12.8k|			if (apps[jj].aid_len != card->app[ii]->aid.len)
  ------------------
  |  Branch (249:8): [True: 12.5k, False: 313]
  ------------------
  250|  12.5k|				continue;
  251|    313|			if (memcmp(apps[jj].aid, card->app[ii]->aid.value, apps[jj].aid_len))
  ------------------
  |  Branch (251:8): [True: 127, False: 186]
  ------------------
  252|    127|				continue;
  253|    186|			break;
  254|    313|		}
  255|       |
  256|  1.69k|		if (ii != idx && jj < sizeof(apps)/sizeof(apps[0]))   {
  ------------------
  |  Branch (256:7): [True: 1.04k, False: 656]
  |  Branch (256:20): [True: 167, False: 876]
  ------------------
  257|    167|			struct sc_app_info *tmp = card->app[idx];
  258|       |
  259|    167|			card->app[idx] = card->app[ii];
  260|    167|			card->app[ii] = tmp;
  261|    167|			idx++;
  262|    167|		}
  263|  1.69k|	}
  264|       |
  265|    927|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    927|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    927|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    927|	int _ret = r; \
  |  |  |  |  155|    927|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 927, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    927|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 927]
  |  |  |  |  ------------------
  |  |  |  |  157|    927|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    927|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    927|	return _ret; \
  |  |  |  |  163|    927|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|    927|}
sc_free_apps:
  269|  28.5k|{
  270|  28.5k|	int	i;
  271|       |
  272|  32.3k|	for (i = 0; i < card->app_count; i++) {
  ------------------
  |  Branch (272:14): [True: 3.81k, False: 28.5k]
  ------------------
  273|  3.81k|		free(card->app[i]->label);
  274|  3.81k|		free(card->app[i]->ddo.value);
  275|  3.81k|		free(card->app[i]);
  276|  3.81k|	}
  277|  28.5k|	card->app_count = -1;
  278|  28.5k|}
dir.c:parse_dir_record:
   65|  5.23k|{
   66|  5.23k|	struct sc_context *ctx = card->ctx;
   67|  5.23k|	struct sc_asn1_entry asn1_dirrecord[5], asn1_dir[2];
   68|  5.23k|	scconf_block *conf_block = NULL;
   69|  5.23k|	sc_app_info_t *app = NULL;
   70|  5.23k|	struct sc_aid aid;
   71|  5.23k|	u8 label[128], path[128], ddo[128];
   72|  5.23k|	size_t label_len = sizeof(label) - 1, path_len = sizeof(path), ddo_len = sizeof(ddo);
   73|  5.23k|	int r;
   74|       |
   75|  5.23k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.23k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.23k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.23k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.23k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   76|  5.23k|	aid.len = sizeof(aid.value);
   77|       |
   78|  5.23k|	memset(label, 0, sizeof(label));
   79|  5.23k|	sc_copy_asn1_entry(c_asn1_dirrecord, asn1_dirrecord);
   80|  5.23k|	sc_copy_asn1_entry(c_asn1_dir, asn1_dir);
   81|  5.23k|	sc_format_asn1_entry(asn1_dir + 0, asn1_dirrecord, NULL, 0);
   82|  5.23k|	sc_format_asn1_entry(asn1_dirrecord + 0, aid.value, &aid.len, 0);
   83|  5.23k|	sc_format_asn1_entry(asn1_dirrecord + 1, label, &label_len, 0);
   84|  5.23k|	sc_format_asn1_entry(asn1_dirrecord + 2, path, &path_len, 0);
   85|  5.23k|	sc_format_asn1_entry(asn1_dirrecord + 3, ddo, &ddo_len, 0);
   86|       |
   87|  5.23k|	r = sc_asn1_decode(ctx, asn1_dir, *buf, *buflen, (const u8 **) buf, buflen);
   88|  5.23k|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  5.23k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (88:6): [True: 225, False: 5.01k]
  ------------------
   89|  5.23k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    225|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    225|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    225|	int _ret = r; \
  |  |  |  |  155|    225|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 225, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    225|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    225|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 225, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    225|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    225|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    225|	return _ret; \
  |  |  |  |  163|    225|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|  5.01k|	LOG_TEST_RET(ctx, r, "EF(DIR) parsing failed");
  ------------------
  |  |  174|  5.01k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.01k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.01k|	int _ret = (r); \
  |  |  |  |  168|  5.01k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.19k, False: 3.81k]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.19k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.19k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.19k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.19k|		return _ret; \
  |  |  |  |  172|  1.19k|	} \
  |  |  |  |  173|  5.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.81k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|       |
   92|  3.81k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
   93|  3.81k|	if (conf_block)   {
  ------------------
  |  Branch (93:6): [True: 0, False: 3.81k]
  ------------------
   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|  3.81k|	app = calloc(1, sizeof(struct sc_app_info));
  112|  3.81k|	if (app == NULL)
  ------------------
  |  Branch (112:6): [True: 0, False: 3.81k]
  ------------------
  113|  3.81k|		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|  3.81k|	memcpy(&app->aid, &aid, sizeof(struct sc_aid));
  116|       |
  117|  3.81k|	if (asn1_dirrecord[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|  3.81k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (117:6): [True: 88, False: 3.72k]
  ------------------
  118|     88|		app->label = strdup((char *) label);
  119|  3.72k|	else
  120|  3.72k|		app->label = NULL;
  121|       |
  122|  3.81k|	if (asn1_dirrecord[2].flags & SC_ASN1_PRESENT && path_len > 0) {
  ------------------
  |  |  147|  7.63k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (122:6): [True: 521, False: 3.29k]
  |  Branch (122:51): [True: 476, False: 45]
  ------------------
  123|       |		/* application path present: ignore AID */
  124|    476|		if (path_len > SC_MAX_PATH_SIZE) {
  ------------------
  |  |   47|    476|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (124:7): [True: 1, False: 475]
  ------------------
  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|    475|		memcpy(app->path.value, path, path_len);
  130|    475|		app->path.len = path_len;
  131|    475|		app->path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    475|#define SC_PATH_TYPE_PATH		2
  ------------------
  132|    475|	}
  133|  3.33k|	else {
  134|       |		/* application path not present: use AID as application path */
  135|  3.33k|		memcpy(app->path.value, aid.value, aid.len);
  136|  3.33k|		app->path.len = aid.len;
  137|  3.33k|		app->path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.33k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  138|  3.33k|	}
  139|       |
  140|  3.81k|	if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|  3.81k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (140:6): [True: 384, False: 3.43k]
  ------------------
  141|    384|		app->ddo.value = malloc(ddo_len);
  142|    384|		if (app->ddo.value == NULL) {
  ------------------
  |  Branch (142:7): [True: 0, False: 384]
  ------------------
  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|    384|		memcpy(app->ddo.value, ddo, ddo_len);
  148|    384|		app->ddo.len = ddo_len;
  149|  3.43k|	} else {
  150|  3.43k|		app->ddo.value = NULL;
  151|  3.43k|		app->ddo.len = 0;
  152|  3.43k|	}
  153|       |
  154|  3.81k|	app->rec_nr = rec_nr;
  155|  3.81k|	card->app[card->app_count] = app;
  156|  3.81k|	card->app_count++;
  157|       |
  158|  3.81k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.81k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.81k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.81k|	int _ret = r; \
  |  |  |  |  155|  3.81k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.81k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.81k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.81k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.81k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.81k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.81k|	return _ret; \
  |  |  |  |  163|  3.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|  3.81k|}

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

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

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

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

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

iasecc_sm_initialize:
  270|    139|{
  271|    139|	struct sc_context *ctx = card->ctx;
  272|    139|#ifdef ENABLE_SM
  273|    139|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    139|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    139|	struct sc_remote_data rdata;
  276|    139|	int rv;
  277|       |
  278|    139|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    139|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    139|#define strlcpy _strlcpy
  ------------------
  281|    139|	sm_info->cmd = cmd;
  282|    139|	sm_info->serialnr = card->serialnr;
  283|    139|	sm_info->card_type = card->type;
  284|    139|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    139|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    139|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    139|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() MUTUAL AUTHENTICATION failed");
  ------------------
  |  |  174|    139|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    139|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    139|	int _ret = (r); \
  |  |  |  |  168|    139|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 139, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    139|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    139|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    139|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    139|		return _ret; \
  |  |  |  |  172|    139|	} \
  |  |  |  |  173|    139|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    139|{
  587|    139|	struct sc_context *ctx = card->ctx;
  588|    139|#ifdef ENABLE_SM
  589|    139|	struct sm_info *sm_info = &card->sm_ctx.info;
  590|    139|	struct sc_remote_data rdata;
  591|    139|	struct iasecc_sm_cmd_update_binary cmd_data;
  592|    139|	int rv;
  593|       |
  594|    139|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  595|    139|	sc_log(ctx, "SM read binary: acl:%X, offs:%zu, count:%zu", se_num, offs, count);
  ------------------
  |  |   71|    139|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  596|       |
  597|    139|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    139|#define SM_CMD_FILE_READ		0x201
  ------------------
  598|    139|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM INITIALIZE failed");
  ------------------
  |  |  174|    139|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    139|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    139|	int _ret = (r); \
  |  |  |  |  168|    139|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 139, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    139|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    139|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    139|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    139|		return _ret; \
  |  |  |  |  172|    139|	} \
  |  |  |  |  173|    139|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    139|{
  223|    139|	struct sc_context *ctx = card->ctx;
  224|    139|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    139|	struct iasecc_se_info se;
  226|    139|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    139|	struct sc_apdu apdu;
  228|    139|	unsigned char sbuf[0x100];
  229|    139|	int rv, offs;
  230|       |
  231|    139|	memset(&se, 0, sizeof(se));
  232|       |
  233|    139|	se.reference = se_num;
  234|    139|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    139|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    139|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    139|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    139|	rv = iasecc_se_get_info(card, &se);
  238|    139|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  174|    139|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    139|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    139|	int _ret = (r); \
  |  |  |  |  168|    139|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 130, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|    130|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    130|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    130|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    130|		return _ret; \
  |  |  |  |  172|    130|	} \
  |  |  |  |  173|    139|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|       |
  240|      9|	rv = iasecc_se_get_crt(card, &se, crt);
  241|      9|	sc_file_free(se.df);
  242|      9|	LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  37.3k|{
   37|  37.3k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (37:6): [True: 0, False: 37.3k]
  |  Branch (37:22): [True: 0, False: 37.3k]
  ------------------
   38|      0|		return;
   39|      0|	}
   40|       |
   41|  37.3k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (41:6): [True: 874, False: 36.4k]
  ------------------
   42|       |		/* The lower layers will automatically do chaining */
   43|    874|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    874|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   44|    874|	}
   45|       |
   46|  37.3k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (46:6): [True: 3.98k, False: 33.3k]
  ------------------
   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|  3.98k|		apdu->le = sc_get_max_recv_size(card);
   50|  3.98k|	}
   51|  37.3k|}
encode_do_data:
  177|  7.21k|{
  178|  7.21k|	unsigned char offset_buffer[2];
  179|  7.21k|	size_t offset_buffer_len = sizeof offset_buffer;
  180|  7.21k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  181|  7.21k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  182|       |
  183|  7.21k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (183:6): [True: 0, False: 7.21k]
  ------------------
  184|  7.21k|		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.21k|	offset_buffer[0] = (u8) (idx >> 8);
  186|  7.21k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  187|  7.21k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  188|       |
  189|  7.21k|	if (data && data_len) {
  ------------------
  |  Branch (189:6): [True: 0, False: 7.21k]
  |  Branch (189:14): [True: 0, False: 0]
  ------------------
  190|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  191|  7.21k|	} else {
  192|  7.21k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  193|  7.21k|	}
  194|       |
  195|  7.21k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  7.21k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.21k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.21k|	int _ret = (r); \
  |  |  |  |  168|  7.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7.21k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  7.21k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  197|  7.21k|			"sc_asn1_encode() failed");
  198|       |
  199|  7.21k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.21k|#define SC_SUCCESS				0
  ------------------
  200|  7.21k|}
decode_do_data:
  205|  4.99k|{
  206|  4.99k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  207|  4.99k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  208|       |
  209|  4.99k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  210|  4.99k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  211|       |
  212|  4.99k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  4.99k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.99k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.99k|	int _ret = (r); \
  |  |  |  |  168|  4.99k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 102, False: 4.88k]
  |  |  |  |  ------------------
  |  |  |  |  169|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    102|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    102|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    102|		return _ret; \
  |  |  |  |  172|    102|	} \
  |  |  |  |  173|  4.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.88k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|  4.88k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  214|  4.88k|			"sc_asn1_decode() failed");
  215|       |
  216|  4.88k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  4.88k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (216:6): [True: 2.61k, False: 2.27k]
  ------------------
  217|  2.61k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  2.61k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  218|       |
  219|  2.27k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.27k|#define SC_SUCCESS				0
  ------------------
  220|  4.88k|}
iso7816_build_pin_apdu:
 1183|  1.96k|{
 1184|  1.96k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1185|  1.96k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  1.96k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1186|       |
 1187|  1.96k|	switch (data->pin_type) {
 1188|  1.94k|	case SC_AC_CHV:
  ------------------
  |  |  151|  1.94k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1188:2): [True: 1.94k, False: 26]
  ------------------
 1189|       |		/* fall through */
 1190|  1.94k|	case SC_AC_SESSION:
  ------------------
  |  |  159|  1.94k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1190:2): [True: 0, False: 1.96k]
  ------------------
 1191|  1.96k|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|  1.96k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1191:2): [True: 26, False: 1.94k]
  ------------------
 1192|  1.96k|		break;
 1193|      0|	default:
  ------------------
  |  Branch (1193:2): [True: 0, False: 1.96k]
  ------------------
 1194|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1195|  1.96k|	}
 1196|       |
 1197|  1.96k|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  422|  1.96k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1197:6): [True: 394, False: 1.57k]
  ------------------
 1198|    394|		pad = 1;
 1199|  1.96k|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  421|  1.96k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1199:6): [True: 0, False: 1.96k]
  ------------------
 1200|      0|		use_pin_pad = 1;
 1201|       |
 1202|  1.96k|	data->pin1.offset = 5;
 1203|       |
 1204|  1.96k|	switch (data->cmd) {
 1205|    294|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|    294|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1205:2): [True: 294, False: 1.67k]
  ------------------
 1206|    294|		ins = 0x20;
 1207|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1208|    294|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1208:7): [True: 0, False: 294]
  |  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|    294|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1210:7): [True: 14, False: 280]
  ------------------
 1211|     14|			return r;
 1212|    280|		len = r;
 1213|    280|		break;
 1214|     59|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     59|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1214:2): [True: 59, False: 1.90k]
  ------------------
 1215|     59|		ins = 0x24;
 1216|     59|		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: 56, False: 3]
  |  Branch (1216:31): [True: 0, False: 3]
  |  Branch (1216:46): [True: 0, False: 0]
  ------------------
 1217|     56|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1217:8): [True: 6, False: 50]
  ------------------
 1218|      6|				return r;
 1219|     50|			len += r;
 1220|     50|		}
 1221|      3|		else {
 1222|       |			/* implicit test */
 1223|      3|			p1 = 1;
 1224|      3|		}
 1225|       |
 1226|     53|		data->pin2.offset = data->pin1.offset + len;
 1227|     53|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1227:7): [True: 0, False: 53]
  ------------------
 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|     53|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1232:7): [True: 50, False: 3]
  |  Branch (1232:25): [True: 0, False: 50]
  ------------------
 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|     53|		len += r;
 1237|     53|		break;
 1238|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1238:2): [True: 0, False: 1.96k]
  ------------------
 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|  1.61k|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|  1.61k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1261:2): [True: 1.61k, False: 353]
  ------------------
 1262|  1.61k|		ins = 0x20;
 1263|       |		/* No data to send or to receive */
 1264|  1.61k|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|  1.61k|#define SC_APDU_CASE_1			0x01
  ------------------
 1265|  1.61k|		break;
 1266|      0|	default:
  ------------------
  |  Branch (1266:2): [True: 0, False: 1.96k]
  ------------------
 1267|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1268|  1.96k|	}
 1269|       |
 1270|  1.94k|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1271|  1.94k|	apdu->lc = len;
 1272|  1.94k|	apdu->datalen = len;
 1273|  1.94k|	apdu->data = buf;
 1274|  1.94k|	apdu->resplen = 0;
 1275|       |
 1276|  1.94k|	return 0;
 1277|  1.96k|}
iso7816_select_aid:
 1395|  14.7k|{
 1396|  14.7k|	struct sc_context *ctx = card->ctx;
 1397|  14.7k|	struct sc_apdu apdu;
 1398|  14.7k|	int rv;
 1399|       |
 1400|  14.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  14.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  14.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  14.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 14.7k]
  |  |  ------------------
  ------------------
 1401|       |
 1402|  14.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|  7.01k|#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|  7.70k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1402:30): [True: 7.01k, False: 7.70k]
  |  Branch (1402:102): [True: 7.01k, False: 7.70k]
  ------------------
 1403|  14.7k|	apdu.lc = reqlen;
 1404|  14.7k|	apdu.data = req;
 1405|  14.7k|	apdu.datalen = reqlen;
 1406|  14.7k|	apdu.resp = resp;
 1407|  14.7k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1407:17): [True: 7.01k, False: 7.70k]
  ------------------
 1408|  14.7k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1408:12): [True: 7.01k, False: 7.70k]
  ------------------
 1409|       |
 1410|  14.7k|	rv = sc_transmit_apdu(card, &apdu);
 1411|  14.7k|	if (resplen)
  ------------------
  |  Branch (1411:6): [True: 7.70k, False: 7.01k]
  ------------------
 1412|  7.70k|		*resplen = apdu.resplen;
 1413|  14.7k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  14.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  14.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  14.7k|	int _ret = (r); \
  |  |  |  |  168|  14.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 134, False: 14.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    134|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    134|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    134|		return _ret; \
  |  |  |  |  172|    134|	} \
  |  |  |  |  173|  14.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1414|       |
 1415|  14.5k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1416|  14.5k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  14.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  14.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  14.5k|	int _ret = r; \
  |  |  |  |  155|  14.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  14.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.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10.0k, False: 4.53k]
  |  |  |  |  ------------------
  |  |  |  |  157|  14.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.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|  14.5k|	return _ret; \
  |  |  |  |  163|  14.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1417|  14.5k|}
sc_get_iso7816_driver:
 1485|   544k|{
 1486|   544k|	return &iso_driver;
 1487|   544k|}
iso7816.c:no_match:
 1431|  8.02k|{
 1432|  8.02k|	return 0;
 1433|  8.02k|}
iso7816.c:iso7816_read_record:
  225|  14.2k|{
  226|  14.2k|	struct sc_apdu apdu;
  227|  14.2k|	int r;
  228|       |	/* XXX maybe use some bigger buffer */
  229|  14.2k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  230|  14.2k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  231|  14.2k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  232|       |
  233|  14.2k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (233:6): [True: 1, False: 14.2k]
  ------------------
  234|  14.2k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  14.2k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 7.02k, False: 7.21k]
  ------------------
  237|  7.02k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  7.02k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  7.02k|		apdu.le = count;
  239|  7.02k|		apdu.resplen = count;
  240|  7.02k|		apdu.resp = buf;
  241|  7.21k|	} else {
  242|  7.21k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  7.21k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  7.21k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  7.21k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  7.21k|	int _ret = (r); \
  |  |  |  |  178|  7.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 7.21k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 7.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  7.21k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  7.21k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  7.21k|		apdu.lc = encoded_data_len;
  247|  7.21k|		apdu.datalen = encoded_data_len;
  248|  7.21k|		apdu.data = encoded_data;
  249|  7.21k|		apdu.le = sizeof resp;
  250|  7.21k|		apdu.resplen = sizeof resp;
  251|  7.21k|		apdu.resp = resp;
  252|  7.21k|	}
  253|  14.2k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  14.2k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  14.2k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  14.2k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 14.2k, False: 0]
  ------------------
  255|  14.2k|		apdu.p2 |= 0x04;
  256|       |
  257|  14.2k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  14.2k|	r = sc_transmit_apdu(card, &apdu);
  259|  14.2k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  14.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  14.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  14.2k|	int _ret = (r); \
  |  |  |  |  178|  14.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 640, False: 13.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|    640|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    640|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    640|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    640|		goto err; \
  |  |  |  |  182|    640|	} \
  |  |  |  |  183|  14.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 13.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  13.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  13.6k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  13.6k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.6k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.6k|	int _ret = (r); \
  |  |  |  |  178|  13.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2.71k, False: 10.8k]
  |  |  |  |  ------------------
  |  |  |  |  179|  2.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.71k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  2.71k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  2.71k|		goto err; \
  |  |  |  |  182|  2.71k|	} \
  |  |  |  |  183|  13.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 10.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  10.8k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 5.89k, False: 4.99k]
  ------------------
  264|  5.89k|		r = (int)apdu.resplen;
  265|  5.89k|	} else {
  266|  4.99k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  4.99k|				&decoded_data, &decoded_data_len);
  268|  4.99k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  4.99k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.99k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.99k|	int _ret = (r); \
  |  |  |  |  178|  4.99k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2.71k, False: 2.27k]
  |  |  |  |  ------------------
  |  |  |  |  179|  2.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.71k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  2.71k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  2.71k|		goto err; \
  |  |  |  |  182|  2.71k|	} \
  |  |  |  |  183|  4.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  2.27k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 1.93k, False: 340]
  ------------------
  270|  1.93k|			count = decoded_data_len;
  271|  1.93k|		}
  272|  2.27k|		memcpy(buf, decoded_data, count);
  273|  2.27k|		r = (int)count;
  274|  2.27k|	}
  275|       |
  276|  14.2k|err:
  277|  14.2k|	free(encoded_data);
  278|  14.2k|	free(decoded_data);
  279|  14.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  14.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  14.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  14.2k|	int _ret = r; \
  |  |  |  |  155|  14.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.38k, False: 7.86k]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.38k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.07k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.07k, False: 305]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.38k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.86k|	} else { \
  |  |  |  |  159|  7.86k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  7.86k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  7.86k|	} \
  |  |  |  |  162|  14.2k|	return _ret; \
  |  |  |  |  163|  14.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  14.2k|}
iso7816.c:iso7816_select_file:
  629|  49.8k|{
  630|  49.8k|	struct sc_context *ctx;
  631|  49.8k|	struct sc_apdu apdu;
  632|  49.8k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  633|  49.8k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  634|  49.8k|	int r, pathtype;
  635|  49.8k|	size_t pathlen;
  636|  49.8k|	int select_mf = 0;
  637|  49.8k|	struct sc_file *file = NULL;
  638|  49.8k|	const u8 *buffer;
  639|  49.8k|	size_t buffer_len;
  640|  49.8k|	unsigned int cla, tag;
  641|       |
  642|  49.8k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 49.8k]
  |  Branch (642:22): [True: 0, False: 49.8k]
  ------------------
  643|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  644|      0|	}
  645|  49.8k|	ctx = card->ctx;
  646|  49.8k|	memcpy(path, in_path->value, in_path->len);
  647|  49.8k|	pathlen = in_path->len;
  648|  49.8k|	pathtype = in_path->type;
  649|       |
  650|  49.8k|	if (in_path->aid.len) {
  ------------------
  |  Branch (650:6): [True: 2.42k, False: 47.4k]
  ------------------
  651|  2.42k|		if (!pathlen) {
  ------------------
  |  Branch (651:7): [True: 1.41k, False: 1.01k]
  ------------------
  652|  1.41k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  653|  1.41k|			pathlen = in_path->aid.len;
  654|  1.41k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.41k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  655|  1.41k|		} else {
  656|       |			/* First, select the application */
  657|  1.01k|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|  1.01k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  658|  1.01k|			apdu.data = in_path->aid.value;
  659|  1.01k|			apdu.datalen = in_path->aid.len;
  660|  1.01k|			apdu.lc = in_path->aid.len;
  661|       |
  662|  1.01k|			r = sc_transmit_apdu(card, &apdu);
  663|  1.01k|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.01k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.01k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.01k|	int _ret = (r); \
  |  |  |  |  168|  1.01k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 994]
  |  |  |  |  ------------------
  |  |  |  |  169|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     18|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     18|		return _ret; \
  |  |  |  |  172|     18|	} \
  |  |  |  |  173|  1.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 994]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  664|    994|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  665|    994|			if (r)
  ------------------
  |  Branch (665:8): [True: 679, False: 315]
  ------------------
  666|    994|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    679|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    679|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    679|	int _ret = r; \
  |  |  |  |  155|    679|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 679, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    679|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    679|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 679, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    679|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    679|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    679|	return _ret; \
  |  |  |  |  163|    679|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|       |
  668|    315|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    630|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (668:8): [True: 315, 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|    315|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|    315|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  671|    315|		}
  672|  2.42k|	}
  673|       |
  674|  49.1k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  49.1k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  675|       |
  676|  49.1k|	switch (pathtype) {
  677|  7.82k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  7.82k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (677:2): [True: 7.82k, False: 41.3k]
  ------------------
  678|  7.82k|		apdu.p1 = 0;
  679|  7.82k|		if (pathlen != 2)
  ------------------
  |  Branch (679:7): [True: 0, False: 7.82k]
  ------------------
  680|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  681|  7.82k|		break;
  682|  23.0k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  23.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (682:2): [True: 23.0k, False: 26.1k]
  ------------------
  683|  23.0k|		apdu.p1 = 4;
  684|  23.0k|		break;
  685|  17.9k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  17.9k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (685:2): [True: 17.9k, False: 31.2k]
  ------------------
  686|  17.9k|		apdu.p1 = 8;
  687|  17.9k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (687:7): [True: 17.8k, False: 27]
  |  Branch (687:23): [True: 13.0k, False: 4.80k]
  ------------------
  688|  13.0k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (688:8): [True: 3.41k, False: 9.67k]
  ------------------
  689|  3.41k|				select_mf = 1;
  690|  3.41k|				apdu.p1 = 0;
  691|  3.41k|				break;
  692|  3.41k|			}
  693|  9.67k|			path += 2;
  694|  9.67k|			pathlen -= 2;
  695|  9.67k|		}
  696|  14.5k|		break;
  697|  14.5k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    315|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (697:2): [True: 315, False: 48.8k]
  ------------------
  698|    315|		apdu.p1 = 9;
  699|    315|		break;
  700|     59|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|     59|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (700:2): [True: 59, False: 49.1k]
  ------------------
  701|     59|		apdu.p1 = 3;
  702|     59|		pathlen = 0;
  703|     59|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|     59|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  704|     59|		break;
  705|      0|	default:
  ------------------
  |  Branch (705:2): [True: 0, False: 49.1k]
  ------------------
  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|  49.1k|	}
  708|  49.1k|	apdu.lc = pathlen;
  709|  49.1k|	apdu.data = path;
  710|  49.1k|	apdu.datalen = pathlen;
  711|       |
  712|  49.1k|	if (file_out != NULL) {
  ------------------
  |  Branch (712:6): [True: 29.5k, False: 19.6k]
  ------------------
  713|  29.5k|		apdu.p2 = 0;		/* first record, return FCI */
  714|  29.5k|		apdu.resp = buf;
  715|  29.5k|		apdu.resplen = sizeof(buf);
  716|  29.5k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (716:13): [True: 1.06k, False: 28.4k]
  ------------------
  717|  29.5k|	}
  718|  19.6k|	else {
  719|  19.6k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  720|  19.6k|		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|  39.3k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (720:14): [True: 0, False: 19.6k]
  ------------------
  721|  19.6k|	}
  722|       |
  723|  49.1k|	r = sc_transmit_apdu(card, &apdu);
  724|  49.1k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  49.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  49.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  49.1k|	int _ret = (r); \
  |  |  |  |  168|  49.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 440, False: 48.7k]
  |  |  |  |  ------------------
  |  |  |  |  169|    440|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    440|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    440|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    440|		return _ret; \
  |  |  |  |  172|    440|	} \
  |  |  |  |  173|  49.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  725|  48.7k|	if (file_out == NULL) {
  ------------------
  |  Branch (725:6): [True: 19.6k, False: 29.1k]
  ------------------
  726|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  727|  19.6k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  728|  19.6k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (728:7): [True: 121, False: 19.5k]
  |  Branch (728:27): [True: 40, False: 81]
  ------------------
  729|     40|			apdu.p2 = 0x00;
  730|     40|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     40|#define SC_SUCCESS				0
  ------------------
  |  Branch (730:8): [True: 21, False: 19]
  ------------------
  731|     21|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  732|     40|		}
  733|  19.6k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (733:7): [True: 0, False: 19.6k]
  ------------------
  734|  19.6k|			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|  19.6k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  19.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  19.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  19.6k|	int _ret = r; \
  |  |  |  |  155|  19.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 19.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  19.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  13.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.6k, False: 5.99k]
  |  |  |  |  ------------------
  |  |  |  |  157|  19.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  19.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|  19.6k|	return _ret; \
  |  |  |  |  163|  19.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  736|  19.6k|	}
  737|       |
  738|  29.1k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  739|  29.1k|	if (r)
  ------------------
  |  Branch (739:6): [True: 17.0k, False: 12.0k]
  ------------------
  740|  29.1k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  17.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.0k|	int _ret = r; \
  |  |  |  |  155|  17.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  17.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  17.0k|	return _ret; \
  |  |  |  |  163|  17.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  741|       |
  742|  12.0k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (742:6): [True: 12.0k, False: 0]
  |  Branch (742:18): [True: 2.07k, False: 9.93k]
  ------------------
  743|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  744|  2.07k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.76k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (744:7): [True: 304, False: 1.76k]
  |  Branch (744:20): [True: 1.39k, False: 376]
  ------------------
  745|  1.69k|			file = sc_file_new();
  746|  1.69k|			if (file == NULL)
  ------------------
  |  Branch (746:8): [True: 0, False: 1.69k]
  ------------------
  747|  1.69k|				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|  1.69k|			file->path = *in_path;
  749|       |
  750|  1.69k|			*file_out = file;
  751|  1.69k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.69k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.69k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.69k|	int _ret = r; \
  |  |  |  |  155|  1.69k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.69k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.69k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.69k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.69k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.69k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.69k|	return _ret; \
  |  |  |  |  163|  1.69k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|  1.69k|		}
  753|  2.07k|	}
  754|       |
  755|  10.3k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (755:6): [True: 680, False: 9.63k]
  ------------------
  756|  10.3k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    680|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  757|  9.63k|	switch (apdu.resp[0]) {
  758|  7.88k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  7.88k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (758:2): [True: 7.88k, False: 1.75k]
  ------------------
  759|  9.37k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  9.37k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (759:2): [True: 1.48k, False: 8.14k]
  ------------------
  760|  9.37k|		file = sc_file_new();
  761|  9.37k|		if (file == NULL)
  ------------------
  |  Branch (761:7): [True: 0, False: 9.37k]
  ------------------
  762|  9.37k|			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|  9.37k|		file->path = *in_path;
  764|  9.37k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (764:7): [True: 0, False: 9.37k]
  ------------------
  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|  9.37k|		buffer = apdu.resp;
  769|  9.37k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  770|  9.37k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  9.37k|#define SC_SUCCESS				0
  ------------------
  |  Branch (770:7): [True: 8.35k, False: 1.02k]
  ------------------
  771|  8.35k|			card->ops->process_fci(card, file, buffer, buffer_len);
  772|  9.37k|		*file_out = file;
  773|  9.37k|		break;
  774|     64|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (774:2): [True: 64, False: 9.57k]
  ------------------
  775|     64|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     64|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     64|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     64|	int _ret = r; \
  |  |  |  |  155|     64|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     64|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     64|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     64|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|    198|	default:
  ------------------
  |  Branch (776:2): [True: 198, False: 9.43k]
  ------------------
  777|    198|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    198|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    198|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    198|	int _ret = r; \
  |  |  |  |  155|    198|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 198, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    198|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    198|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 198, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    198|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    198|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    198|	return _ret; \
  |  |  |  |  163|    198|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|  9.63k|	}
  779|       |
  780|  9.37k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.37k|#define SC_SUCCESS				0
  ------------------
  781|  9.63k|}
iso7816.c:iso7816_get_response:
  904|   100k|{
  905|   100k|	struct sc_apdu apdu = {0};
  906|   100k|	int r;
  907|   100k|	size_t rlen;
  908|       |
  909|       |	/* request at most max_recv_size bytes */
  910|   100k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (910:6): [True: 1.12k, False: 98.8k]
  ------------------
  911|  1.12k|		rlen = sc_get_max_recv_size(card);
  912|  98.8k|	else
  913|  98.8k|		rlen = *count;
  914|       |
  915|   100k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|   100k|#define SC_APDU_CASE_2			0x22
  ------------------
  916|   100k|	apdu.le      = rlen;
  917|   100k|	apdu.resplen = rlen;
  918|   100k|	apdu.resp    = buf;
  919|       |	/* don't call GET RESPONSE recursively */
  920|   100k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|   100k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  921|       |
  922|   100k|	r = sc_transmit_apdu(card, &apdu);
  923|   100k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|   100k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   100k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   100k|	int _ret = (r); \
  |  |  |  |  168|   100k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 429, False: 99.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|    429|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    429|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    429|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    429|		return _ret; \
  |  |  |  |  172|    429|	} \
  |  |  |  |  173|   100k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 99.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  924|       |
  925|  99.5k|	*count = apdu.resplen;
  926|       |
  927|  99.5k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (927:6): [True: 4.36k, False: 95.2k]
  ------------------
  928|  4.36k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  4.36k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.36k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.36k|	int _ret = r; \
  |  |  |  |  155|  4.36k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.36k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.36k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.18k, False: 2.17k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.36k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.36k|	return _ret; \
  |  |  |  |  163|  4.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  929|  4.36k|	}
  930|  95.2k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (930:6): [True: 25.4k, False: 69.7k]
  |  Branch (930:26): [True: 25.0k, False: 389]
  ------------------
  931|  25.0k|		r = 0;					/* no more data to read */
  932|  70.1k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (932:11): [True: 66.2k, False: 3.89k]
  ------------------
  933|  66.2k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (933:7): [True: 1.82k, False: 64.4k]
  ------------------
  934|  3.89k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (934:11): [True: 680, False: 3.21k]
  |  Branch (934:31): [True: 610, False: 70]
  ------------------
  935|    610|		r = 0; /* Le not reached but file/record ended */
  936|  3.28k|	else
  937|  3.28k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  938|       |
  939|  95.2k|	return r;
  940|  99.5k|}
iso7816.c:iso7816_get_challenge:
  786|  3.48k|{
  787|  3.48k|	int r;
  788|  3.48k|	struct sc_apdu apdu;
  789|       |
  790|  3.48k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x84, 0x00, 0x00);
  ------------------
  |  |  301|  3.48k|#define SC_APDU_CASE_2			0x22
  ------------------
  791|  3.48k|	apdu.le = len;
  792|  3.48k|	apdu.resp = rnd;
  793|  3.48k|	apdu.resplen = len;
  794|       |
  795|  3.48k|	r = sc_transmit_apdu(card, &apdu);
  796|  3.48k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  3.48k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.48k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.48k|	int _ret = (r); \
  |  |  |  |  168|  3.48k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 3.47k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  797|       |
  798|  3.47k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  799|  3.47k|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE failed");
  ------------------
  |  |  174|  3.47k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.47k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.47k|	int _ret = (r); \
  |  |  |  |  168|  3.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 981, False: 2.49k]
  |  |  |  |  ------------------
  |  |  |  |  169|    981|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    981|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    981|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    981|		return _ret; \
  |  |  |  |  172|    981|	} \
  |  |  |  |  173|  3.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  800|       |
  801|  2.49k|	if (len < apdu.resplen) {
  ------------------
  |  Branch (801:6): [True: 0, False: 2.49k]
  ------------------
  802|      0|		return (int) len;
  803|      0|	}
  804|       |
  805|  2.49k|	return (int) apdu.resplen;
  806|  2.49k|}
iso7816.c:iso7816_restore_security_env:
 1076|      3|{
 1077|      3|	struct sc_apdu apdu;
 1078|      3|	int r;
 1079|       |
 1080|      3|	if (card == NULL) {
  ------------------
  |  Branch (1080:6): [True: 0, False: 3]
  ------------------
 1081|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1082|      0|	}
 1083|       |
 1084|      3|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
  ------------------
  |  |  291|      3|#define SC_APDU_CASE_1			0x01
  ------------------
 1085|       |
 1086|      3|	r = sc_transmit_apdu(card, &apdu);
 1087|      3|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      3|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      3|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      3|	int _ret = (r); \
  |  |  |  |  168|      3|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1088|      2|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1089|      2|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1090|       |
 1091|      1|	return r;
 1092|      2|}
iso7816.c:iso7816_set_security_env:
  981|     72|{
  982|     72|	struct sc_apdu apdu;
  983|     72|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  984|     72|	u8 *p;
  985|     72|	int r, locked = 0;
  986|       |
  987|     72|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (987:6): [True: 0, False: 72]
  |  Branch (987:22): [True: 0, False: 72]
  ------------------
  988|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  989|      0|	}
  990|     72|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|     72|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  991|     72|	switch (env->operation) {
  992|      0|	case SC_SEC_OPERATION_AUTHENTICATE:
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (992:2): [True: 0, False: 72]
  ------------------
  993|      0|		apdu.p2 = 0xA4;
  994|      0|		break;
  995|     26|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     26|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (995:2): [True: 26, False: 46]
  ------------------
  996|     26|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|     26|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (996:2): [True: 0, False: 72]
  ------------------
  997|     26|		apdu.p2 = 0xB8;
  998|     26|		break;
  999|     46|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     46|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (999:2): [True: 46, False: 26]
  ------------------
 1000|     46|		apdu.p2 = 0xB6;
 1001|     46|		break;
 1002|      0|	default:
  ------------------
  |  Branch (1002:2): [True: 0, False: 72]
  ------------------
 1003|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1004|     72|	}
 1005|     72|	p = sbuf;
 1006|     72|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|     72|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1006:6): [True: 72, False: 0]
  ------------------
 1007|     72|		*p++ = 0x80;	/* algorithm reference */
 1008|     72|		*p++ = 0x01;
 1009|     72|		*p++ = env->algorithm_ref & 0xFF;
 1010|     72|	}
 1011|     72|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   57|     72|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1011:6): [True: 0, False: 72]
  ------------------
 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|     72|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|     72|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1022:6): [True: 72, False: 0]
  ------------------
 1023|     72|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1023:7): [True: 0, False: 72]
  ------------------
 1024|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1025|       |
 1026|     72|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|     72|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1026:7): [True: 0, False: 72]
  ------------------
 1027|      0|			*p++ = 0x83;
 1028|     72|		else
 1029|     72|			*p++ = 0x84;
 1030|     72|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|     72|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1030:7): [True: 0, False: 72]
  ------------------
 1031|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1032|     72|		*p++ = env->key_ref_len & 0xFF;
 1033|     72|		memcpy(p, env->key_ref, env->key_ref_len);
 1034|     72|		p += env->key_ref_len;
 1035|     72|	}
 1036|     72|	r = (int)(p - sbuf);
 1037|     72|	apdu.lc = r;
 1038|     72|	apdu.datalen = r;
 1039|     72|	apdu.data = sbuf;
 1040|     72|	if (se_num > 0) {
  ------------------
  |  Branch (1040:6): [True: 0, False: 72]
  ------------------
 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|     72|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1045:6): [True: 72, False: 0]
  ------------------
 1046|     72|		r = sc_transmit_apdu(card, &apdu);
 1047|     72|		if (r) {
  ------------------
  |  Branch (1047:7): [True: 1, False: 71]
  ------------------
 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|     71|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1052|     71|		if (r) {
  ------------------
  |  Branch (1052:7): [True: 14, False: 57]
  ------------------
 1053|     14|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1054|     14|			goto err;
 1055|     14|		}
 1056|     71|	}
 1057|     57|	if (se_num <= 0) {
  ------------------
  |  Branch (1057:6): [True: 57, False: 0]
  ------------------
 1058|     57|		r = SC_SUCCESS;
  ------------------
  |  |   28|     57|#define SC_SUCCESS				0
  ------------------
 1059|     57|		goto err;
 1060|     57|	}
 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|     72|err:
 1068|     72|	if (locked)
  ------------------
  |  Branch (1068:6): [True: 0, False: 72]
  ------------------
 1069|      0|		sc_unlock(card);
 1070|     72|	return r;
 1071|      0|}
iso7816.c:iso7816_compute_signature:
 1099|      6|{
 1100|      6|	int r;
 1101|      6|	struct sc_apdu apdu;
 1102|       |
 1103|      6|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1103:6): [True: 0, False: 6]
  |  Branch (1103:22): [True: 0, False: 6]
  |  Branch (1103:38): [True: 0, False: 6]
  ------------------
 1104|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1105|      0|	}
 1106|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|      6|	sc_log(card->ctx, "ISO7816 compute signature: in-len %zu, out-len %zu", datalen, outlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1108|       |
 1109|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1110|       |	 * P1:  0x9E  Resp: Digital Signature
 1111|       |	 * P2:  0x9A  Cmd: Input for Digital Signature */
 1112|      6|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  303|      6|#define SC_APDU_CASE_4			0x24
  ------------------
 1113|      6|	apdu.resp = out;
 1114|      6|	apdu.resplen = outlen;
 1115|      6|	apdu.le = outlen;
 1116|       |
 1117|      6|	apdu.data = data;
 1118|      6|	apdu.lc = datalen;
 1119|      6|	apdu.datalen = datalen;
 1120|       |
 1121|      6|	iso7816_fixup_transceive_length(card, &apdu);
 1122|      6|	r = sc_transmit_apdu(card, &apdu);
 1123|      6|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1124|      5|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1124:6): [True: 3, False: 2]
  |  Branch (1124:26): [True: 2, False: 1]
  ------------------
 1125|      5|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1126|       |
 1127|      3|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1128|      3|	LOG_TEST_RET(card->ctx, r, "Card returned 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1129|       |
 1130|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|      0|}
iso7816.c:iso7816_check_sw:
  111|   369k|{
  112|   369k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  113|   369k|	int i;
  114|       |
  115|       |	/* Handle special cases here */
  116|   369k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (116:6): [True: 245, False: 369k]
  ------------------
  117|    245|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    245|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  118|    245|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    245|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  119|    245|	}
  120|   369k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (120:6): [True: 129k, False: 240k]
  |  Branch (120:21): [True: 123k, False: 5.45k]
  ------------------
  121|   123k|		return SC_SUCCESS;
  ------------------
  |  |   28|   123k|#define SC_SUCCESS				0
  ------------------
  122|   245k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (122:6): [True: 2.26k, False: 243k]
  |  Branch (122:22): [True: 127, False: 2.13k]
  ------------------
  123|    127|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  124|    127|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    127|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  125|    127|	}
  126|  10.0M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (126:14): [True: 10.0M, False: 26.4k]
  ------------------
  127|  10.0M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (127:7): [True: 219k, False: 9.79M]
  ------------------
  128|   219k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   219k|#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|   219k|			return iso7816_errors[i].errorno;
  130|   219k|		}
  131|  10.0M|	}
  132|       |
  133|  26.4k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  26.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__
  |  |  ------------------
  ------------------
  134|  26.4k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  26.4k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  135|   245k|}
iso7816.c:iso7816_process_fci:
  431|  9.63k|{
  432|  9.63k|	struct sc_context *ctx = card->ctx;
  433|  9.63k|	const unsigned char *p, *end;
  434|  9.63k|	unsigned int cla = 0, tag = 0;
  435|  9.63k|	size_t length;
  436|       |
  437|  9.63k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.63k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  438|       |
  439|  9.63k|	for (p = buf, length = buflen, end = buf + buflen;
  440|  26.7k|			p < end;
  ------------------
  |  Branch (440:4): [True: 24.2k, False: 2.52k]
  ------------------
  441|  24.2k|			p += length, length = end - p) {
  442|       |
  443|  24.2k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  24.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:7): [True: 4.34k, False: 19.8k]
  ------------------
  444|  19.8k|				|| p == NULL) {
  ------------------
  |  Branch (444:8): [True: 2.76k, False: 17.1k]
  ------------------
  445|  7.11k|			break;
  446|  7.11k|		}
  447|  17.1k|		switch (cla | tag) {
  ------------------
  |  Branch (447:11): [True: 13.9k, False: 3.15k]
  ------------------
  448|  1.45k|			case 0x81:
  ------------------
  |  Branch (448:4): [True: 1.45k, False: 15.6k]
  ------------------
  449|  1.45k|				if (file->size != 0) {
  ------------------
  |  Branch (449:9): [True: 87, False: 1.36k]
  ------------------
  450|       |					/* don't overwrite existing file size excluding structural information */
  451|     87|					break;
  452|     87|				}
  453|       |				/* fall through */
  454|  4.45k|			case 0x80:
  ------------------
  |  Branch (454:4): [True: 3.09k, False: 14.0k]
  ------------------
  455|       |				/* determine the file size */
  456|  4.45k|				file->size = 0;
  457|  4.45k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (457:9): [True: 4.45k, False: 0]
  |  Branch (457:14): [True: 4.40k, False: 52]
  ------------------
  458|  4.40k|					size_t size = 0, i;
  459|  14.6k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (459:18): [True: 10.2k, False: 4.40k]
  ------------------
  460|  10.2k|						size <<= 8;
  461|  10.2k|						size |= p[i];
  462|  10.2k|					}
  463|  4.40k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  4.40k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (463:10): [True: 685, False: 3.71k]
  ------------------
  464|    685|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  220|    685|#define MAX_FILE_SIZE 65535
  ------------------
  465|    685|						sc_log(ctx, "  file size truncated, encoded length: %zu", size);
  ------------------
  |  |   71|    685|#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.71k|					} else {
  467|  3.71k|						file->size = size;
  468|  3.71k|					}
  469|  4.40k|				}
  470|       |
  471|  4.45k|				sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
  472|  4.45k|				break;
  473|       |
  474|  2.89k|			case 0x82:
  ------------------
  |  Branch (474:4): [True: 2.89k, False: 14.2k]
  ------------------
  475|  2.89k|				if (length > 0) {
  ------------------
  |  Branch (475:9): [True: 2.57k, False: 318]
  ------------------
  476|  2.57k|					unsigned char byte = p[0];
  477|  2.57k|					const char *type;
  478|       |
  479|  2.57k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (479:24): [True: 347, False: 2.23k]
  ------------------
  480|  2.57k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  5.15k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 347, False: 2.23k]
  |  |  ------------------
  ------------------
  481|  2.57k|					file->ef_structure = byte & 0x07;
  482|  2.57k|					switch ((byte >> 3) & 7) {
  483|  1.79k|						case 0:
  ------------------
  |  Branch (483:7): [True: 1.79k, False: 782]
  ------------------
  484|  1.79k|							type = "working EF";
  485|  1.79k|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.79k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  486|  1.79k|							break;
  487|    170|						case 1:
  ------------------
  |  Branch (487:7): [True: 170, False: 2.40k]
  ------------------
  488|    170|							type = "internal EF";
  489|    170|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    170|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  490|    170|							break;
  491|    319|						case 7:
  ------------------
  |  Branch (491:7): [True: 319, False: 2.25k]
  ------------------
  492|    319|							type = "DF";
  493|    319|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    319|#define SC_FILE_TYPE_DF			0x04
  ------------------
  494|    319|							break;
  495|    293|						default:
  ------------------
  |  Branch (495:7): [True: 293, False: 2.28k]
  ------------------
  496|    293|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    293|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  497|    293|							type = "unknown";
  498|    293|							break;
  499|  2.57k|					}
  500|  2.57k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   71|  2.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  501|  2.57k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   71|  2.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  502|  2.57k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   71|  2.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|       |
  504|       |					/* if possible, get additional information for non-DFs */
  505|  2.57k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  2.57k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (505:10): [True: 2.25k, False: 319]
  ------------------
  506|       |						/* max. record length for fixed- & variable-sized records */
  507|  2.25k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (507:11): [True: 504, False: 1.75k]
  |  Branch (507:25): [True: 287, False: 217]
  ------------------
  508|    287|							file->record_length = (length > 3)
  ------------------
  |  Branch (508:30): [True: 217, False: 70]
  ------------------
  509|    287|								? bebytes2ushort(p+2)
  510|    287|								: p[2];
  511|    287|							sc_log(ctx, "  record length: %zu", file->record_length);
  ------------------
  |  |   71|    287|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  512|    287|						}
  513|       |
  514|       |						/* number of records */
  515|  2.25k|						if (length > 4) {
  ------------------
  |  Branch (515:11): [True: 391, False: 1.86k]
  ------------------
  516|    391|							file->record_count = (length > 5)
  ------------------
  |  Branch (516:29): [True: 191, False: 200]
  ------------------
  517|    391|								? bebytes2ushort(p+4)
  518|    391|								: p[4];
  519|    391|							sc_log(ctx, "  records: %zu", file->record_count);
  ------------------
  |  |   71|    391|#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|    391|						}
  521|  2.25k|					}
  522|       |
  523|  2.57k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  2.57k|#define SC_SUCCESS				0
  ------------------
  |  Branch (523:10): [True: 0, False: 2.57k]
  ------------------
  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.57k|				}
  526|  2.89k|				break;
  527|       |
  528|  2.89k|			case 0x83:
  ------------------
  |  Branch (528:4): [True: 641, False: 16.4k]
  ------------------
  529|    641|				if (length == 2) {
  ------------------
  |  Branch (529:9): [True: 368, False: 273]
  ------------------
  530|    368|					file->id = (p[0] << 8) | p[1];
  531|    368|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|    368|#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|    368|				}
  533|    641|				break;
  534|       |
  535|    648|			case 0x84:
  ------------------
  |  Branch (535:4): [True: 648, False: 16.4k]
  ------------------
  536|    648|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (536:9): [True: 451, False: 197]
  |  Branch (536:23): [True: 433, False: 18]
  ------------------
  537|    433|					memcpy(file->name, p, length);
  538|    433|					file->namelen = length;
  539|       |
  540|    433|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    433|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    433|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  541|    433|					if (!file->type)
  ------------------
  |  Branch (541:10): [True: 137, False: 296]
  ------------------
  542|    137|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    137|#define SC_FILE_TYPE_DF			0x04
  ------------------
  543|    433|				}
  544|    648|				break;
  545|       |
  546|    595|			case 0x85:
  ------------------
  |  Branch (546:4): [True: 595, False: 16.5k]
  ------------------
  547|    811|			case 0xA5:
  ------------------
  |  Branch (547:4): [True: 216, False: 16.8k]
  ------------------
  548|    811|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|    811|#define SC_SUCCESS				0
  ------------------
  |  Branch (548:9): [True: 0, False: 811]
  ------------------
  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|    811|				break;
  552|       |
  553|  1.22k|			case 0x86:
  ------------------
  |  Branch (553:4): [True: 1.22k, False: 15.8k]
  ------------------
  554|  1.22k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (554:9): [True: 0, False: 1.22k]
  ------------------
  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.22k|				break;
  558|       |
  559|    292|			case 0x88:
  ------------------
  |  Branch (559:4): [True: 292, False: 16.8k]
  ------------------
  560|    292|				if (length == 1) {
  ------------------
  |  Branch (560:9): [True: 71, False: 221]
  ------------------
  561|     71|					file->sid = *p;
  562|     71|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  563|     71|				}
  564|    292|				break;
  565|       |
  566|  1.56k|			case 0x8A:
  ------------------
  |  Branch (566:4): [True: 1.56k, False: 15.5k]
  ------------------
  567|  1.56k|				if (length == 1) {
  ------------------
  |  Branch (567:9): [True: 1.35k, False: 207]
  ------------------
  568|  1.35k|					switch (p[0]) {
  569|     74|						case 0:
  ------------------
  |  Branch (569:7): [True: 74, False: 1.28k]
  ------------------
  570|     74|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     74|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  571|     74|							break;
  572|     69|						case 1:
  ------------------
  |  Branch (572:7): [True: 69, False: 1.28k]
  ------------------
  573|     69|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     69|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  574|     69|							break;
  575|     66|						case 3:
  ------------------
  |  Branch (575:7): [True: 66, False: 1.29k]
  ------------------
  576|     66|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     66|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  577|     66|							break;
  578|     66|						case 4:
  ------------------
  |  Branch (578:7): [True: 66, False: 1.29k]
  ------------------
  579|    133|						case 6:
  ------------------
  |  Branch (579:7): [True: 67, False: 1.28k]
  ------------------
  580|    133|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    133|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  581|    133|							break;
  582|    275|						case 5:
  ------------------
  |  Branch (582:7): [True: 275, False: 1.08k]
  ------------------
  583|    343|						case 7:
  ------------------
  |  Branch (583:7): [True: 68, False: 1.28k]
  ------------------
  584|    343|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    343|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  585|    343|							break;
  586|     66|						case 12:
  ------------------
  |  Branch (586:7): [True: 66, False: 1.29k]
  ------------------
  587|    132|						case 13:
  ------------------
  |  Branch (587:7): [True: 66, False: 1.29k]
  ------------------
  588|    198|						case 14:
  ------------------
  |  Branch (588:7): [True: 66, False: 1.29k]
  ------------------
  589|    264|						case 15:
  ------------------
  |  Branch (589:7): [True: 66, False: 1.29k]
  ------------------
  590|    264|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    264|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  591|    264|							break;
  592|     66|						case 2:
  ------------------
  |  Branch (592:7): [True: 66, False: 1.29k]
  ------------------
  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|     68|						case 8:
  ------------------
  |  Branch (595:7): [True: 68, False: 1.28k]
  ------------------
  596|     68|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     68|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  597|     68|							break;
  598|     66|						case 9:
  ------------------
  |  Branch (598:7): [True: 66, False: 1.29k]
  ------------------
  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|     67|						case 10:
  ------------------
  |  Branch (601:7): [True: 67, False: 1.28k]
  ------------------
  602|     67|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     67|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  603|     67|							break;
  604|     66|						case 11:
  ------------------
  |  Branch (604:7): [True: 66, False: 1.29k]
  ------------------
  605|     66|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     66|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  606|     66|							break;
  607|     74|						default:
  ------------------
  |  Branch (607:7): [True: 74, False: 1.28k]
  ------------------
  608|     74|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|     74|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  609|  1.35k|					}
  610|  1.35k|				}
  611|  1.56k|				break;
  612|       |
  613|  1.56k|			case 0x62:
  ------------------
  |  Branch (613:4): [True: 1.10k, False: 16.0k]
  ------------------
  614|  1.18k|			case 0x64:
  ------------------
  |  Branch (614:4): [True: 83, False: 17.0k]
  ------------------
  615|  1.34k|			case 0x6F:
  ------------------
  |  Branch (615:4): [True: 159, False: 16.9k]
  ------------------
  616|       |				/* allow nested FCP/FMD/FCI templates */
  617|  1.34k|				iso7816_process_fci(card, file, p, length);
  618|  17.1k|		}
  619|  17.1k|	}
  620|       |
  621|  9.63k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  9.63k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  622|       |
  623|  9.63k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.63k|#define SC_SUCCESS				0
  ------------------
  624|  9.63k|}
iso7816.c:iso7816_pin_cmd:
 1282|  2.40k|{
 1283|  2.40k|	struct sc_apdu local_apdu, *apdu;
 1284|  2.40k|	int r;
 1285|  2.40k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1286|       |
 1287|  2.40k|	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|  2.40k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|  4.80k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1293:6): [True: 2.04k, False: 353]
  ------------------
 1294|  2.04k|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  553|  2.04k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1294:6): [True: 434, False: 1.61k]
  ------------------
 1295|    434|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    434|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1296|    434|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    434|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1297|    434|	}
 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.96k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1304:6): [True: 1.96k, False: 1]
  ------------------
 1305|  1.96k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1306|  1.96k|		if (r < 0)
  ------------------
  |  Branch (1306:7): [True: 20, False: 1.94k]
  ------------------
 1307|     20|			return r;
 1308|  1.94k|		data->apdu = &local_apdu;
 1309|  1.94k|	}
 1310|  1.94k|	apdu = data->apdu;
 1311|       |
 1312|  1.94k|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  421|  1.94k|#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: 1.94k, False: 0]
  |  Branch (1312:48): [True: 0, False: 0]
  ------------------
 1313|       |		/* Transmit the APDU to the card */
 1314|  1.94k|		r = sc_transmit_apdu(card, apdu);
 1315|       |
 1316|       |		/* Clear the buffer - it may contain pins */
 1317|  1.94k|		sc_mem_clear(sbuf, sizeof(sbuf));
 1318|  1.94k|	}
 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|  1.94k|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1338:6): [True: 1.94k, False: 1]
  ------------------
 1339|  1.94k|		data->apdu = NULL;
 1340|       |
 1341|  1.94k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.94k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.94k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.94k|	int _ret = (r); \
  |  |  |  |  168|  1.94k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 1.93k]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|  1.94k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1342|  1.93k|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1343|       |
 1344|  1.93k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.93k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1344:6): [True: 877, False: 1.05k]
  ------------------
 1345|    877|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|    877|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1346|  1.05k|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|  1.05k|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1346:13): [True: 13, False: 1.04k]
  ------------------
 1347|     13|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1348|     13|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     13|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1349|     13|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     13|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1349:7): [True: 10, False: 3]
  ------------------
 1350|     10|			r = SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
 1351|  1.04k|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|  1.04k|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1351:13): [True: 2, False: 1.04k]
  ------------------
 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|  1.93k|	return r;
 1359|  1.94k|}
iso7816.c:iso7816_get_data:
 1363|    184|{
 1364|    184|	int                             r, cse;
 1365|    184|	struct sc_apdu                  apdu;
 1366|       |
 1367|    184|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    184|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    184|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    184|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 184]
  |  |  ------------------
  ------------------
 1368|       |
 1369|    184|	if (buf && len)
  ------------------
  |  Branch (1369:6): [True: 184, False: 0]
  |  Branch (1369:13): [True: 184, False: 0]
  ------------------
 1370|    184|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    184|#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|    184|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1375|    184|	apdu.le = len;
 1376|    184|	apdu.resp = buf;
 1377|    184|	apdu.resplen = len;
 1378|    184|	r = sc_transmit_apdu(card, &apdu);
 1379|    184|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    184|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    184|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    184|	int _ret = (r); \
  |  |  |  |  168|    184|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 174]
  |  |  |  |  ------------------
  |  |  |  |  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|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 174]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1380|       |
 1381|    174|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1382|    174|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|    174|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    174|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    174|	int _ret = (r); \
  |  |  |  |  168|    174|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 57, False: 117]
  |  |  |  |  ------------------
  |  |  |  |  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|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 117]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|       |
 1384|    117|	if (apdu.resplen > len)
  ------------------
  |  Branch (1384:6): [True: 0, False: 117]
  ------------------
 1385|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1386|    117|	else
 1387|    117|		r = (int)apdu.resplen;
 1388|       |
 1389|    117|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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: 11, False: 106]
  |  |  |  |  ------------------
  |  |  |  |  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|    106|	} else { \
  |  |  |  |  159|    106|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    106|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    106|	} \
  |  |  |  |  162|    117|	return _ret; \
  |  |  |  |  163|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1390|    117|}
iso7816.c:iso7816_read_binary:
  140|  23.1k|{
  141|  23.1k|	struct sc_context *ctx = card->ctx;
  142|  23.1k|	struct sc_apdu apdu;
  143|  23.1k|	int r;
  144|       |
  145|  23.1k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (145:6): [True: 11, False: 23.1k]
  ------------------
  146|     11|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  147|     11|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|     11|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  148|     11|	}
  149|       |
  150|  23.1k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  23.1k|#define SC_APDU_CASE_2			0x22
  ------------------
  151|  23.1k|	apdu.le = count;
  152|  23.1k|	apdu.resplen = count;
  153|  23.1k|	apdu.resp = buf;
  154|       |
  155|  23.1k|	iso7816_fixup_transceive_length(card, &apdu);
  156|  23.1k|	r = sc_transmit_apdu(card, &apdu);
  157|  23.1k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  23.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  23.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  23.1k|	int _ret = (r); \
  |  |  |  |  168|  23.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 600, False: 22.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|    600|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    600|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    600|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    600|		return _ret; \
  |  |  |  |  172|    600|	} \
  |  |  |  |  173|  23.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|       |
  159|  22.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  160|  22.5k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  45.0k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  22.0k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (160:6): [True: 486, False: 22.0k]
  |  Branch (160:40): [True: 96, False: 21.9k]
  ------------------
  161|  22.5k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    582|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    582|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    582|	int _ret = r; \
  |  |  |  |  155|    582|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 113, False: 469]
  |  |  |  |  ------------------
  |  |  |  |  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|    469|	} else { \
  |  |  |  |  159|    469|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    469|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    469|	} \
  |  |  |  |  162|    582|	return _ret; \
  |  |  |  |  163|    582|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|  21.9k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  21.9k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  21.9k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  21.9k|	int _ret = (r); \
  |  |  |  |  168|  21.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.36k, False: 18.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.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|  3.36k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.36k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.36k|		return _ret; \
  |  |  |  |  172|  3.36k|	} \
  |  |  |  |  173|  21.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|  18.5k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  18.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.5k|	int _ret = r; \
  |  |  |  |  155|  18.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.18k, False: 16.3k]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.18k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.3k|	} else { \
  |  |  |  |  159|  16.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.3k|	} \
  |  |  |  |  162|  18.5k|	return _ret; \
  |  |  |  |  163|  18.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|  18.5k|}

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

mscfs_new:
   45|    748|mscfs_t *mscfs_new(void) {
   46|    748|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   47|    748|	if (!fs)
  ------------------
  |  Branch (47:6): [True: 0, False: 748]
  ------------------
   48|      0|		return NULL;
   49|    748|	memset(fs, 0, sizeof(mscfs_t));
   50|    748|	memcpy(fs->currentPath, "\x3F\x00", 2);
   51|    748|	return fs;
   52|    748|}
mscfs_free:
   54|    748|void mscfs_free(mscfs_t *fs) {
   55|    748|	mscfs_clear_cache(fs);
   56|    748|	free(fs);
   57|    748|}
mscfs_clear_cache:
   59|  3.30k|void mscfs_clear_cache(mscfs_t* fs) {
   60|  3.30k|	if(!fs->cache.array) {
  ------------------
  |  Branch (60:5): [True: 2.96k, False: 341]
  ------------------
   61|  2.96k|		return;
   62|  2.96k|	}
   63|    341|	free(fs->cache.array);
   64|       |	fs->cache.array = NULL;
   65|    341|	fs->cache.totalSize = 0;
   66|    341|	fs->cache.size = 0;
   67|    341|}
mscfs_push_file:
   83|  29.4k|{
   84|  29.4k|	mscfs_cache_t *cache = &fs->cache;
   85|  29.4k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   81|  29.4k|#define MAX_FILES 10000
  ------------------
  |  Branch (85:6): [True: 0, False: 29.4k]
  ------------------
   86|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   87|  29.4k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (87:5): [True: 341, False: 29.0k]
  |  Branch (87:22): [True: 213, False: 28.8k]
  ------------------
   88|    554|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   35|    554|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   89|    554|		mscfs_file_t *oldArray;
   90|    554|		cache->totalSize = length;
   91|    554|		oldArray = cache->array;
   92|    554|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   93|    554|		if(!cache->array)
  ------------------
  |  Branch (93:6): [True: 0, False: 554]
  ------------------
   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|    554|		if(oldArray) {
  ------------------
  |  Branch (95:6): [True: 213, False: 341]
  ------------------
   96|    213|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   97|    213|			free(oldArray);
   98|    213|		}
   99|    554|	}
  100|  29.4k|	cache->array[cache->size] = *file;
  101|  29.4k|	cache->size++;
  102|  29.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  29.4k|#define SC_SUCCESS				0
  ------------------
  103|  29.4k|}
mscfs_update_cache:
  105|  2.55k|int mscfs_update_cache(mscfs_t* fs) {
  106|  2.55k|	mscfs_file_t file;
  107|  2.55k|	int r;
  108|  2.55k|	mscfs_clear_cache(fs);
  109|  2.55k|	r = fs->listFile(&file, 1, fs->udata);
  110|  2.55k|	if(r == 0)
  ------------------
  |  Branch (110:5): [True: 84, False: 2.47k]
  ------------------
  111|     84|		return 0;
  112|  2.47k|	else if(r < 0)
  ------------------
  |  Branch (112:10): [True: 2.09k, False: 381]
  ------------------
  113|  2.09k|		return r;
  114|  30.0k|	while(1) {
  ------------------
  |  Branch (114:8): [True: 30.0k, Folded]
  ------------------
  115|  30.0k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (115:6): [True: 29.4k, False: 645]
  ------------------
  116|       |			/* Check if its a directory in the root */
  117|  29.4k|			u8* oid = file.objectId.id;
  118|  29.4k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (118:7): [True: 19.7k, False: 9.62k]
  |  Branch (118:22): [True: 7.83k, False: 11.9k]
  ------------------
  119|  7.83k|				oid[2] = oid[0];
  120|  7.83k|				oid[3] = oid[1];
  121|  7.83k|				oid[0] = 0x3F;
  122|  7.83k|				oid[1] = 0x00;
  123|  7.83k|				file.ef = 0;
  124|  21.5k|			} else  {
  125|  21.5k|				file.ef = 1; /* File is a working elementary file */
  126|  21.5k|			}
  127|       |
  128|  29.4k|			r = mscfs_push_file(fs, &file);
  129|  29.4k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  29.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (129:8): [True: 0, False: 29.4k]
  ------------------
  130|      0|				return r;
  131|  29.4k|		}
  132|  30.0k|		r = fs->listFile(&file, 0, fs->udata);
  133|  30.0k|		if(r == 0)
  ------------------
  |  Branch (133:6): [True: 168, False: 29.8k]
  ------------------
  134|    168|			break;
  135|  29.8k|		else if(r < 0)
  ------------------
  |  Branch (135:11): [True: 213, False: 29.6k]
  ------------------
  136|    213|			return r;
  137|  30.0k|	}
  138|    168|	return fs->cache.size;
  139|    381|}
mscfs_check_cache:
  142|  4.50k|{
  143|  4.50k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  4.50k|#define SC_SUCCESS				0
  ------------------
  144|  4.50k|	if(!fs->cache.array) {
  ------------------
  |  Branch (144:5): [True: 2.55k, False: 1.94k]
  ------------------
  145|  2.55k|		r = mscfs_update_cache(fs);
  146|  2.55k|	}
  147|  4.50k|	return r;
  148|  4.50k|}
mscfs_lookup_path:
  151|  1.32k|{
  152|  1.32k|	u8* oid = objectId->id;
  153|  1.32k|	if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (153:6): [True: 405, False: 915]
  ------------------
  154|    405|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|    405|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    405|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  155|    915|	if(isDirectory) {
  ------------------
  |  Branch (155:5): [True: 0, False: 915]
  ------------------
  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|    915|	oid[0] = fs->currentPath[0];
  167|    915|	oid[1] = fs->currentPath[1];
  168|       |	/* Chop off the root in the path */
  169|    915|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (169:5): [True: 796, False: 119]
  |  Branch (169:20): [True: 758, False: 38]
  ------------------
  170|    758|		path += 2;
  171|    758|		pathlen -= 2;
  172|    758|		oid[0] = 0x3F;
  173|    758|		oid[1] = 0x00;
  174|    758|	}
  175|       |	/* Limit to a single directory */
  176|    915|	if(pathlen > 4)
  ------------------
  |  Branch (176:5): [True: 15, False: 900]
  ------------------
  177|     15|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|     15|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|     15|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  178|       |	/* Reset to root */
  179|    900|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (179:5): [True: 670, False: 230]
  |  Branch (179:21): [True: 11, False: 659]
  ------------------
  180|     11|		oid[0] = oid[2] = path[0];
  181|     11|		oid[1] = oid[3] = path[1];
  182|    889|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (182:12): [True: 659, False: 230]
  ------------------
  183|    659|		oid[2] = path[0];
  184|    659|		oid[3] = path[1];
  185|    659|	} else if(pathlen == 4) {
  ------------------
  |  Branch (185:12): [True: 230, False: 0]
  ------------------
  186|    230|		oid[0] = path[0];
  187|    230|		oid[1] = path[1];
  188|    230|		oid[2] = path[2];
  189|    230|		oid[3] = path[3];
  190|    230|	}
  191|       |
  192|    900|	return 0;
  193|    915|}
mscfs_check_selection:
  207|    244|{
  208|    244|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (208:5): [True: 0, False: 244]
  |  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|    244|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (210:5): [True: 0, False: 244]
  |  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|    244|	return 0;
  213|    244|}
mscfs_loadFileInfo:
  216|  1.32k|{
  217|  1.32k|	msc_id fullPath = {{0, 0, 0, 0}};
  218|  1.32k|	int x, rc;
  219|  1.32k|	if (fs == NULL || path == NULL || file_data == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 1.32k]
  |  Branch (219:20): [True: 0, False: 1.32k]
  |  Branch (219:36): [True: 0, False: 1.32k]
  ------------------
  220|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  221|  1.32k|	rc = mscfs_lookup_path(fs, path, pathlen, &fullPath, 0);
  222|  1.32k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  1.32k|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:6): [True: 420, False: 900]
  ------------------
  223|    420|		return rc;
  224|    420|	}
  225|       |
  226|       |	/* Obtain file information while checking if it exists */
  227|    900|	rc = mscfs_check_cache(fs);
  228|    900|	if (rc < 0)
  ------------------
  |  Branch (228:6): [True: 22, False: 878]
  ------------------
  229|     22|		return rc;
  230|    878|	if(idx) *idx = -1;
  ------------------
  |  Branch (230:5): [True: 878, False: 0]
  ------------------
  231|  47.6k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (231:13): [True: 47.1k, False: 577]
  ------------------
  232|  47.1k|		*file_data = &fs->cache.array[x];
  233|  47.1k|		if (*file_data) {
  ------------------
  |  Branch (233:7): [True: 47.1k, False: 0]
  ------------------
  234|  47.1k|			msc_id objectId;
  235|  47.1k|			objectId = (*file_data)->objectId;
  236|  47.1k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (236:7): [True: 301, False: 46.8k]
  ------------------
  237|    301|				if (idx)
  ------------------
  |  Branch (237:9): [True: 301, False: 0]
  ------------------
  238|    301|					*idx = x;
  239|    301|				break;
  240|    301|			}
  241|  46.8k|			*file_data = NULL;
  242|  46.8k|		}
  243|  47.1k|	}
  244|    878|	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: 577, False: 301]
  |  Branch (244:28): [True: 13, False: 564]
  |  Branch (244:79): [True: 191, False: 373]
  |  Branch (244:131): [True: 11, False: 362]
  ------------------
  245|    215|		static mscfs_file_t ROOT_FILE;
  246|    215|		ROOT_FILE.ef = 0;
  247|    215|		ROOT_FILE.size = 0;
  248|       |		/* Faked Root ID */
  249|    215|		ROOT_FILE.objectId = rootId;
  250|       |
  251|    215|		ROOT_FILE.read = 0;
  252|    215|		ROOT_FILE.write = 0x02; /* User Pin access */
  253|    215|		ROOT_FILE.delete = 0x02;
  254|       |
  255|    215|		*file_data = &ROOT_FILE;
  256|    215|		if(idx) *idx = -2;
  ------------------
  |  Branch (256:6): [True: 215, False: 0]
  ------------------
  257|    663|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (257:12): [True: 362, False: 301]
  ------------------
  258|    362|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   34|    362|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    362|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  259|    362|	}
  260|       |
  261|    516|	return 0;
  262|    878|}
muscle-filesystem.c:mscfs_is_ignored:
   70|  30.0k|{
   71|  30.0k|	int ignored = 0;
   72|  30.0k|	const u8** ptr = ignoredFiles;
   73|  89.5k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (73:8): [True: 89.5k, False: 0]
  |  Branch (73:15): [True: 60.0k, False: 29.4k]
  |  Branch (73:23): [True: 59.4k, False: 626]
  ------------------
   74|  59.4k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (74:6): [True: 645, False: 58.8k]
  ------------------
   75|    645|			ignored = 1;
   76|  59.4k|		ptr++;
   77|  59.4k|	}
   78|  30.0k|	return ignored;
   79|  30.0k|}

msc_list_objects:
   37|  32.6k|int msc_list_objects(sc_card_t* card, u8 next, mscfs_file_t* file) {
   38|  32.6k|	sc_apdu_t apdu;
   39|  32.6k|	u8 fileData[14];
   40|  32.6k|	int r;
   41|       |
   42|  32.6k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x58, next, 0x00);
  ------------------
  |  |  301|  32.6k|#define SC_APDU_CASE_2			0x22
  ------------------
   43|  32.6k|	apdu.le = 14;
   44|  32.6k|	apdu.resplen = 14;
   45|  32.6k|	apdu.resp = fileData;
   46|  32.6k|	r = sc_transmit_apdu(card, &apdu);
   47|  32.6k|	if (r)
  ------------------
  |  Branch (47:6): [True: 39, False: 32.5k]
  ------------------
   48|     39|		return r;
   49|       |
   50|  32.5k|	if(apdu.sw1 == 0x9C && apdu.sw2 == 0x12) {
  ------------------
  |  Branch (50:5): [True: 183, False: 32.3k]
  |  Branch (50:25): [True: 30, False: 153]
  ------------------
   51|     30|		return 0;
   52|     30|	}
   53|  32.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
   54|  32.5k|	if (r)
  ------------------
  |  Branch (54:6): [True: 2.25k, False: 30.2k]
  ------------------
   55|  2.25k|		return r;
   56|  30.2k|	if(apdu.resplen == 0) /* No more left */
  ------------------
  |  Branch (56:5): [True: 222, False: 30.0k]
  ------------------
   57|    222|		return 0;
   58|  30.0k|	if (apdu.resplen != 14) {
  ------------------
  |  Branch (58:6): [True: 15, False: 30.0k]
  ------------------
   59|     15|		sc_log(card->ctx, "expected 14 bytes, got %zu.\n", apdu.resplen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   60|     15|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     15|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   61|     15|	}
   62|  30.0k|	memcpy(file->objectId.id, fileData, 4);
   63|  30.0k|	file->size = bebytes2ulong(fileData + 4);
   64|  30.0k|	file->read = bebytes2ushort(fileData + 8);
   65|  30.0k|	file->write = bebytes2ushort(fileData + 10);
   66|  30.0k|	file->delete = bebytes2ushort(fileData + 12);
   67|       |
   68|  30.0k|	return 1;
   69|  30.0k|}
msc_partial_read_object:
   72|    244|{
   73|    244|	u8 buffer[9];
   74|    244|	sc_apdu_t apdu;
   75|    244|	int r;
   76|       |
   77|    244|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x56, 0x00, 0x00);
  ------------------
  |  |  294|    244|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
   78|       |
   79|    244|	sc_log(card->ctx, "READ: Offset: %x\tLength: %zu\n", offset, dataLength);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   80|    244|	memcpy(buffer, objectId.id, 4);
   81|    244|	ulong2bebytes(buffer + 4, offset);
   82|    244|	buffer[8] = (u8)dataLength;
   83|    244|	apdu.data = buffer;
   84|    244|	apdu.datalen = 9;
   85|    244|	apdu.lc = 9;
   86|    244|	apdu.le = dataLength;
   87|    244|	apdu.resplen = dataLength;
   88|    244|	apdu.resp = data;
   89|    244|	r = sc_transmit_apdu(card, &apdu);
   90|    244|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    244|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    244|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    244|	int _ret = (r); \
  |  |  |  |  168|    244|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 241]
  |  |  |  |  ------------------
  |  |  |  |  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|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 241]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|    241|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && dataLength <= apdu.resplen)
  ------------------
  |  Branch (91:6): [True: 205, False: 36]
  |  Branch (91:26): [True: 203, False: 2]
  |  Branch (91:46): [True: 201, False: 2]
  ------------------
   92|    201|		return (int)dataLength;
   93|     40|	if (apdu.sw1 == 0x9C) {
  ------------------
  |  Branch (93:6): [True: 3, False: 37]
  ------------------
   94|      3|		if (apdu.sw2 == 0x07) {
  ------------------
  |  Branch (94:7): [True: 1, False: 2]
  ------------------
   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|      2|		} else if (apdu.sw2 == 0x06) {
  ------------------
  |  Branch (96:14): [True: 1, False: 1]
  ------------------
   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|      1|		} else if (apdu.sw2 == 0x0F) {
  ------------------
  |  Branch (98:14): [True: 1, False: 0]
  ------------------
   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|      3|	}
  103|     37|	sc_log(card->ctx,
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  104|     37|		"got strange SWs: 0x%02X 0x%02X\n", apdu.sw1, apdu.sw2);
  105|     37|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  153|     37|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     37|	int _ret = r; \
  |  |  155|     37|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 37, False: 0]
  |  |  ------------------
  |  |  156|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     37|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 37, False: 0]
  |  |  ------------------
  |  |  157|     37|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     37|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     37|	return _ret; \
  |  |  163|     37|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  106|     37|}
msc_read_object:
  109|    244|{
  110|    244|	int r = 0;
  111|    244|	unsigned int i;
  112|    244|	size_t max_read_unit = MSC_MAX_READ;
  ------------------
  |  |   35|    244|#define MSC_MAX_READ (card->max_recv_size > 0 ? card->max_recv_size : 255)
  |  |  ------------------
  |  |  |  Branch (35:23): [True: 244, False: 0]
  |  |  ------------------
  ------------------
  113|       |
  114|    445|	for (i = 0; i < dataLength; i += r) {
  ------------------
  |  Branch (114:14): [True: 244, False: 201]
  ------------------
  115|    244|		r = msc_partial_read_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_read_unit));
  ------------------
  |  |   70|    244|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 118, False: 126]
  |  |  ------------------
  ------------------
  116|    244|		LOG_TEST_RET(card->ctx, r, "Error in partial object read");
  ------------------
  |  |  174|    244|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    244|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    244|	int _ret = (r); \
  |  |  |  |  168|    244|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 43, False: 201]
  |  |  |  |  ------------------
  |  |  |  |  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|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 201]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|    201|		if (r == 0)
  ------------------
  |  Branch (117:7): [True: 0, False: 201]
  ------------------
  118|      0|			break;
  119|    201|	}
  120|    201|	return (int)dataLength;
  121|    244|}
msc_select_applet:
  256|  7.03k|{
  257|  7.03k|	sc_apdu_t apdu;
  258|  7.03k|	int r;
  259|       |
  260|  7.03k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|  7.03k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  261|  7.03k|	apdu.lc = appletIdLength;
  262|  7.03k|	apdu.data = appletId;
  263|  7.03k|	apdu.datalen = appletIdLength;
  264|  7.03k|	apdu.resplen = 0;
  265|  7.03k|	apdu.le = 0;
  266|       |
  267|  7.03k|	r = sc_transmit_apdu(card, &apdu);
  268|  7.03k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  7.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.03k|	int _ret = (r); \
  |  |  |  |  168|  7.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 7.00k]
  |  |  |  |  ------------------
  |  |  |  |  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|  7.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  7.00k|	if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (269:5): [True: 756, False: 6.24k]
  |  Branch (269:25): [True: 748, False: 8]
  ------------------
  270|    748|		return 1;
  271|       |
  272|  6.25k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,  SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  153|  6.25k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  6.25k|	int _ret = r; \
  |  |  155|  6.25k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 6.25k, False: 0]
  |  |  ------------------
  |  |  156|  6.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|  6.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 6.25k, False: 0]
  |  |  ------------------
  |  |  157|  6.25k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  6.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|  6.25k|	return _ret; \
  |  |  163|  6.25k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  273|  6.25k|}
msc_get_challenge:
  434|     36|{
  435|     36|	sc_apdu_t apdu;
  436|     36|	int r, location, cse;
  437|     36|	size_t len;
  438|     36|	u8 *buffer, *ptr;
  439|       |
  440|     36|	location = (dataLength < MSC_MAX_READ) ? 1 : 2; /* 1 == APDU, 2 == (seed in 0xFFFFFFFE, out in 0xFFFFFFFF) */
  ------------------
  |  |   35|     36|#define MSC_MAX_READ (card->max_recv_size > 0 ? card->max_recv_size : 255)
  |  |  ------------------
  |  |  |  Branch (35:23): [True: 36, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (440:13): [True: 33, False: 3]
  ------------------
  441|     36|	cse = (location == 1) ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  294|     33|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	cse = (location == 1) ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     39|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (441:8): [True: 33, False: 3]
  ------------------
  442|     36|	len = seedLength + 4;
  443|       |
  444|     36|	if (seedLength >= MSC_MAX_SEND - 4 || dataLength >= MSC_MAX_READ - 9)/* Output buffer doesn't seem to operate as desired.... nobody can read/delete */
  ------------------
  |  |   36|     36|#define MSC_MAX_SEND (card->max_send_size > 0 ? card->max_send_size : 255)
  |  |  ------------------
  |  |  |  Branch (36:23): [True: 36, False: 0]
  |  |  ------------------
  ------------------
              	if (seedLength >= MSC_MAX_SEND - 4 || dataLength >= MSC_MAX_READ - 9)/* Output buffer doesn't seem to operate as desired.... nobody can read/delete */
  ------------------
  |  |   35|     36|#define MSC_MAX_READ (card->max_recv_size > 0 ? card->max_recv_size : 255)
  |  |  ------------------
  |  |  |  Branch (35:23): [True: 36, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (444:6): [True: 0, False: 36]
  |  Branch (444:40): [True: 5, False: 31]
  ------------------
  445|     36|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|       |
  447|     31|	buffer = malloc(len);
  448|     31|	if(!buffer) LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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 (448:5): [True: 0, False: 31]
  ------------------
  449|     31|	ptr = buffer;
  450|     31|	ushort2bebytes(ptr, dataLength);
  451|     31|	ptr+=2;
  452|     31|	ushort2bebytes(ptr, seedLength);
  453|     31|	ptr+=2;
  454|     31|	if(seedLength > 0) {
  ------------------
  |  Branch (454:5): [True: 0, False: 31]
  ------------------
  455|      0|		memcpy(ptr, seedData, seedLength);
  456|      0|	}
  457|     31|	sc_format_apdu(card, &apdu, cse, 0x62, 0x00, location);
  458|     31|	apdu.data = buffer;
  459|     31|	apdu.datalen = len;
  460|     31|	apdu.lc = len;
  461|       |
  462|     31|	if(location == 1) {
  ------------------
  |  Branch (462:5): [True: 31, False: 0]
  ------------------
  463|     31|		u8* outputBuffer = malloc(dataLength + 2);
  464|     31|		if(outputBuffer == NULL) {
  ------------------
  |  Branch (464:6): [True: 0, False: 31]
  ------------------
  465|      0|			free(buffer);
  466|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|     31|		};
  468|     31|		apdu.le = dataLength + 2;
  469|     31|		apdu.resp = outputBuffer;
  470|     31|		apdu.resplen = dataLength + 2;
  471|     31|	}
  472|     31|	r = sc_transmit_apdu(card, &apdu);
  473|     31|	if(location == 1) {
  ------------------
  |  Branch (473:5): [True: 31, False: 0]
  ------------------
  474|     31|		memcpy(outputData, apdu.resp + 2, dataLength);
  475|     31|		free(apdu.resp);
  476|     31|	}
  477|     31|	free(buffer);
  478|     31|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     31|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     31|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     31|	int _ret = (r); \
  |  |  |  |  168|     31|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  479|     30|	if(location == 1) {
  ------------------
  |  Branch (479:5): [True: 30, False: 0]
  ------------------
  480|     30|		if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (480:6): [True: 2, False: 28]
  |  Branch (480:26): [True: 1, False: 1]
  ------------------
  481|      1|			return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  482|     29|		} else {
  483|     29|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  484|     29|			if (r) {
  ------------------
  |  Branch (484:8): [True: 29, False: 0]
  ------------------
  485|     29|				if (card->ctx->debug >= 2) {
  ------------------
  |  Branch (485:9): [True: 0, False: 29]
  ------------------
  486|      0|					sc_log(card->ctx,  "got strange SWs: 0x%02X 0x%02X\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__
  |  |  ------------------
  ------------------
  487|      0|					     apdu.sw1, apdu.sw2);
  488|      0|				}
  489|     29|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     29|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     29|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     29|	int _ret = r; \
  |  |  |  |  155|     29|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     29|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     29|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     29|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     29|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     29|	return _ret; \
  |  |  |  |  163|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|     29|			}
  491|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  492|      0|		}
  493|     30|	} else {
  494|      0|		if(apdu.sw1 != 0x90 || apdu.sw2 != 0x00) {
  ------------------
  |  Branch (494:6): [True: 0, False: 0]
  |  Branch (494:26): [True: 0, False: 0]
  ------------------
  495|      0|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  496|      0|			if (r) {
  ------------------
  |  Branch (496:8): [True: 0, False: 0]
  ------------------
  497|      0|				if (card->ctx->debug >= 2) {
  ------------------
  |  Branch (497:9): [True: 0, False: 0]
  ------------------
  498|      0|					sc_log(card->ctx,  "got strange SWs: 0x%02X 0x%02X\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__
  |  |  ------------------
  ------------------
  499|      0|					     apdu.sw1, apdu.sw2);
  500|      0|				}
  501|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  502|      0|			}
  503|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  504|      0|		}
  505|      0|		r = msc_read_object(card, inputId, 2, outputData, dataLength);
  506|      0|		if(r < 0)
  ------------------
  |  Branch (506:6): [True: 0, False: 0]
  ------------------
  507|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  508|      0|		msc_delete_object(card, inputId,0);
  509|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  510|      0|	}
  511|     30|}

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

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

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

sc_pkcs15_read_cached_file:
  113|  5.59k|{
  114|  5.59k|	char fname[PATH_MAX];
  115|  5.59k|	int rv;
  116|  5.59k|	FILE *f;
  117|  5.59k|	size_t count;
  118|  5.59k|	struct stat stbuf;
  119|  5.59k|	u8 *data = NULL;
  120|       |
  121|  5.59k|	if (path->len < 2)
  ------------------
  |  Branch (121:6): [True: 1.78k, False: 3.80k]
  ------------------
  122|  1.78k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.78k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  123|       |
  124|       |	/* Accept full path or FILE-ID path with AID */
  125|  3.80k|	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  119|  3.80k|#define SC_PATH_TYPE_PATH		2
  ------------------
              	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  117|  3.93k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (125:6): [True: 1.96k, False: 1.83k]
  |  Branch (125:44): [True: 1, False: 1.96k]
  |  Branch (125:82): [True: 842, False: 1.12k]
  ------------------
  126|    843|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    843|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  127|       |
  128|  2.96k|	sc_log(p15card->card->ctx, "try to read cache for %s", sc_print_path(path));
  ------------------
  |  |   71|  2.96k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|  2.96k|	rv = generate_cache_filename(p15card, path, fname, sizeof(fname));
  130|  2.96k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  2.96k|#define SC_SUCCESS				0
  ------------------
  |  Branch (130:6): [True: 962, False: 1.99k]
  ------------------
  131|    962|		return rv;
  132|  1.99k|	sc_log(p15card->card->ctx, "read cached file %s", fname);
  ------------------
  |  |   71|  1.99k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  133|       |
  134|  1.99k|	f = fopen(fname, "rb");
  135|  1.99k|	if (!f)
  ------------------
  |  Branch (135:6): [True: 877, False: 1.12k]
  ------------------
  136|    877|		return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    877|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  137|  1.12k|	if (fstat(fileno(f), &stbuf))   {
  ------------------
  |  Branch (137:6): [True: 0, False: 1.12k]
  ------------------
  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|  1.12k|	if (path->count < 0) {
  ------------------
  |  Branch (142:6): [True: 585, False: 536]
  ------------------
  143|    585|		count = stbuf.st_size;
  144|    585|	}
  145|    536|	else {
  146|    536|		count = path->count;
  147|    536|		if (path->index + count > (size_t)stbuf.st_size)   {
  ------------------
  |  Branch (147:7): [True: 385, False: 151]
  ------------------
  148|    385|			rv = SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */
  ------------------
  |  |   51|    385|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  149|    385|			goto err;
  150|    385|		}
  151|       |
  152|    151|		if (0 != fseek(f, (long)path->index, SEEK_SET)) {
  ------------------
  |  Branch (152:7): [True: 0, False: 151]
  ------------------
  153|      0|			rv = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  154|      0|			goto err;
  155|      0|		}
  156|    151|	}
  157|       |
  158|    736|	if (*buf == NULL) {
  ------------------
  |  Branch (158:6): [True: 733, False: 3]
  ------------------
  159|    733|		data = malloc((size_t)stbuf.st_size);
  160|    733|		if (data == NULL)   {
  ------------------
  |  Branch (160:7): [True: 0, False: 733]
  ------------------
  161|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  162|      0|			goto err;
  163|      0|		}
  164|    733|	}
  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|    735|	if (count != fread(data, 1, count, f)) {
  ------------------
  |  Branch (173:6): [True: 0, False: 735]
  ------------------
  174|      0|		rv = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  175|      0|		goto err;
  176|      0|	}
  177|    735|	*buf = data;
  178|    735|	*bufsize = count;
  179|       |
  180|    735|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    735|#define SC_SUCCESS				0
  ------------------
  181|       |
  182|  1.12k|err:
  183|  1.12k|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|  1.12k|#define SC_SUCCESS				0
  ------------------
  |  Branch (183:6): [True: 386, False: 735]
  ------------------
  184|    386|		if (data != *buf) {
  ------------------
  |  Branch (184:7): [True: 1, False: 385]
  ------------------
  185|      1|			free(data);
  186|      1|		}
  187|    386|	}
  188|       |
  189|  1.12k|	fclose(f);
  190|  1.12k|	return rv;
  191|    735|}
sc_pkcs15_cache_file:
  196|    774|{
  197|    774|	char fname[PATH_MAX];
  198|    774|	int r;
  199|    774|	long len;
  200|    774|	FILE *f;
  201|    774|	size_t c;
  202|       |
  203|    774|	r = generate_cache_filename(p15card, path, fname, sizeof(fname));
  204|    774|	if (r != 0)
  ------------------
  |  Branch (204:6): [True: 435, False: 339]
  ------------------
  205|    435|		return r;
  206|       |
  207|    339|	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|    339|	if (f == NULL && errno == ENOENT) {
  ------------------
  |  Branch (211:6): [True: 43, False: 296]
  |  Branch (211:19): [True: 43, False: 0]
  ------------------
  212|     43|		if ((r = sc_make_cache_dir(p15card->card->ctx)) < 0)
  ------------------
  |  Branch (212:7): [True: 43, False: 0]
  ------------------
  213|     43|			return r;
  214|      0|		f = fopen(fname, "ab");
  215|      0|	}
  216|    296|	if (f == NULL)
  ------------------
  |  Branch (216:6): [True: 0, False: 296]
  ------------------
  217|      0|		return 0;
  218|       |
  219|       |	/* we opened the file for appending so we should be at the end of file.
  220|       |	 * The ftell() will give use the length of the file */
  221|    296|	len = ftell(f);
  222|    296|	if (len > path->index) {
  ------------------
  |  Branch (222:6): [True: 32, False: 264]
  ------------------
  223|       |		/* override previous cache records on this location */
  224|     32|		r = fseek(f, path->index, SEEK_SET);
  225|     32|		if (r != 0) {
  ------------------
  |  Branch (225:7): [True: 0, False: 32]
  ------------------
  226|      0|			fclose(f);
  227|      0|			return 0;
  228|      0|		}
  229|    264|	} else if (path->index > len) {
  ------------------
  |  Branch (229:13): [True: 59, False: 205]
  ------------------
  230|       |		/* We miss some bytes so we will not cache this chunk */
  231|     59|		fclose(f);
  232|     59|		return 0;
  233|     59|	}
  234|       |
  235|    237|	c = fwrite(buf, 1, bufsize, f);
  236|    237|	fclose(f);
  237|    237|	if (c != bufsize) {
  ------------------
  |  Branch (237:6): [True: 0, False: 237]
  ------------------
  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|    237|	return 0;
  243|    237|}
pkcs15-cache.c:generate_cache_filename:
   44|  3.73k|{
   45|  3.73k|	char dir[PATH_MAX];
   46|  3.73k|	char *last_update = NULL;
   47|  3.73k|	int  r;
   48|  3.73k|	unsigned u;
   49|  3.73k|	size_t change_counter;
   50|       |
   51|  3.73k|	if (p15card->tokeninfo->serial_number == NULL
  ------------------
  |  Branch (51:6): [True: 1.09k, False: 2.63k]
  ------------------
   52|  1.09k|			&& (p15card->card->uid.len == 0
  ------------------
  |  Branch (52:8): [True: 1.09k, 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.09k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.09k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   55|       |
   56|  2.63k|	if (path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  2.63k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (56:6): [True: 0, False: 2.63k]
  ------------------
   57|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|  2.63k|	r = sc_get_cache_dir(p15card->card->ctx, dir, sizeof(dir));
   59|  2.63k|	if (r)
  ------------------
  |  Branch (59:6): [True: 0, False: 2.63k]
  ------------------
   60|      0|		return r;
   61|  2.63k|	snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "/");
   62|       |
   63|  2.63k|	last_update = sc_pkcs15_get_lastupdate(p15card);
   64|  2.63k|	if (!last_update)
  ------------------
  |  Branch (64:6): [True: 2.63k, False: 0]
  ------------------
   65|  2.63k|		last_update = "NODATE";
   66|       |
   67|  2.63k|	if (p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (67:6): [True: 2.63k, False: 0]
  ------------------
   68|  2.63k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   69|  2.63k|				"%s_%s", p15card->tokeninfo->serial_number,
   70|  2.63k|				last_update);
   71|  2.63k|	} else {
   72|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   73|      0|				"uid-%s_%s", sc_dump_hex(
   74|      0|					p15card->card->uid.value,
   75|      0|					p15card->card->uid.len), last_update);
   76|      0|	}
   77|       |
   78|  2.63k|	if (SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_CHANGE_COUNTER, &change_counter))
  ------------------
  |  |   28|  2.63k|#define SC_SUCCESS				0
  ------------------
  |  Branch (78:6): [True: 1, False: 2.63k]
  ------------------
   79|      1|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_%zu", change_counter);
   80|       |
   81|  2.63k|	if (path->aid.len &&
  ------------------
  |  Branch (81:6): [True: 1.48k, False: 1.15k]
  ------------------
   82|  1.48k|		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  117|  2.96k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
              		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  119|    271|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (82:4): [True: 1.21k, False: 271]
  |  Branch (82:42): [True: 4, False: 267]
  ------------------
   83|  1.21k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   84|  9.74k|		for (u = 0; u < path->aid.len; u++)
  ------------------
  |  Branch (84:15): [True: 8.53k, False: 1.21k]
  ------------------
   85|  8.53k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   86|  8.53k|					"%02X",  path->aid.value[u]);
   87|  1.21k|	}
   88|  1.42k|	else if (path->type != SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.42k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (88:11): [True: 301, False: 1.12k]
  ------------------
   89|    301|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    301|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   90|    301|	}
   91|       |
   92|  2.33k|	if (path->len)   {
  ------------------
  |  Branch (92:6): [True: 2.33k, False: 0]
  ------------------
   93|  2.33k|		size_t offs = 0;
   94|       |
   95|  2.33k|		if (path->len > 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (95:7): [True: 1.12k, False: 1.21k]
  |  Branch (95:24): [True: 1.06k, False: 63]
  ------------------
   96|  1.06k|			offs = 2;
   97|  2.33k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   98|  9.40k|		for (u = 0; u < path->len - offs; u++)
  ------------------
  |  Branch (98:15): [True: 7.06k, False: 2.33k]
  ------------------
   99|  7.06k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  100|  7.06k|					"%02X",  path->value[u + offs]);
  101|  2.33k|	}
  102|       |
  103|  2.33k|	if (!buf)
  ------------------
  |  Branch (103:6): [True: 0, False: 2.33k]
  ------------------
  104|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  105|  2.33k|	strlcpy(buf, dir, bufsize);
  ------------------
  |  |   43|  2.33k|#define strlcpy _strlcpy
  ------------------
  106|       |
  107|  2.33k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.33k|#define SC_SUCCESS				0
  ------------------
  108|  2.33k|}

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

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

sc_pkcs15_get_name_from_dn:
  158|  1.03k|{
  159|  1.03k|	const u8 *rdn = NULL;
  160|  1.03k|	const u8 *next_ava = NULL;
  161|  1.03k|	size_t rdn_len = 0;
  162|  1.03k|	size_t next_ava_len = 0;
  163|  1.03k|	int rv;
  164|       |
  165|  1.03k|	rdn = sc_asn1_skip_tag(ctx, &dn, &dn_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &rdn_len);
  ------------------
  |  |  206|  1.03k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              	rdn = sc_asn1_skip_tag(ctx, &dn, &dn_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &rdn_len);
  ------------------
  |  |  141|  1.03k|#define SC_ASN1_CONS			0x20000000
  ------------------
  166|  1.03k|	if (rdn == NULL)
  ------------------
  |  Branch (166:6): [True: 0, False: 1.03k]
  ------------------
  167|  1.03k|		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|  1.08k|	for (next_ava = rdn, next_ava_len = rdn_len; next_ava_len; ) {
  ------------------
  |  Branch (169:47): [True: 1.03k, False: 44]
  ------------------
  170|  1.03k|		const u8 *ava, *dummy, *oidp;
  171|  1.03k|		struct sc_object_id oid;
  172|  1.03k|		size_t ava_len = 0, dummy_len, oid_len = 0;
  173|       |
  174|       |		/* unwrap the set and point to the next ava */
  175|  1.03k|		ava = sc_asn1_skip_tag(ctx, &next_ava, &next_ava_len, SC_ASN1_TAG_SET | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  207|  1.03k|#define SC_ASN1_TAG_SET			17
  ------------------
              		ava = sc_asn1_skip_tag(ctx, &next_ava, &next_ava_len, SC_ASN1_TAG_SET | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  141|  1.03k|#define SC_ASN1_CONS			0x20000000
  ------------------
  176|  1.03k|		if (ava == NULL)
  ------------------
  |  Branch (176:7): [True: 368, False: 669]
  ------------------
  177|  1.03k|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  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: 368, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    368|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    368|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    368|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    368|		return _ret; \
  |  |  |  |  172|    368|	} \
  |  |  |  |  173|    368|} 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|    669|		dummy = ava; dummy_len = ava_len;
  189|    669|		ava = sc_asn1_skip_tag(ctx, &dummy, &dummy_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  206|    669|#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|    669|#define SC_ASN1_CONS			0x20000000
  ------------------
  190|    669|		if (ava == NULL)
  ------------------
  |  Branch (190:7): [True: 193, False: 476]
  ------------------
  191|    669|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|    193|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    193|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    193|	int _ret = (r); \
  |  |  |  |  168|    193|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 193, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    193|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    193|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    193|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    193|		return _ret; \
  |  |  |  |  172|    193|	} \
  |  |  |  |  173|    193|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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: 10, False: 466]
  ------------------
  196|    476|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA OID");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  197|       |
  198|       |		/* Convert to OID */
  199|    466|		rv = sc_asn1_decode_object_id(oidp, oid_len, &oid);
  200|    466|		if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    466|#define SC_SUCCESS				0
  ------------------
  |  Branch (200:7): [True: 377, False: 89]
  ------------------
  201|    466|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA OID");
  ------------------
  |  |  174|    377|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    377|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    377|	int _ret = (r); \
  |  |  |  |  168|    377|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 377, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    377|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    377|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    377|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    377|		return _ret; \
  |  |  |  |  172|    377|	} \
  |  |  |  |  173|    377|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|       |
  203|     89|		if (sc_compare_oid(&oid, type) == 0)
  ------------------
  |  Branch (203:7): [True: 44, False: 45]
  ------------------
  204|     44|			continue;
  205|       |
  206|       |		/* Yes, then return the name */
  207|     45|		dummy = sc_asn1_skip_tag(ctx, &ava, &ava_len, ava[0] & SC_ASN1_TAG_PRIMITIVE, &dummy_len);
  ------------------
  |  |  191|     45|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  208|     45|		if (dummy == NULL)
  ------------------
  |  Branch (208:7): [True: 31, False: 14]
  ------------------
  209|     45|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA name");
  ------------------
  |  |  174|     31|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     31|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     31|	int _ret = (r); \
  |  |  |  |  168|     31|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     31|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     31|		return _ret; \
  |  |  |  |  172|     31|	} \
  |  |  |  |  173|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|     14|		if (*name == NULL) {
  ------------------
  |  Branch (210:7): [True: 14, False: 0]
  ------------------
  211|     14|			*name = malloc(dummy_len);
  212|     14|			if (*name == NULL)
  ------------------
  |  Branch (212:8): [True: 0, False: 14]
  ------------------
  213|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|     14|			*name_len = dummy_len;
  215|     14|		}
  216|       |
  217|     14|		*name_len = MIN(dummy_len, *name_len);
  ------------------
  |  |   70|     14|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 14]
  |  |  ------------------
  ------------------
  218|     14|		memcpy(*name, dummy, *name_len);
  219|     14|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  157|     14|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|     14|	}
  221|       |
  222|     44|	LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  223|     44|}
sc_pkcs15_get_extension:
  248|  1.06k|{
  249|  1.06k|	const u8 *ext = NULL;
  250|  1.06k|	const u8 *next_ext = NULL;
  251|  1.06k|	size_t ext_len = 0;
  252|  1.06k|	size_t next_ext_len = 0;
  253|  1.06k|	struct sc_object_id oid;
  254|  1.06k|	u8 *val = NULL;
  255|  1.06k|	size_t val_len = 0;
  256|  1.06k|	int critical;
  257|  1.06k|	int r;
  258|  1.06k|	struct sc_asn1_entry asn1_cert_ext[] = {
  259|  1.06k|		{ "x509v3 entry OID", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, &oid, 0 },
  ------------------
  |  |  159|  1.06k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "x509v3 entry OID", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, &oid, 0 },
  ------------------
  |  |  200|  1.06k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  260|  1.06k|		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  153|  1.06k|#define SC_ASN1_BOOLEAN                 1
  ------------------
              		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  195|  1.06k|#define SC_ASN1_TAG_BOOLEAN		1
  ------------------
              		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  148|  1.06k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  261|  1.06k|		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  157|  1.06k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  198|  1.06k|#define SC_ASN1_TAG_OCTET_STRING	4
  ------------------
              		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  149|  1.06k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  262|  1.06k|		{ NULL, 0, 0, 0, NULL, NULL }
  263|  1.06k|	};
  264|       |
  265|  1.06k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.06k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.06k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.06k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.06k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.06k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|       |
  267|  1.06k|	for (next_ext = cert->extensions, next_ext_len = cert->extensions_len; next_ext_len; ) {
  ------------------
  |  Branch (267:73): [True: 0, False: 1.06k]
  ------------------
  268|       |		/* unwrap the set and point to the next ava */
  269|      0|		ext = sc_asn1_skip_tag(ctx, &next_ext, &next_ext_len,
  270|      0|			SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ext_len);
  ------------------
  |  |  206|      0|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              			SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ext_len);
  ------------------
  |  |  141|      0|#define SC_ASN1_CONS			0x20000000
  ------------------
  271|      0|		if (ext == NULL)
  ------------------
  |  Branch (271:7): [True: 0, False: 0]
  ------------------
  272|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|       |
  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|      0|		critical = 0;
  280|      0|		r = sc_asn1_decode(ctx, asn1_cert_ext, ext, ext_len, NULL, NULL);
  281|      0|		if (r < 0)
  ------------------
  |  Branch (281:7): [True: 0, False: 0]
  ------------------
  282|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  283|       |
  284|       |		/* is it the RN we are looking for */
  285|      0|		if (sc_compare_oid(&oid, type) != 0) {
  ------------------
  |  Branch (285:7): [True: 0, False: 0]
  ------------------
  286|      0|			if (*ext_val == NULL) {
  ------------------
  |  Branch (286:8): [True: 0, False: 0]
  ------------------
  287|      0|				*ext_val = val;
  288|      0|				val = NULL;
  289|      0|				*ext_val_len = val_len;
  290|       |				/* do not free here -- return the allocated value to caller */
  291|      0|			}
  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|      0|			if (is_critical)
  ------------------
  |  Branch (300:8): [True: 0, False: 0]
  ------------------
  301|      0|				*is_critical = critical;
  302|       |
  303|      0|			r = (int)val_len;
  304|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|      0|		}
  306|      0|		if (val) {
  ------------------
  |  Branch (306:7): [True: 0, False: 0]
  ------------------
  307|      0|			free(val);
  308|      0|			val = NULL;
  309|      0|		}
  310|      0|	}
  311|  1.06k|	if (val)
  ------------------
  |  Branch (311:6): [True: 0, False: 1.06k]
  ------------------
  312|      0|	    free(val);
  313|       |
  314|  1.06k|	LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  1.06k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.06k|	int _ret = r; \
  |  |  |  |  155|  1.06k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.06k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.06k|	return _ret; \
  |  |  |  |  163|  1.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|  1.06k|}
sc_pkcs15_get_bitstring_extension:
  325|  1.06k|{
  326|  1.06k|	int r;
  327|  1.06k|	u8 *bit_string = NULL;
  328|  1.06k|	size_t bit_string_len=0, val_len = sizeof(*value);
  329|  1.06k|	struct sc_asn1_entry asn1_bit_string[] = {
  330|  1.06k|		{ "bitString", SC_ASN1_BIT_FIELD, SC_ASN1_TAG_BIT_STRING, 0, value, &val_len },
  ------------------
  |  |  171|  1.06k|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
              		{ "bitString", SC_ASN1_BIT_FIELD, SC_ASN1_TAG_BIT_STRING, 0, value, &val_len },
  ------------------
  |  |  197|  1.06k|#define SC_ASN1_TAG_BIT_STRING		3
  ------------------
  331|  1.06k|		{ NULL, 0, 0, 0, NULL, NULL }
  332|  1.06k|	};
  333|       |
  334|  1.06k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.06k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.06k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.06k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.06k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.06k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|       |
  336|  1.06k|	r = sc_pkcs15_get_extension(ctx, cert, type, &bit_string, &bit_string_len, is_critical);
  337|  1.06k|	LOG_TEST_RET(ctx, r, "Get extension error");
  ------------------
  |  |  174|  1.06k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.06k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.06k|	int _ret = (r); \
  |  |  |  |  168|  1.06k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.06k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.06k|		return _ret; \
  |  |  |  |  172|  1.06k|	} \
  |  |  |  |  173|  1.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  338|       |
  339|      0|	r = sc_asn1_decode(ctx, asn1_bit_string, bit_string, bit_string_len, NULL, NULL);
  340|      0|	free(bit_string);
  341|      0|	LOG_TEST_RET(ctx, r, "Decoding extension bit string");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|       |
  343|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  344|      0|}
sc_pkcs15_pubkey_from_cert:
  350|     36|{
  351|     36|	int rv;
  352|     36|	struct sc_pkcs15_cert * cert;
  353|       |
  354|     36|	cert =  calloc(1, sizeof(struct sc_pkcs15_cert));
  355|     36|	if (cert == NULL)
  ------------------
  |  Branch (355:6): [True: 0, False: 36]
  ------------------
  356|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  357|       |
  358|     36|	rv = parse_x509_cert(ctx, cert_blob, cert);
  359|       |
  360|     36|	*out = cert->key;
  361|     36|	cert->key = NULL;
  362|     36|	sc_pkcs15_free_certificate(cert);
  363|       |
  364|     36|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     36|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     36|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     36|	int _ret = r; \
  |  |  |  |  155|     36|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  157|     36|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     36|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     36|	return _ret; \
  |  |  |  |  163|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  365|     36|}
sc_pkcs15_read_certificate:
  371|  5.04k|{
  372|  5.04k|	struct sc_context *ctx = NULL;
  373|  5.04k|	struct sc_pkcs15_cert *cert = NULL;
  374|  5.04k|	struct sc_pkcs15_der der;
  375|  5.04k|	int r;
  376|       |
  377|  5.04k|	if (p15card == NULL || info == NULL || cert_out == NULL) {
  ------------------
  |  Branch (377:6): [True: 0, False: 5.04k]
  |  Branch (377:25): [True: 0, False: 5.04k]
  |  Branch (377:41): [True: 0, False: 5.04k]
  ------------------
  378|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  379|      0|	}
  380|  5.04k|	ctx = p15card->card->ctx;
  381|  5.04k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.04k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.04k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|  5.04k|	if (info->value.len && info->value.value)   {
  ------------------
  |  Branch (383:6): [True: 3.14k, False: 1.89k]
  |  Branch (383:25): [True: 3.14k, False: 0]
  ------------------
  384|  3.14k|		sc_der_copy(&der, &info->value);
  385|  3.14k|	}
  386|  1.89k|	else if (info->path.len) {
  ------------------
  |  Branch (386:11): [True: 1.74k, False: 148]
  ------------------
  387|  1.74k|		r = sc_pkcs15_read_file(p15card, &info->path, &der.value, &der.len, private_obj);
  388|  1.74k|		LOG_TEST_RET(ctx, r, "Unable to read certificate file.");
  ------------------
  |  |  174|  1.74k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.74k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.74k|	int _ret = (r); \
  |  |  |  |  168|  1.74k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.20k, False: 542]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.20k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.20k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.20k|		return _ret; \
  |  |  |  |  172|  1.20k|	} \
  |  |  |  |  173|  1.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 542]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  389|  1.74k|	}
  390|    148|	else   {
  391|    148|		LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|    148|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    148|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    148|	int _ret = r; \
  |  |  |  |  155|    148|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 148, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    148|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    148|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 148, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    148|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    148|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    148|	return _ret; \
  |  |  |  |  163|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|    148|	}
  393|       |
  394|  3.69k|	cert = malloc(sizeof(struct sc_pkcs15_cert));
  395|  3.69k|	if (cert == NULL) {
  ------------------
  |  Branch (395:6): [True: 0, False: 3.69k]
  ------------------
  396|      0|		free(der.value);
  397|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|      0|	}
  399|  3.69k|	memset(cert, 0, sizeof(struct sc_pkcs15_cert));
  400|  3.69k|	if (parse_x509_cert(ctx, &der, cert)) {
  ------------------
  |  Branch (400:6): [True: 1.55k, False: 2.13k]
  ------------------
  401|  1.55k|		free(der.value);
  402|  1.55k|		sc_pkcs15_free_certificate(cert);
  403|  1.55k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  404|  1.55k|	}
  405|  2.13k|	free(der.value);
  406|       |
  407|  2.13k|	*cert_out = cert;
  408|  2.13k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.13k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.13k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.13k|	int _ret = r; \
  |  |  |  |  155|  2.13k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.13k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.13k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.13k|	return _ret; \
  |  |  |  |  163|  2.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  409|  2.13k|}
sc_pkcs15_decode_cdf_entry:
  446|      3|{
  447|      3|	sc_context_t *ctx = p15card->card->ctx;
  448|      3|	struct sc_pkcs15_cert_info info;
  449|      3|	struct sc_asn1_entry	asn1_cred_ident[3], asn1_com_cert_attr[4],
  450|      3|				asn1_x509_cert_attr[2], asn1_type_cert_attr[2],
  451|      3|				asn1_cert[2], asn1_x509_cert_value_choice[3];
  452|      3|	struct sc_asn1_pkcs15_object cert_obj = {
  453|      3|		obj, asn1_com_cert_attr, NULL,
  454|      3|		asn1_type_cert_attr };
  455|      3|	sc_pkcs15_der_t *der = &info.value;
  456|      3|	u8 id_value[128];
  457|      3|	int id_type;
  458|      3|	size_t id_value_len = sizeof(id_value);
  459|      3|	int r;
  460|       |
  461|      3|	sc_copy_asn1_entry(c_asn1_cred_ident, asn1_cred_ident);
  462|      3|	sc_copy_asn1_entry(c_asn1_com_cert_attr, asn1_com_cert_attr);
  463|      3|	sc_copy_asn1_entry(c_asn1_x509_cert_attr, asn1_x509_cert_attr);
  464|      3|	sc_copy_asn1_entry(c_asn1_x509_cert_value_choice, asn1_x509_cert_value_choice);
  465|      3|	sc_copy_asn1_entry(c_asn1_type_cert_attr, asn1_type_cert_attr);
  466|      3|	sc_copy_asn1_entry(c_asn1_cert, asn1_cert);
  467|       |
  468|      3|	sc_format_asn1_entry(asn1_cred_ident + 0, &id_type, NULL, 0);
  469|      3|	sc_format_asn1_entry(asn1_cred_ident + 1, &id_value, &id_value_len, 0);
  470|      3|	sc_format_asn1_entry(asn1_com_cert_attr + 0, &info.id, NULL, 0);
  471|      3|	sc_format_asn1_entry(asn1_com_cert_attr + 1, &info.authority, NULL, 0);
  472|      3|	sc_format_asn1_entry(asn1_com_cert_attr + 2, asn1_cred_ident, NULL, 0);
  473|      3|	sc_format_asn1_entry(asn1_x509_cert_attr + 0, asn1_x509_cert_value_choice, NULL, 0);
  474|      3|	sc_format_asn1_entry(asn1_x509_cert_value_choice + 0, &info.path, NULL, 0);
  475|      3|	sc_format_asn1_entry(asn1_x509_cert_value_choice + 1, &der->value, &der->len, 0);
  476|      3|	sc_format_asn1_entry(asn1_type_cert_attr + 0, asn1_x509_cert_attr, NULL, 0);
  477|      3|	sc_format_asn1_entry(asn1_cert + 0, &cert_obj, NULL, 0);
  478|       |
  479|       |	/* Fill in defaults */
  480|      3|	memset(&info, 0, sizeof(info));
  481|      3|	info.authority = 0;
  482|       |
  483|      3|	r = sc_asn1_decode(ctx, asn1_cert, *buf, *buflen, buf, buflen);
  484|       |	/* In case of error, trash the cert value (direct coding) */
  485|      3|	if (r < 0 && der->value)
  ------------------
  |  Branch (485:6): [True: 3, False: 0]
  |  Branch (485:15): [True: 0, False: 3]
  ------------------
  486|      0|		free(der->value);
  487|      3|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      3|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (487:6): [True: 1, False: 2]
  ------------------
  488|      1|		return r;
  489|      2|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|       |
  491|      0|	if (!p15card->app || !p15card->app->ddo.aid.len) {
  ------------------
  |  Branch (491:6): [True: 0, False: 0]
  |  Branch (491:23): [True: 0, False: 0]
  ------------------
  492|      0|		if (!p15card->file_app) {
  ------------------
  |  Branch (492:7): [True: 0, False: 0]
  ------------------
  493|      0|			free(der->value);
  494|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  495|      0|		}
  496|      0|		r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path);
  497|      0|		LOG_TEST_RET(ctx, r, "Cannot make absolute path");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  498|      0|	}
  499|      0|	else   {
  500|      0|		info.path.aid = p15card->app->ddo.aid;
  501|      0|	}
  502|      0|	sc_log(ctx, "Certificate path '%s'", sc_print_path(&info.path));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|       |
  504|      0|	switch (p15card->opts.pin_protected_certificate) {
  ------------------
  |  Branch (504:10): [True: 0, False: 0]
  ------------------
  505|      0|		case SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY:
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
  |  Branch (505:3): [True: 0, False: 0]
  ------------------
  506|      0|			sc_log(ctx, "Declassifying certificate");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  507|      0|			obj->flags &= ~SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  508|      0|			break;
  509|      0|		case SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE:
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
  |  Branch (509:3): [True: 0, False: 0]
  ------------------
  510|      0|			sc_log(ctx, "Ignoring certificate");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  511|      0|			free(der->value);
  512|      0|			return 0;
  513|      0|	}
  514|       |
  515|      0|	obj->type = SC_PKCS15_TYPE_CERT_X509;
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  516|      0|	obj->data = malloc(sizeof(info));
  517|      0|	if (obj->data == NULL)
  ------------------
  |  Branch (517:6): [True: 0, False: 0]
  ------------------
  518|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|      0|	memcpy(obj->data, &info, sizeof(info));
  520|       |
  521|      0|	return 0;
  522|      0|}
sc_pkcs15_free_certificate:
  645|  3.72k|{
  646|  3.72k|	if (cert == NULL) {
  ------------------
  |  Branch (646:6): [True: 0, False: 3.72k]
  ------------------
  647|      0|		return;
  648|      0|	}
  649|       |
  650|  3.72k|	sc_pkcs15_free_pubkey(cert->key);
  651|  3.72k|	free(cert->subject);
  652|  3.72k|	free(cert->issuer);
  653|  3.72k|	free(cert->serial);
  654|  3.72k|	free(cert->data.value);
  655|  3.72k|	free(cert->extensions);
  656|  3.72k|	free(cert);
  657|  3.72k|}
sc_pkcs15_free_cert_info:
  662|  2.52k|{
  663|  2.52k|	if (!cert)
  ------------------
  |  Branch (663:6): [True: 0, False: 2.52k]
  ------------------
  664|      0|		return;
  665|  2.52k|	free(cert->value.value);
  666|  2.52k|	free(cert);
  667|  2.52k|}
pkcs15-cert.c:parse_x509_cert:
   40|  3.72k|{
   41|  3.72k|	int r;
   42|  3.72k|	struct sc_algorithm_id sig_alg = {0};
   43|  3.72k|	struct sc_pkcs15_pubkey *pubkey = NULL;
   44|  3.72k|	unsigned char *serial = NULL, *issuer = NULL, *subject = NULL, *buf =  der->value;
   45|  3.72k|	size_t serial_len = 0, issuer_len = 0, subject_len = 0, data_len = 0, buflen = der->len;
   46|  3.72k|	struct sc_asn1_entry asn1_version[] = {
   47|  3.72k|		{ "version", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, &cert->version, NULL },
  ------------------
  |  |  154|  3.72k|#define SC_ASN1_INTEGER                 2
  ------------------
              		{ "version", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, &cert->version, NULL },
  ------------------
  |  |  196|  3.72k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
   48|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   49|  3.72k|	};
   50|  3.72k|	struct sc_asn1_entry asn1_extensions[] = {
   51|  3.72k|		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  148|  3.72k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   52|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   53|  3.72k|	};
   54|  3.72k|	struct sc_asn1_entry asn1_tbscert[] = {
   55|  3.72k|		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  169|  3.72k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  139|  3.72k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  148|  3.72k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
   56|  3.72k|		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  196|  3.72k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
              		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   57|  3.72k|		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  169|  3.72k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
   58|  3.72k|		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   59|  3.72k|		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  169|  3.72k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
   60|  3.72k|		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   61|       |		/* Use a callback to get the algorithm, parameters and pubkey into sc_pkcs15_pubkey */
   62|  3.72k|		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  181|  3.72k|#define SC_ASN1_CALLBACK		384
  ------------------
              		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
   63|  3.72k|		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  169|  3.72k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  139|  3.72k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  148|  3.72k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
   64|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   65|  3.72k|	};
   66|  3.72k|	struct sc_asn1_entry asn1_cert[] = {
   67|  3.72k|		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  169|  3.72k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
   68|  3.72k|		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  177|  3.72k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
              		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
   69|  3.72k|		{ "signatureValue",	SC_ASN1_BIT_STRING, SC_ASN1_TAG_BIT_STRING, 0, NULL, NULL },
  ------------------
  |  |  155|  3.72k|#define SC_ASN1_BIT_STRING              3
  ------------------
              		{ "signatureValue",	SC_ASN1_BIT_STRING, SC_ASN1_TAG_BIT_STRING, 0, NULL, NULL },
  ------------------
  |  |  197|  3.72k|#define SC_ASN1_TAG_BIT_STRING		3
  ------------------
   70|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   71|  3.72k|	};
   72|  3.72k|	struct sc_asn1_entry asn1_serial_number[] = {
   73|  3.72k|		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  196|  3.72k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
              		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   74|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   75|  3.72k|	};
   76|  3.72k|	struct sc_asn1_entry asn1_subject[] = {
   77|  3.72k|		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   78|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   79|  3.72k|	};
   80|  3.72k|	struct sc_asn1_entry asn1_issuer[] = {
   81|  3.72k|		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  3.72k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.72k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   82|  3.72k|		{ NULL, 0, 0, 0, NULL, NULL }
   83|  3.72k|	};
   84|       |
   85|  3.72k|	const u8 *obj;
   86|  3.72k|	size_t objlen;
   87|       |
   88|  3.72k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.72k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.72k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.72k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.72k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.72k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|       |
   90|  3.72k|	memset(cert, 0, sizeof(*cert));
   91|  3.72k|	obj = sc_asn1_verify_tag(ctx, buf, buflen, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &objlen);
  ------------------
  |  |  206|  3.72k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              	obj = sc_asn1_verify_tag(ctx, buf, buflen, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &objlen);
  ------------------
  |  |  141|  3.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
   92|  3.72k|	if (obj == NULL)
  ------------------
  |  Branch (92:6): [True: 1.12k, False: 2.60k]
  ------------------
   93|  3.72k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "X.509 certificate not found");
  ------------------
  |  |  174|  1.12k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.12k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.12k|	int _ret = (r); \
  |  |  |  |  168|  1.12k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.12k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.12k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.12k|		return _ret; \
  |  |  |  |  172|  1.12k|	} \
  |  |  |  |  173|  1.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|       |
   95|  2.60k|	data_len = objlen + (obj - buf);
   96|  2.60k|	cert->data.value = malloc(data_len);
   97|  2.60k|	if (!cert->data.value)
  ------------------
  |  Branch (97:6): [True: 0, False: 2.60k]
  ------------------
   98|  2.60k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   99|  2.60k|	memcpy(cert->data.value, buf, data_len);
  100|  2.60k|	cert->data.len = data_len;
  101|       |
  102|  2.60k|	r = sc_asn1_decode(ctx, asn1_cert, obj, objlen, NULL, NULL);
  103|  2.60k|	cert->key = pubkey;
  104|  2.60k|	cert->version++;
  105|       |
  106|  2.60k|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of certificate failed");
  ------------------
  |  |  184|  2.60k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.60k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.60k|	int _ret = (r); \
  |  |  |  |  178|  2.60k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 430, False: 2.17k]
  |  |  |  |  ------------------
  |  |  |  |  179|    430|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    430|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    430|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    430|		goto err; \
  |  |  |  |  182|    430|	} \
  |  |  |  |  183|  2.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|       |
  108|  2.17k|	if (!pubkey)
  ------------------
  |  Branch (108:6): [True: 12, False: 2.16k]
  ------------------
  109|  2.17k|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "Unable to decode subjectPublicKeyInfo from cert");
  ------------------
  |  |  184|     12|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     12|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     12|	int _ret = (r); \
  |  |  |  |  178|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     12|		goto err; \
  |  |  |  |  182|     12|	} \
  |  |  |  |  183|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  110|       |
  111|       |
  112|  2.16k|	if (serial && serial_len)   {
  ------------------
  |  Branch (112:6): [True: 2.16k, False: 0]
  |  Branch (112:16): [True: 2.16k, False: 0]
  ------------------
  113|  2.16k|		sc_format_asn1_entry(asn1_serial_number + 0, serial, &serial_len, 1);
  114|  2.16k|		r = sc_asn1_encode(ctx, asn1_serial_number, &cert->serial, &cert->serial_len);
  115|  2.16k|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of serial failed");
  ------------------
  |  |  184|  2.16k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.16k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.16k|	int _ret = (r); \
  |  |  |  |  178|  2.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.16k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.16k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  116|  2.16k|	}
  117|       |
  118|  2.16k|	if (subject && subject_len)   {
  ------------------
  |  Branch (118:6): [True: 2.16k, False: 0]
  |  Branch (118:17): [True: 2.16k, False: 0]
  ------------------
  119|  2.16k|		sc_format_asn1_entry(asn1_subject + 0, subject, &subject_len, 1);
  120|  2.16k|		r = sc_asn1_encode(ctx, asn1_subject, &cert->subject, &cert->subject_len);
  121|  2.16k|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of subject");
  ------------------
  |  |  184|  2.16k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.16k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.16k|	int _ret = (r); \
  |  |  |  |  178|  2.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.16k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.16k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|  2.16k|	}
  123|       |
  124|  2.16k|	if (issuer && issuer_len)   {
  ------------------
  |  Branch (124:6): [True: 2.07k, False: 85]
  |  Branch (124:16): [True: 2.07k, False: 0]
  ------------------
  125|  2.07k|		sc_format_asn1_entry(asn1_issuer + 0, issuer, &issuer_len, 1);
  126|  2.07k|		r = sc_asn1_encode(ctx, asn1_issuer, &cert->issuer, &cert->issuer_len);
  127|  2.07k|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of issuer");
  ------------------
  |  |  184|  2.07k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.07k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.07k|	int _ret = (r); \
  |  |  |  |  178|  2.07k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.07k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|  2.07k|	}
  129|       |
  130|  2.60k|err:
  131|       |	/* not used for anything */
  132|  2.60k|	sc_asn1_clear_algorithm_id(&sig_alg);
  133|  2.60k|	free(serial);
  134|  2.60k|	free(subject);
  135|  2.60k|	free(issuer);
  136|       |
  137|  2.60k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  2.60k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.60k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.60k|	int _ret = r; \
  |  |  |  |  155|  2.60k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.60k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.60k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    430|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 430, False: 2.17k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.60k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.60k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.60k|	return _ret; \
  |  |  |  |  163|  2.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|  2.60k|}

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

sc_pkcs15_read_data_object:
   46|    348|{
   47|    348|	struct sc_context *ctx = p15card->card->ctx;
   48|    348|	struct sc_pkcs15_data *data_object;
   49|    348|	struct sc_pkcs15_der der;
   50|    348|	int r;
   51|       |
   52|    348|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    348|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    348|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    348|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    348|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 348]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|    348|	if (!info || !data_object_out)
  ------------------
  |  Branch (53:6): [True: 0, False: 348]
  |  Branch (53:15): [True: 0, False: 348]
  ------------------
   54|    348|		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|    348|	if (!info->data.value)   {
  ------------------
  |  Branch (56:6): [True: 348, False: 0]
  ------------------
   57|    348|		r = sc_pkcs15_read_file(p15card, &info->path, (unsigned char **) &info->data.value, (size_t *) &info->data.len, private_obj);
   58|    348|		LOG_TEST_RET(ctx, r, "Cannot get DATA object data");
  ------------------
  |  |  174|    348|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    348|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    348|	int _ret = (r); \
  |  |  |  |  168|    348|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 309]
  |  |  |  |  ------------------
  |  |  |  |  169|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     39|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     39|		return _ret; \
  |  |  |  |  172|     39|	} \
  |  |  |  |  173|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 309]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|    348|	}
   60|       |
   61|    309|	r = sc_der_copy(&der, &info->data);
   62|    309|	LOG_TEST_RET(ctx, r, "Cannot allocate memory for der value");
  ------------------
  |  |  174|    309|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    309|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    309|	int _ret = (r); \
  |  |  |  |  168|    309|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 309]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    309|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 309]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|       |
   64|    309|	data_object = calloc(1, sizeof(struct sc_pkcs15_data));
   65|    309|	if (!data_object)   {
  ------------------
  |  Branch (65:6): [True: 0, False: 309]
  ------------------
   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|    309|	data_object->data = der.value;
   71|    309|	data_object->data_len = der.len;
   72|    309|	*data_object_out = data_object;
   73|       |
   74|    309|	LOG_FUNC_RETURN(ctx,SC_SUCCESS);
  ------------------
  |  |  164|    309|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    309|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    309|	int _ret = r; \
  |  |  |  |  155|    309|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 309, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    309|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 309]
  |  |  |  |  ------------------
  |  |  |  |  157|    309|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    309|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    309|	return _ret; \
  |  |  |  |  163|    309|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|    309|}
sc_pkcs15_decode_dodf_entry:
   95|      2|{
   96|      2|        sc_context_t *ctx = p15card->card->ctx;
   97|      2|	struct sc_pkcs15_data_info info;
   98|      2|	struct sc_asn1_entry	asn1_com_data_attr[3],
   99|      2|				asn1_type_data_attr[2],
  100|      2|				asn1_data[2];
  101|      2|	struct sc_asn1_pkcs15_object data_obj = { obj, asn1_com_data_attr, NULL,
  102|      2|					     asn1_type_data_attr };
  103|      2|	size_t label_len = sizeof(info.app_label) - 1;
  104|      2|	int r;
  105|       |
  106|      2|	memset(info.app_label, 0, sizeof(info.app_label));
  107|       |
  108|      2|	sc_copy_asn1_entry(c_asn1_com_data_attr, asn1_com_data_attr);
  109|      2|	sc_copy_asn1_entry(c_asn1_type_data_attr, asn1_type_data_attr);
  110|      2|	sc_copy_asn1_entry(c_asn1_data, asn1_data);
  111|       |
  112|      2|	sc_format_asn1_entry(asn1_com_data_attr + 0, &info.app_label, &label_len, 0);
  113|      2|	sc_format_asn1_entry(asn1_com_data_attr + 1, &info.app_oid, NULL, 0);
  114|      2|	sc_format_asn1_entry(asn1_type_data_attr + 0, &info.path, NULL, 0);
  115|      2|	sc_format_asn1_entry(asn1_data + 0, &data_obj, NULL, 0);
  116|       |
  117|       |	/* Fill in defaults */
  118|      2|	memset(&info, 0, sizeof(info));
  119|      2|	sc_init_oid(&info.app_oid);
  120|       |
  121|      2|	r = sc_asn1_decode(ctx, asn1_data, *buf, *buflen, buf, buflen);
  122|      2|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      2|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (122:6): [True: 1, False: 1]
  ------------------
  123|      1|		return r;
  124|      1|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    309|{
  181|    309|	if (data_object == NULL)
  ------------------
  |  Branch (181:6): [True: 0, False: 309]
  ------------------
  182|      0|		return;
  183|       |
  184|    309|	free(data_object->data);
  185|    309|	free(data_object);
  186|    309|}
sc_pkcs15_free_data_info:
  189|  23.0k|{
  190|  23.0k|	if (info && info->data.value && info->data.len)
  ------------------
  |  Branch (190:6): [True: 23.0k, False: 0]
  |  Branch (190:14): [True: 0, False: 23.0k]
  |  Branch (190:34): [True: 0, False: 0]
  ------------------
  191|      0|		free(info->data.value);
  192|       |
  193|  23.0k|	free(info);
  194|  23.0k|}

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

sc_pkcs15emu_dnie_init_ex:
  281|  12.0k|{
  282|  12.0k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  12.0k|#define SC_SUCCESS				0
  ------------------
  283|  12.0k|	sc_context_t *ctx = p15card->card->ctx;
  284|  12.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|  12.0k|#if defined(ENABLE_OPENSSL) && defined(ENABLE_SM)
  287|       |	/* check for proper card */
  288|  12.0k|	r = dnie_match_card(p15card->card);
  289|  12.0k|	if (r == 0)
  ------------------
  |  Branch (289:6): [True: 11.3k, False: 704]
  ------------------
  290|  12.0k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  11.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.3k|	int _ret = r; \
  |  |  |  |  155|  11.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.3k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.3k|	return _ret; \
  |  |  |  |  163|  11.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |	/* ok: initialize and return */
  292|    704|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_dnie_init(p15card));
  ------------------
  |  |  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|    704|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 704, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|       |#else
  294|       |	r = SC_ERROR_WRONG_CARD;
  295|       |	LOG_FUNC_RETURN(ctx, r);
  296|       |#endif
  297|    704|}
pkcs15-dnie.c:sc_pkcs15emu_dnie_init:
  139|    704|{
  140|    704|	u8 buf[1024];
  141|    704|	sc_pkcs15_df_t *df;
  142|    704|	sc_pkcs15_object_t *p15_obj;
  143|    704|	size_t len = sizeof(buf);
  144|    704|	int rv;
  145|    704|	struct sc_pkcs15_cert_info *p15_info = NULL;
  146|    704|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  147|       |
  148|    704|	sc_context_t *ctx = p15card->card->ctx;
  149|    704|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    704|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|       |	/* Check for correct card driver (i.e. iso7816) */
  152|    704|	if (strcmp(p15card->card->driver->short_name, "dnie") != 0)
  ------------------
  |  Branch (152:6): [True: 5, False: 699]
  ------------------
  153|      5|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      5|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  154|       |
  155|       |	/* Check for correct card atr */
  156|    699|	if (dnie_match_card(p15card->card) != 1)
  ------------------
  |  Branch (156:6): [True: 0, False: 699]
  ------------------
  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|    699|	if (p15card->card->atr.value[15] >= DNIE_30_VERSION) {
  ------------------
  |  |  100|    699|#define DNIE_30_VERSION 0x04
  ------------------
  |  Branch (162:6): [True: 587, False: 112]
  ------------------
  163|    587|		p15card->opts.use_pin_cache = 1;
  164|    587|		p15card->opts.pin_cache_counter = DNIE_30_CACHE_COUNTER;
  ------------------
  |  |  101|    587|#define DNIE_30_CACHE_COUNTER 30000
  ------------------
  165|    587|		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|    587|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  166|    587|			p15card->opts.use_file_cache,
  167|    587|			p15card->opts.use_pin_cache,
  168|    587|			p15card->opts.pin_cache_counter,
  169|    587|			p15card->opts.pin_cache_ignore_user_consent);
  170|    587|        }
  171|       |
  172|       |	/* Set root path of this application */
  173|    699|	sc_file_free(p15card->file_app);
  174|    699|	p15card->file_app = sc_file_new();
  175|    699|	if (NULL == p15card->file_app) {
  ------------------
  |  Branch (175:6): [True: 0, False: 699]
  ------------------
  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|    699|	sc_format_path("3F00", &p15card->file_app->path);
  180|       |
  181|       |	/* Load TokenInfo */
  182|    699|	rv = dump_ef(p15card->card, "3F0050155032", buf, &len);
  183|    699|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    699|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    699|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    699|	int _ret = (r); \
  |  |  |  |  178|    699|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 662, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  179|    662|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    662|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    662|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    662|		goto err; \
  |  |  |  |  182|    662|	} \
  |  |  |  |  183|    699|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|     37|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  186|     37|				       buf, len);
  187|     37|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of EF.TOKENINFO failed.");
  ------------------
  |  |  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: 36, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  179|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     36|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     36|		goto err; \
  |  |  |  |  182|     36|	} \
  |  |  |  |  183|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* Only accept the original stuff */
  190|      1|	if (strcmp(p15card->tokeninfo->manufacturer_id, "DGP-FNMT") != 0) {
  ------------------
  |  Branch (190:6): [True: 1, False: 0]
  ------------------
  191|      1|		rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      1|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  192|      1|		LOG_TEST_GOTO_ERR(ctx, rv, "Wrong card.");
  ------------------
  |  |  184|      1|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      1|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      1|	int _ret = (r); \
  |  |  |  |  178|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      1|		goto err; \
  |  |  |  |  182|      1|	} \
  |  |  |  |  183|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|      1|	}
  194|       |
  195|       |	/* Load ODF */
  196|      0|	rv = dump_ef(p15card->card, "3F0050155031", buf, &len);
  197|      0|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of ODF failed.");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|      0|	rv = parse_odf(buf, len, p15card);
  200|      0|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of ODF failed.");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|       |	/* Decode EF.PrKDF, EF.PuKDF and EF.CDF */
  203|      0|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (203:30): [True: 0, False: 0]
  ------------------
  204|      0|		if (df->type == SC_PKCS15_PRKDF) {
  ------------------
  |  |  488|      0|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (204:7): [True: 0, False: 0]
  ------------------
  205|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  206|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (206:8): [True: 0, False: 0]
  ------------------
  207|      0|				sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  208|      0|				       "Decoding of EF.PrKDF (%s) failed: %d",
  209|      0|				       sc_print_path(&df->path), rv);
  210|      0|			}
  211|      0|		}
  212|      0|		if (df->type == SC_PKCS15_PUKDF) {
  ------------------
  |  |  489|      0|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (212:7): [True: 0, False: 0]
  ------------------
  213|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  214|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (214:8): [True: 0, False: 0]
  ------------------
  215|      0|				sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  216|      0|				       "Decoding of EF.PuKDF (%s) failed: %d",
  217|      0|				       sc_print_path(&df->path), rv);
  218|      0|			}
  219|      0|		}
  220|      0|		if (df->type == SC_PKCS15_CDF) {
  ------------------
  |  |  492|      0|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (220:7): [True: 0, False: 0]
  ------------------
  221|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  222|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:8): [True: 0, False: 0]
  ------------------
  223|      0|				sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  224|      0|				       "Decoding of EF.CDF (%s) failed: %d",
  225|      0|				       sc_print_path(&df->path), rv);
  226|      0|			}
  227|      0|		}
  228|      0|		if (df->type == SC_PKCS15_DODF) {
  ------------------
  |  |  495|      0|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (228:7): [True: 0, False: 0]
  ------------------
  229|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  230|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (230:8): [True: 0, False: 0]
  ------------------
  231|      0|				sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  232|      0|				       "Decoding of EF.DODF (%s) failed: %d",
  233|      0|				       sc_print_path(&df->path), rv);
  234|      0|			}
  235|      0|		}
  236|      0|	}
  237|       |
  238|       |	/* Perform required fixes */
  239|      0|	p15_obj = p15card->obj_list;
  240|      0|	while (p15_obj != NULL) {
  ------------------
  |  Branch (240:9): [True: 0, False: 0]
  ------------------
  241|       |		/* Add missing 'auth_id' to private objects */
  242|      0|		if ((p15_obj->flags & SC_PKCS15_CO_FLAG_PRIVATE)
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (242:7): [True: 0, False: 0]
  ------------------
  243|      0|		    && (p15_obj->auth_id.len == 0)) {
  ------------------
  |  Branch (243:10): [True: 0, False: 0]
  ------------------
  244|      0|			p15_obj->auth_id.value[0] = 0x01;
  245|      0|			p15_obj->auth_id.len = 1;
  246|      0|		};
  247|       |		/* Set path count to -1 for public certificates, as they
  248|       |		   will need to be decompressed and read_binary()'d, so
  249|       |		   we make sure we end up reading the file->size and not the
  250|       |		   path->count which is the compressed size on newer
  251|       |                   DNIe versions  */
  252|      0|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_CDF) ) {
  ------------------
  |  |  492|      0|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (252:8): [True: 0, False: 0]
  |  Branch (252:23): [True: 0, False: 0]
  ------------------
  253|      0|                    p15_info = (struct sc_pkcs15_cert_info *) p15_obj ->data;
  254|      0|		    p15_info ->path.count = -1;
  255|      0|		}
  256|       |		/* Remove found public keys as cannot be read_binary()'d */
  257|      0|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_PUKDF) ) {
  ------------------
  |  |  489|      0|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (257:8): [True: 0, False: 0]
  |  Branch (257:23): [True: 0, False: 0]
  ------------------
  258|      0|			sc_pkcs15_object_t *puk = p15_obj;
  259|      0|			p15_obj = p15_obj->next;
  260|      0|			sc_pkcs15_remove_object(p15card, puk);
  261|      0|			sc_pkcs15_free_object(puk);
  262|      0|                } else {
  263|      0|			p15_obj = p15_obj->next;
  264|      0|		}
  265|      0|	}
  266|       |	
  267|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|    699|err:
  270|    699|	sc_pkcs15_card_clear(p15card);
  271|    699|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  272|    699|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    699|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    699|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    699|	int _ret = r; \
  |  |  |  |  155|    699|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 699, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    699|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    699|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 699, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    699|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    699|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    699|	return _ret; \
  |  |  |  |  163|    699|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|    699|}
pkcs15-dnie.c:dump_ef:
   42|    699|{
   43|    699|	int rv;
   44|    699|	sc_file_t *file = NULL;
   45|    699|	sc_path_t scpath;
   46|    699|	sc_format_path(path, &scpath);
   47|    699|	rv = sc_select_file(card, &scpath, &file);
   48|    699|	if (rv < 0) {
  ------------------
  |  Branch (48:6): [True: 632, False: 67]
  ------------------
   49|    632|		sc_file_free(file);
   50|    632|		return rv;
   51|    632|	}
   52|     67|	if (file->size > *buf_len) {
  ------------------
  |  Branch (52:6): [True: 27, False: 40]
  ------------------
   53|     27|		sc_file_free(file);
   54|     27|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     27|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   55|     27|	}
   56|     40|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   57|     40|	sc_file_free(file);
   58|     40|	if (rv < 0)
  ------------------
  |  Branch (58:6): [True: 3, False: 37]
  ------------------
   59|      3|		return rv;
   60|     37|	*buf_len = rv;
   61|       |
   62|     37|	return SC_SUCCESS;
  ------------------
  |  |   28|     37|#define SC_SUCCESS				0
  ------------------
   63|     40|}

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

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

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

sc_pkcs15emu_esteid2018_init_ex:
  256|  9.66k|int sc_pkcs15emu_esteid2018_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid) {
  257|  9.66k|	if (p15card->card->type == SC_CARD_TYPE_ESTEID_2018 ||
  ------------------
  |  Branch (257:6): [True: 0, False: 9.66k]
  ------------------
  258|  9.66k|			p15card->card->type == SC_CARD_TYPE_ESTEID_2018_V2_2025 ||
  ------------------
  |  Branch (258:4): [True: 0, False: 9.66k]
  ------------------
  259|  9.66k|			is_latvian_eid(p15card))
  ------------------
  |  Branch (259:4): [True: 0, False: 9.66k]
  ------------------
  260|      0|		return sc_pkcs15emu_esteid2018_init(p15card);
  261|  9.66k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.66k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  262|  9.66k|}
pkcs15-esteid2018.c:is_latvian_eid:
   38|  9.66k|{
   39|  9.66k|	return p15card->card->type == SC_CARD_TYPE_LATEID_2018 ||
  ------------------
  |  Branch (39:9): [True: 0, False: 9.66k]
  ------------------
   40|  9.66k|	       p15card->card->type == SC_CARD_TYPE_LATEID_2018_V2_2025;
  ------------------
  |  Branch (40:9): [True: 0, False: 9.66k]
  ------------------
   41|  9.66k|}

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

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

sc_pkcs15emu_gids_init_ex:
  241|  12.0k|{
  242|  12.0k|	if (p15card->card->type != SC_CARD_TYPE_GIDS_GENERIC && p15card->card->type != SC_CARD_TYPE_GIDS_V1 && p15card->card->type != SC_CARD_TYPE_GIDS_V2) {
  ------------------
  |  Branch (242:6): [True: 12.0k, False: 86]
  |  Branch (242:58): [True: 11.9k, False: 1]
  |  Branch (242:105): [True: 11.9k, False: 1]
  ------------------
  243|  11.9k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.9k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  244|  11.9k|	}
  245|     88|	return sc_pkcs15emu_gids_init(p15card);
  246|  12.0k|}
pkcs15-gids.c:sc_pkcs15emu_gids_init:
  112|     88|{
  113|     88|	sc_card_t *card = p15card->card;
  114|     88|	int r;
  115|     88|	size_t i;
  116|     88|	struct sc_pkcs15_auth_info pin_info;
  117|     88|	struct sc_pkcs15_object pin_obj;
  118|     88|	struct sc_pin_cmd_data pin_cmd_data;
  119|     88|	size_t recordsnum;
  120|     88|	int has_puk;
  121|       |
  122|     88|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  123|     88|	LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 88, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     88|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     88|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     88|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     88|		return _ret; \
  |  |  |  |  172|     88|	} \
  |  |  |  |  173|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  12.0k|{
  269|  12.0k|	if (iasecc_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (269:6): [True: 11.2k, False: 746]
  ------------------
  270|  11.2k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  271|       |
  272|    746|	return sc_pkcs15emu_iasecc_init(p15card, aid);
  273|  12.0k|}
pkcs15-iasecc.c:iasecc_pkcs15emu_detect_card:
  239|  12.0k|{
  240|  12.0k|	if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
  ------------------
  |  Branch (240:6): [True: 8.64k, False: 3.37k]
  ------------------
  241|  8.64k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.64k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  242|       |
  243|  3.37k|	if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
  ------------------
  |  Branch (243:6): [True: 2.63k, False: 746]
  ------------------
  244|  2.63k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  2.63k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  245|       |
  246|    746|	return SC_SUCCESS;
  ------------------
  |  |   28|    746|#define SC_SUCCESS				0
  ------------------
  247|  3.37k|}
pkcs15-iasecc.c:sc_pkcs15emu_iasecc_init:
  252|    746|{
  253|    746|	struct sc_context *ctx = p15card->card->ctx;
  254|    746|	int rv;
  255|       |
  256|    746|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|       |
  258|    746|	rv = sc_pkcs15_bind_internal(p15card, aid);
  259|       |
  260|    746|	p15card->ops.parse_df = _iasecc_parse_df;
  261|       |
  262|    746|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|    742|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 742, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|    746|}

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

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

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

sc_pkcs15emu_oberthur_init_ex:
 1160|  12.1k|{
 1161|  12.1k|	int rv;
 1162|       |
 1163|  12.1k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  12.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|  12.1k|	rv = oberthur_detect_card(p15card);
 1165|  12.1k|	if (!rv)
  ------------------
  |  Branch (1165:6): [True: 803, False: 11.3k]
  ------------------
 1166|    803|		rv = sc_pkcs15emu_oberthur_init(p15card);
 1167|       |
 1168|  12.1k|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|  12.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.1k|	int _ret = r; \
  |  |  |  |  155|  12.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.0k, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.1k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.1k|	return _ret; \
  |  |  |  |  163|  12.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|  12.1k|}
pkcs15-oberthur.c:oberthur_detect_card:
 1148|  12.1k|{
 1149|  12.1k|	struct sc_card *card = p15card->card;
 1150|       |
 1151|  12.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  12.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  12.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  12.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12.1k]
  |  |  ------------------
  ------------------
 1152|  12.1k|	if (p15card->card->type != SC_CARD_TYPE_OBERTHUR_64K)
  ------------------
  |  Branch (1152:6): [True: 11.3k, False: 803]
  ------------------
 1153|  12.1k|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  11.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.3k|	int _ret = r; \
  |  |  |  |  155|  11.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.3k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.3k|	return _ret; \
  |  |  |  |  163|  11.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1154|    803|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    803|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    803|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    803|	int _ret = r; \
  |  |  |  |  155|    803|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 803, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    803|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 803]
  |  |  |  |  ------------------
  |  |  |  |  157|    803|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    803|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    803|	return _ret; \
  |  |  |  |  163|    803|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1155|    803|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_init:
 1015|    803|{
 1016|    803|	struct sc_context *ctx = p15card->card->ctx;
 1017|    803|	struct sc_pkcs15_auth_info auth_info;
 1018|    803|	struct sc_pkcs15_object   obj;
 1019|    803|	struct sc_card *card = p15card->card;
 1020|    803|	struct sc_path path;
 1021|    803|	int rv, ii, tries_left;
 1022|    803|	char serial[0x10];
 1023|    803|	unsigned char sopin_reference = 0x04;
 1024|       |
 1025|    803|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    803|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    803|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    803|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 803]
  |  |  ------------------
  ------------------
 1026|    803|	sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial, sizeof(serial), 0);
 1027|    803|	set_string(&p15card->tokeninfo->serial_number, serial);
 1028|       |
 1029|    803|	p15card->ops.parse_df = sc_awp_parse_df;
 1030|    803|	p15card->ops.clear = sc_awp_clear;
 1031|       |
 1032|    803|	sc_log(ctx, "Oberthur init: serial %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   71|    803|#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|    803|	sc_format_path(AWP_PIN_DF, &path);
  ------------------
  |  |   69|    803|#define AWP_PIN_DF		"3F005011"
  ------------------
 1035|    803|	rv = sc_select_file(card, &path, NULL);
 1036|    803|	LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot select PIN dir");
  ------------------
  |  |  184|    803|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    803|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    803|	int _ret = (r); \
  |  |  |  |  178|    803|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 360, False: 443]
  |  |  |  |  ------------------
  |  |  |  |  179|    360|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    360|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    360|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    360|		goto err; \
  |  |  |  |  182|    360|	} \
  |  |  |  |  183|    803|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 443]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1037|       |
 1038|    443|	tries_left = -1;
 1039|    443|	rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|    443|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1040|    443|	if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)   {
  ------------------
  |  |   64|     71|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1040:6): [True: 71, False: 372]
  |  Branch (1040:12): [True: 59, False: 12]
  ------------------
 1041|     59|		sopin_reference = 0x84;
 1042|     59|		rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|     59|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1043|     59|	}
 1044|    443|	if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|     58|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1044:6): [True: 58, False: 385]
  |  Branch (1044:12): [True: 41, False: 17]
  ------------------
 1045|    443|		LOG_TEST_GOTO_ERR(ctx, rv, "Invalid state of SO-PIN");
  ------------------
  |  |  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: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     41|		goto err; \
  |  |  |  |  182|     41|	} \
  |  |  |  |  183|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1046|       |
 1047|       |	/* add PIN */
 1048|    402|	memset(&auth_info, 0, sizeof(auth_info));
 1049|    402|	memset(&obj,  0, sizeof(obj));
 1050|       |
 1051|    402|	auth_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    402|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
 1052|    402|	auth_info.auth_method	= SC_AC_CHV;
  ------------------
  |  |  151|    402|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1053|    402|	auth_info.auth_id.len = 1;
 1054|    402|	auth_info.auth_id.value[0] = 0xFF;
 1055|    402|	auth_info.attrs.pin.min_length		= 4;
 1056|    402|	auth_info.attrs.pin.max_length		= 64;
 1057|    402|	auth_info.attrs.pin.stored_length	= 64;
 1058|    402|	auth_info.attrs.pin.type		= SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    402|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
 1059|    402|	auth_info.attrs.pin.reference		= sopin_reference;
 1060|    402|	auth_info.attrs.pin.pad_char		= 0xFF;
 1061|    402|	auth_info.attrs.pin.flags		= SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
  ------------------
  |  |   54|    402|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
 1062|    402|				| SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|    402|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
 1063|    402|				| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
  ------------------
  |  |   59|    402|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
 1064|    402|				| SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   61|    402|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
 1065|    402|	auth_info.tries_left		= tries_left;
 1066|    402|	auth_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    402|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1067|       |
 1068|    402|	strncpy(obj.label, "SO PIN", SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|    402|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1069|    402|	obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    402|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              	obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    402|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1070|       |
 1071|    402|	sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
  ------------------
  |  |   71|    402|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1072|    402|			sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
 1073|    402|	rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
 1074|    402|	LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot add PIN object");
  ------------------
  |  |  184|    402|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    402|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    402|	int _ret = (r); \
  |  |  |  |  178|    402|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 402]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    402|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 402]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1075|       |
 1076|    402|	tries_left = -1;
 1077|    402|	rv = sc_verify(card, SC_AC_CHV, 0x81, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|    402|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1078|    402|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)   {
  ------------------
  |  |   64|    402|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1078:6): [True: 10, False: 392]
  ------------------
 1079|       |		/* add PIN */
 1080|     10|		memset(&auth_info, 0, sizeof(auth_info));
 1081|     10|		memset(&obj,  0, sizeof(obj));
 1082|       |
 1083|     10|		auth_info.auth_id.len = sizeof(PinDomainID) > sizeof(auth_info.auth_id.value)
  ------------------
  |  Branch (1083:27): [Folded, False: 10]
  ------------------
 1084|     10|				? sizeof(auth_info.auth_id.value) : sizeof(PinDomainID);
 1085|     10|		memcpy(auth_info.auth_id.value, PinDomainID, auth_info.auth_id.len);
 1086|     10|		auth_info.auth_method	= SC_AC_CHV;
  ------------------
  |  |  151|     10|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1087|       |
 1088|     10|		auth_info.attrs.pin.min_length		= 4;
 1089|     10|		auth_info.attrs.pin.max_length		= 64;
 1090|     10|		auth_info.attrs.pin.stored_length	= 64;
 1091|     10|		auth_info.attrs.pin.type		= SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|     10|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
 1092|     10|		auth_info.attrs.pin.reference		= 0x81;
 1093|     10|		auth_info.attrs.pin.pad_char		= 0xFF;
 1094|     10|		auth_info.attrs.pin.flags		= SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
  ------------------
  |  |   54|     10|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
 1095|     10|					| SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|     10|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
 1096|     10|					| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
  ------------------
  |  |   59|     10|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
 1097|     10|					| SC_PKCS15_PIN_FLAG_LOCAL;
  ------------------
  |  |   55|     10|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
 1098|     10|		auth_info.tries_left		= tries_left;
 1099|       |
 1100|     10|		strncpy(obj.label, PIN_DOMAIN_LABEL, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   66|     10|#define PIN_DOMAIN_LABEL	"SCM"
  ------------------
              		strncpy(obj.label, PIN_DOMAIN_LABEL, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|     10|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1101|     10|		obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|     10|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     10|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1102|     10|		if (sopin_reference == 0x84) {
  ------------------
  |  Branch (1102:7): [True: 3, False: 7]
  ------------------
 1103|       |			/*
 1104|       |			 * auth_pin_reset_oberthur_style() in card-oberthur.c
 1105|       |			 * always uses PUK with reference 0x84 for
 1106|       |			 * unblocking of User PIN
 1107|       |			 */
 1108|      3|			obj.auth_id.len = 1;
 1109|      3|			obj.auth_id.value[0] = 0xFF;
 1110|      3|		}
 1111|       |
 1112|     10|		sc_format_path(AWP_PIN_DF, &auth_info.path);
  ------------------
  |  |   69|     10|#define AWP_PIN_DF		"3F005011"
  ------------------
 1113|     10|		auth_info.path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|     10|#define SC_PATH_TYPE_PATH		2
  ------------------
 1114|       |
 1115|     10|		sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1116|     10|				sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
 1117|     10|		rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
 1118|     10|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot add PIN object");
  ------------------
  |  |  184|     10|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     10|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     10|	int _ret = (r); \
  |  |  |  |  178|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1119|     10|	}
 1120|    392|	else if (rv != SC_ERROR_DATA_OBJECT_NOT_FOUND)    {
  ------------------
  |  |   66|    392|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (1120:11): [True: 391, False: 1]
  ------------------
 1121|    391|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot verify PIN");
  ------------------
  |  |  184|    391|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    391|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    391|	int _ret = (r); \
  |  |  |  |  178|    391|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 30, False: 361]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     30|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     30|		goto err; \
  |  |  |  |  182|     30|	} \
  |  |  |  |  183|    391|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 361]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1122|    391|	}
 1123|       |
 1124|  1.09k|	for (ii=0; oberthur_infos[ii].name; ii++)   {
  ------------------
  |  Branch (1124:13): [True: 1.05k, False: 45]
  ------------------
 1125|  1.05k|		sc_log(ctx, "Oberthur init: read %s file", oberthur_infos[ii].name);
  ------------------
  |  |   71|  1.05k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1126|  1.05k|		free(oberthur_infos[ii].content);
 1127|  1.05k|		rv = sc_oberthur_read_file(p15card, oberthur_infos[ii].path,
 1128|  1.05k|				&oberthur_infos[ii].content, &oberthur_infos[ii].len, 1);
 1129|  1.05k|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: read oberthur file error");
  ------------------
  |  |  184|  1.05k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.05k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.05k|	int _ret = (r); \
  |  |  |  |  178|  1.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 97, False: 955]
  |  |  |  |  ------------------
  |  |  |  |  179|     97|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     97|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     97|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     97|		goto err; \
  |  |  |  |  182|     97|	} \
  |  |  |  |  183|  1.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 955]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|       |
 1131|    955|		sc_log(ctx, "Oberthur init: parse %s file, content length %zu",
  ------------------
  |  |   71|    955|#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|    955|				oberthur_infos[ii].name, oberthur_infos[ii].len);
 1133|    955|		rv = oberthur_infos[ii].parser(p15card, oberthur_infos[ii].content, oberthur_infos[ii].len,
 1134|    955|				oberthur_infos[ii].postpone_allowed);
 1135|    955|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: parse error");
  ------------------
  |  |  184|    955|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    955|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    955|	int _ret = (r); \
  |  |  |  |  178|    955|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 230, False: 725]
  |  |  |  |  ------------------
  |  |  |  |  179|    230|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    230|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    230|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    230|		goto err; \
  |  |  |  |  182|    230|	} \
  |  |  |  |  183|    955|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 725]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1136|    955|	}
 1137|       |
 1138|     45|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1139|       |
 1140|    758|err:
 1141|    758|	sc_pkcs15_card_clear(p15card);
 1142|    758|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    758|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    758|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    758|	int _ret = r; \
  |  |  |  |  155|    758|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 758, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    758|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    758|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 758, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    758|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    758|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    758|	return _ret; \
  |  |  |  |  163|    758|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1143|    758|}
pkcs15-oberthur.c:sc_awp_parse_df:
 1174|      6|{
 1175|      6|	struct sc_context *ctx = p15card->card->ctx;
 1176|      6|	unsigned char *buf = NULL;
 1177|      6|	size_t buf_len;
 1178|      6|	int rv;
 1179|       |
 1180|      6|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|      6|	if (df->type != SC_PKCS15_PRKDF && df->type != SC_PKCS15_DODF)
  ------------------
  |  |  488|     12|#define SC_PKCS15_PRKDF			0
  ------------------
              	if (df->type != SC_PKCS15_PRKDF && df->type != SC_PKCS15_DODF)
  ------------------
  |  |  495|      6|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (1181:6): [True: 6, False: 0]
  |  Branch (1181:37): [True: 0, False: 6]
  ------------------
 1182|      6|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1183|       |
 1184|      6|	if (df->enumerated)
  ------------------
  |  Branch (1184:6): [True: 0, False: 6]
  ------------------
 1185|      6|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1186|       |
 1187|      6|	rv = sc_oberthur_read_file(p15card, AWP_OBJECTS_LIST_PRV, &buf, &buf_len, 1);
  ------------------
  |  |   74|      6|#define AWP_OBJECTS_LIST_PRV	"3F0050115000"
  ------------------
 1188|      6|	LOG_TEST_RET(ctx, rv, "Parse DF: read private objects info 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1189|       |
 1190|      0|	rv = sc_oberthur_parse_privateinfo(p15card, buf, buf_len, 0);
 1191|       |
 1192|      0|	if (buf)
  ------------------
  |  Branch (1192:6): [True: 0, False: 0]
  ------------------
 1193|      0|		free(buf);
 1194|       |
 1195|      0|	if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (1195:6): [True: 0, False: 0]
  ------------------
 1196|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1197|       |
 1198|      0|	LOG_TEST_RET(ctx, rv, "Parse DF: private info parse 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1199|      0|	df->enumerated = 1;
 1200|       |
 1201|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1202|      0|}
pkcs15-oberthur.c:sc_oberthur_parse_privateinfo:
  500|     65|{
  501|     65|	struct sc_context *ctx = p15card->card->ctx;
  502|     65|	size_t ii;
  503|     65|	int rv;
  504|     65|	int no_more_private_keys = 0, no_more_private_data = 0;
  505|       |
  506|     65|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     65|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     65|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     65|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     65|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  507|       |
  508|  47.2k|	for (ii=0; ii+5<=len; ii+=5)   {
  ------------------
  |  Branch (508:13): [True: 47.1k, False: 45]
  ------------------
  509|  47.1k|		unsigned int file_id, size;
  510|       |
  511|  47.1k|		if(*(buff+ii) != 0xFF)
  ------------------
  |  Branch (511:6): [True: 47.0k, False: 161]
  ------------------
  512|  47.0k|			continue;
  513|       |
  514|    161|		file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
  515|    161|		size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
  516|    161|		sc_log(ctx, "add private object (file-id:%04X, size:%X)", file_id, size);
  ------------------
  |  |   71|    161|#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|    161|		switch (*(buff+ii + 1))   {
  519|      3|		case BASE_ID_PRV_RSA :
  ------------------
  |  |   83|      3|#define BASE_ID_PRV_RSA   0x30
  ------------------
  |  Branch (519:3): [True: 3, False: 158]
  ------------------
  520|      3|			if (no_more_private_keys)
  ------------------
  |  Branch (520:8): [True: 0, False: 3]
  ------------------
  521|      0|				break;
  522|       |
  523|      3|			rv = sc_pkcs15emu_oberthur_add_prvkey(p15card, file_id, size);
  524|      3|			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
  ------------------
  |  |   61|      6|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (524:8): [True: 0, False: 3]
  |  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|      3|			LOG_TEST_RET(ctx, rv, "Cannot parse private key info");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|      0|			break;
  535|     12|		case BASE_ID_PRV_DES :
  ------------------
  |  |   84|     12|#define BASE_ID_PRV_DES   0x40
  ------------------
  |  Branch (535:3): [True: 12, False: 149]
  ------------------
  536|     12|			break;
  537|    145|		case BASE_ID_PRV_DATA :
  ------------------
  |  |   86|    145|#define BASE_ID_PRV_DATA  0x60
  ------------------
  |  Branch (537:3): [True: 145, False: 16]
  ------------------
  538|    145|			sc_log(ctx, "*(buff+ii + 1):%X", *(buff+ii + 1));
  ------------------
  |  |   71|    145|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  539|    145|			if (no_more_private_data)
  ------------------
  |  Branch (539:8): [True: 18, False: 127]
  ------------------
  540|     18|				break;
  541|       |
  542|    127|			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 1);
  543|    127|			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
  ------------------
  |  |   61|    254|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (543:8): [True: 6, False: 121]
  |  Branch (543:56): [True: 6, False: 0]
  ------------------
  544|      6|				struct sc_path path;
  545|       |
  546|      6|				sc_log(ctx, "postpone adding of the private data");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  547|      6|				sc_format_path("5011A6A6", &path);
  548|      6|				rv = sc_pkcs15_add_df(p15card, SC_PKCS15_DODF, &path);
  ------------------
  |  |  495|      6|#define SC_PKCS15_DODF			7
  ------------------
  549|      6|				LOG_TEST_RET(ctx, rv, "Add DODF error");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  550|      6|				no_more_private_data = 1;
  551|      6|			}
  552|    127|			LOG_TEST_RET(ctx, rv, "Cannot parse private data info");
  ------------------
  |  |  174|    127|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    127|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    127|	int _ret = (r); \
  |  |  |  |  168|    127|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 111]
  |  |  |  |  ------------------
  |  |  |  |  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|    127|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 111]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  553|    111|			break;
  554|    111|		default:
  ------------------
  |  Branch (554:3): [True: 1, False: 160]
  ------------------
  555|      1|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Private object parse 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|    161|		}
  557|    161|	}
  558|       |
  559|     45|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|     45|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_prvkey:
  763|      3|{
  764|      3|	struct sc_context *ctx = p15card->card->ctx;
  765|      3|	struct sc_pkcs15_prkey_info kinfo;
  766|      3|	struct sc_pkcs15_object kobj;
  767|      3|	struct crypto_container ccont;
  768|      3|	unsigned char *info_blob = NULL;
  769|      3|	size_t info_len = 0;
  770|      3|	unsigned flags;
  771|      3|	size_t offs, len;
  772|      3|	char ch_tmp[0x100];
  773|      3|	int rv;
  774|       |
  775|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|      3|	sc_log(ctx, "add private key(file-id:%04X,size:%04X)", file_id, size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  777|       |
  778|      3|	memset(&kinfo, 0, sizeof(kinfo));
  779|      3|	memset(&kobj, 0, sizeof(kobj));
  780|      3|	memset(&ccont, 0, sizeof(ccont));
  781|       |
  782|      3|	rv = sc_oberthur_get_friends (file_id, &ccont);
  783|      3|	LOG_TEST_RET(ctx, rv, "Failed to add private key: get friends 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|      3|{
  166|      3|	struct container *cont;
  167|       |
  168|      3|	for (cont = Containers; cont; cont = cont->next)   {
  ------------------
  |  Branch (168:26): [True: 0, False: 3]
  ------------------
  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|      3|	return cont ? 0 : SC_ERROR_TEMPLATE_NOT_FOUND;
  ------------------
  |  |  110|      3|#define SC_ERROR_TEMPLATE_NOT_FOUND		-1508
  ------------------
  |  Branch (182:9): [True: 0, False: 3]
  ------------------
  183|      3|}
pkcs15-oberthur.c:sc_oberthur_decode_usage:
  138|    141|{
  139|    141|	unsigned ret = 0;
  140|       |
  141|    141|	if (flags & OBERTHUR_ATTR_ENCRYPT)
  ------------------
  |  |   48|    141|#define OBERTHUR_ATTR_ENCRYPT		0x0008
  ------------------
  |  Branch (141:6): [True: 81, False: 60]
  ------------------
  142|     81|		ret |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|     81|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  143|    141|	if (flags & OBERTHUR_ATTR_DECRYPT)
  ------------------
  |  |   49|    141|#define OBERTHUR_ATTR_DECRYPT		0x0010
  ------------------
  |  Branch (143:6): [True: 63, False: 78]
  ------------------
  144|     63|		ret |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|     63|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  145|    141|	if (flags & OBERTHUR_ATTR_SIGN)
  ------------------
  |  |   50|    141|#define OBERTHUR_ATTR_SIGN		0x0020
  ------------------
  |  Branch (145:6): [True: 83, False: 58]
  ------------------
  146|     83|		ret |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     83|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  147|    141|	if (flags & OBERTHUR_ATTR_RSIGN)
  ------------------
  |  |   52|    141|#define OBERTHUR_ATTR_RSIGN		0x0080
  ------------------
  |  Branch (147:6): [True: 37, False: 104]
  ------------------
  148|     37|		ret |= SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|     37|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  149|    141|	if (flags & OBERTHUR_ATTR_WRAP)
  ------------------
  |  |   54|    141|#define OBERTHUR_ATTR_WRAP		0x0200
  ------------------
  |  Branch (149:6): [True: 85, False: 56]
  ------------------
  150|     85|		ret |= SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|     85|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  151|    141|	if (flags & OBERTHUR_ATTR_UNWRAP)
  ------------------
  |  |   55|    141|#define OBERTHUR_ATTR_UNWRAP		0x0400
  ------------------
  |  Branch (151:6): [True: 58, False: 83]
  ------------------
  152|     58|		ret |= SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|     58|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  153|    141|	if (flags & OBERTHUR_ATTR_VERIFY)
  ------------------
  |  |   51|    141|#define OBERTHUR_ATTR_VERIFY		0x0040
  ------------------
  |  Branch (153:6): [True: 85, False: 56]
  ------------------
  154|     85|		ret |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|     85|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  155|    141|	if (flags & OBERTHUR_ATTR_RVERIFY)
  ------------------
  |  |   53|    141|#define OBERTHUR_ATTR_RVERIFY		0x0100
  ------------------
  |  Branch (155:6): [True: 31, False: 110]
  ------------------
  156|     31|		ret |= SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     31|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  157|    141|	if (flags & OBERTHUR_ATTR_DERIVE)
  ------------------
  |  |   56|    141|#define OBERTHUR_ATTR_DERIVE		0x0800
  ------------------
  |  Branch (157:6): [True: 59, False: 82]
  ------------------
  158|     59|		ret |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|     59|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  159|    141|	return ret;
  160|    141|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_data:
  909|    182|{
  910|    182|	struct sc_context *ctx = p15card->card->ctx;
  911|    182|	struct sc_pkcs15_data_info dinfo;
  912|    182|	struct sc_pkcs15_object dobj;
  913|    182|	unsigned flags;
  914|    182|	unsigned char *info_blob = NULL, *label = NULL, *app = NULL, *oid = NULL;
  915|    182|	size_t info_len, label_len, app_len, oid_len, offs;
  916|    182|	char ch_tmp[0x100];
  917|    182|	int rv;
  918|       |
  919|    182|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    182|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    182|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    182|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 182]
  |  |  ------------------
  ------------------
  920|    182|	sc_log(ctx, "Add data(file-id:%04X,size:%i,is-private:%i)", file_id, size, private);
  ------------------
  |  |   71|    182|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  921|    182|	memset(&dinfo, 0, sizeof(dinfo));
  922|    182|	memset(&dobj, 0, sizeof(dobj));
  923|       |
  924|    182|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   76|    127|#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|     55|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  |  Branch (924:45): [True: 127, False: 55]
  ------------------
  925|       |
  926|    182|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  927|    182|	LOG_TEST_RET(ctx, rv, "Failed to add data: read oberthur file error");
  ------------------
  |  |  174|    182|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    182|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    182|	int _ret = (r); \
  |  |  |  |  168|    182|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  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|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  928|       |
  929|    159|	if (info_len < 2) {
  ------------------
  |  Branch (929:6): [True: 4, False: 155]
  ------------------
  930|      4|		free(info_blob);
  931|      4|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  932|      4|	}
  933|    155|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  934|    155|	offs = 2;
  935|       |
  936|       |	/* Label */
  937|    155|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (937:6): [True: 1, False: 154]
  ------------------
  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|    154|	label = info_blob + offs + 2;
  942|    154|	label_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  943|    154|	if (offs + 2 + label_len > info_len) {
  ------------------
  |  Branch (943:6): [True: 6, False: 148]
  ------------------
  944|      6|		free(info_blob);
  945|      6|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'label' received");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  946|      6|	}
  947|    148|	if (label_len > sizeof(dobj.label) - 1)
  ------------------
  |  Branch (947:6): [True: 80, False: 68]
  ------------------
  948|     80|		label_len = sizeof(dobj.label) - 1;
  949|    148|	offs += 2 + *(info_blob + offs + 1);
  950|       |
  951|       |	/* Application */
  952|    148|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (952:6): [True: 1, False: 147]
  ------------------
  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|    147|	app = info_blob + offs + 2;
  957|    147|	app_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  958|    147|	if (offs + 2 + app_len > info_len) {
  ------------------
  |  Branch (958:6): [True: 7, False: 140]
  ------------------
  959|      7|		free(info_blob);
  960|      7|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'application' received");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  961|      7|	}
  962|    140|	if (app_len > sizeof(dinfo.app_label) - 1)
  ------------------
  |  Branch (962:6): [True: 32, False: 108]
  ------------------
  963|     32|		app_len = sizeof(dinfo.app_label) - 1;
  964|    140|	offs += 2 + app_len;
  965|       |
  966|       |	/* OID encode like DER(ASN.1(oid)) */
  967|    140|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (967:6): [True: 1, False: 139]
  ------------------
  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|    139|	oid_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  972|    139|	if (offs + 2 + oid_len > info_len) {
  ------------------
  |  Branch (972:6): [True: 7, False: 132]
  ------------------
  973|      7|		free(info_blob);
  974|      7|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'oid' received");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  975|      7|	}
  976|    132|	if (oid_len > 2) {
  ------------------
  |  Branch (976:6): [True: 4, False: 128]
  ------------------
  977|      4|		oid = info_blob + offs + 2;
  978|      4|		if (*oid != 0x06 || (*(oid + 1) != oid_len - 2)) {
  ------------------
  |  Branch (978:7): [True: 2, False: 2]
  |  Branch (978:23): [True: 1, False: 1]
  ------------------
  979|      3|			free(info_blob);
  980|      3|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: invalid 'OID' format");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  981|      3|		}
  982|      1|		oid += 2;
  983|      1|		oid_len -= 2;
  984|      1|	}
  985|       |
  986|    129|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   76|    105|#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|     24|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  |  Branch (986:45): [True: 105, False: 24]
  ------------------
  987|       |
  988|    129|	sc_format_path(ch_tmp, &dinfo.path);
  989|       |
  990|    129|	memcpy(dobj.label, label, label_len);
  991|    129|	memcpy(dinfo.app_label, app, app_len);
  992|    129|	if (oid_len)
  ------------------
  |  Branch (992:6): [True: 4, False: 125]
  ------------------
  993|      4|		sc_asn1_decode_object_id(oid, oid_len, &dinfo.app_oid);
  994|       |
  995|    129|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|    129|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (995:6): [True: 18, False: 111]
  ------------------
  996|     18|		dobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     18|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  997|       |
  998|    129|	if (private)   {
  ------------------
  |  Branch (998:6): [True: 105, False: 24]
  ------------------
  999|    105|		dobj.auth_id.len = sizeof(PinDomainID) > sizeof(dobj.auth_id.value)
  ------------------
  |  Branch (999:22): [Folded, False: 105]
  ------------------
 1000|    105|				? sizeof(dobj.auth_id.value) : sizeof(PinDomainID);
 1001|    105|		memcpy(dobj.auth_id.value, PinDomainID, dobj.auth_id.len);
 1002|       |
 1003|    105|		dobj.flags |= SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    105|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1004|    105|	}
 1005|       |
 1006|    129|	rv = sc_pkcs15emu_add_data_object(p15card, &dobj, &dinfo);
 1007|       |
 1008|    129|	free(info_blob);
 1009|    129|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|    129|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    129|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    129|	int _ret = r; \
  |  |  |  |  155|    129|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 129, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    129|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 129]
  |  |  |  |  ------------------
  |  |  |  |  157|    129|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    129|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    129|	return _ret; \
  |  |  |  |  163|    129|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1010|    129|}
pkcs15-oberthur.c:sc_awp_clear:
 1207|  1.56k|{
 1208|  1.56k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  1.56k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.56k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.56k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.56k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.56k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1209|  1.56k|}
pkcs15-oberthur.c:sc_oberthur_parse_tokeninfo:
  365|    339|{
  366|    339|	struct sc_context *ctx = p15card->card->ctx;
  367|    339|	char label[0x21];
  368|    339|	unsigned flags;
  369|    339|	int ii;
  370|       |
  371|    339|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    339|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    339|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    339|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    339|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 339]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|    339|	if (!buff || len < 0x24)
  ------------------
  |  Branch (372:6): [True: 0, False: 339]
  |  Branch (372:15): [True: 14, False: 325]
  ------------------
  373|    339|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Cannot parse token 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|       |
  375|    325|	memset(label, 0, sizeof(label));
  376|       |
  377|    325|	memcpy(label, buff, 0x20);
  378|    325|	ii = 0x20;
  379|    397|	while (*(label + --ii)==' ' && ii)
  ------------------
  |  Branch (379:9): [True: 73, False: 324]
  |  Branch (379:33): [True: 72, False: 1]
  ------------------
  380|     72|		;
  381|    325|	*(label + ii + 1) = '\0';
  382|       |
  383|    325|	flags = *(buff + 0x22) * 0x100 + *(buff + 0x23);
  384|       |
  385|    325|	set_string(&p15card->tokeninfo->label, label);
  386|    325|	set_string(&p15card->tokeninfo->manufacturer_id, "Oberthur/OpenSC");
  387|       |
  388|    325|	if (flags & 0x01)
  ------------------
  |  Branch (388:6): [True: 11, False: 314]
  ------------------
  389|     11|		p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION;
  ------------------
  |  |  597|     11|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
  390|       |
  391|    325|	sc_log(ctx, "label %s", p15card->tokeninfo->label);
  ------------------
  |  |   71|    325|#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|    325|	sc_log(ctx, "manufacturer_id %s", p15card->tokeninfo->manufacturer_id);
  ------------------
  |  |   71|    325|#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|    325|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    325|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    325|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    325|	int _ret = r; \
  |  |  |  |  155|    325|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 325, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    325|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 325]
  |  |  |  |  ------------------
  |  |  |  |  157|    325|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    325|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    325|	return _ret; \
  |  |  |  |  163|    325|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|    325|}
pkcs15-oberthur.c:sc_oberthur_parse_containers:
  401|    294|{
  402|    294|	struct sc_context *ctx = p15card->card->ctx;
  403|    294|	size_t offs;
  404|       |
  405|    294|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    294|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    294|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    294|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    294|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 294]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  406|       |
  407|    357|	while (Containers)   {
  ------------------
  |  Branch (407:9): [True: 63, False: 294]
  ------------------
  408|     63|		struct container *next = Containers->next;
  409|       |
  410|     63|		free (Containers);
  411|     63|		Containers = next;
  412|     63|	}
  413|       |
  414|    357|	for (offs=0; offs + 2 + 2+2+2 + 2+2+2 + 2+36 <= len;)  {
  ------------------
  |  Branch (414:15): [True: 90, False: 267]
  ------------------
  415|     90|		struct container *cont;
  416|     90|		unsigned char *ptr =  buff + offs + 2;
  417|       |
  418|     90|		sc_log(ctx, "parse contaniers offs:%zu, len:%zu", offs, len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  419|     90|		if (*(buff + offs) != 'R')
  ------------------
  |  Branch (419:7): [True: 27, False: 63]
  ------------------
  420|     27|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     27|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  421|       |
  422|     63|		cont = (struct container *)calloc(1, sizeof(struct container));
  423|     63|		if (!cont)
  ------------------
  |  Branch (423:7): [True: 0, False: 63]
  ------------------
  424|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  425|       |
  426|     63|		cont->exchange.id_pub = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  427|     63|		cont->exchange.id_prv = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  428|     63|		cont->exchange.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
  429|       |
  430|     63|		cont->sign.id_pub = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  431|     63|		cont->sign.id_prv = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  432|     63|		cont->sign.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
  433|       |
  434|     63|		memcpy(cont->uuid, ptr + 2, 36);
  435|     63|		sc_log(ctx, "UUID: %s; 0x%X, 0x%X, 0x%X", cont->uuid,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  436|     63|				cont->exchange.id_pub, cont->exchange.id_prv, cont->exchange.id_cert);
  437|       |
  438|     63|		if (!Containers)  {
  ------------------
  |  Branch (438:7): [True: 17, False: 46]
  ------------------
  439|     17|			Containers = cont;
  440|     17|		}
  441|     46|		else   {
  442|     46|			cont->next = Containers;
  443|     46|			Containers->prev = (void *)cont;
  444|     46|			Containers = cont;
  445|     46|		}
  446|       |
  447|     63|		offs += *(buff + offs + 1) + 2;
  448|     63|	}
  449|       |
  450|    267|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    267|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    267|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    267|	int _ret = r; \
  |  |  |  |  155|    267|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 267, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    267|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 267]
  |  |  |  |  ------------------
  |  |  |  |  157|    267|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    267|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    267|	return _ret; \
  |  |  |  |  163|    267|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  451|    267|}
pkcs15-oberthur.c:sc_oberthur_parse_publicinfo:
  457|    257|{
  458|    257|	struct sc_context *ctx = p15card->card->ctx;
  459|    257|	size_t ii;
  460|    257|	int rv;
  461|       |
  462|    257|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    257|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    257|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|  91.5k|	for (ii=0; ii+5<=len; ii+=5)   {
  ------------------
  |  Branch (463:13): [True: 91.4k, False: 88]
  ------------------
  464|  91.4k|		unsigned int file_id, size;
  465|       |
  466|  91.4k|		if(*(buff+ii) != 0xFF)
  ------------------
  |  Branch (466:6): [True: 91.1k, False: 291]
  ------------------
  467|  91.1k|			continue;
  468|       |
  469|    291|		file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
  470|    291|		size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
  471|    291|		sc_log(ctx, "add public object(file-id:%04X,size:%X)", file_id, size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  472|       |
  473|    291|		switch (*(buff+ii + 1))   {
  474|    154|		case BASE_ID_PUB_RSA :
  ------------------
  |  |   81|    154|#define BASE_ID_PUB_RSA   0x10
  ------------------
  |  Branch (474:3): [True: 154, False: 137]
  ------------------
  475|    154|			rv = sc_pkcs15emu_oberthur_add_pubkey(p15card, file_id, size);
  476|    154|			LOG_TEST_RET(ctx, rv, "Cannot parse public key info");
  ------------------
  |  |  174|    154|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    154|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    154|	int _ret = (r); \
  |  |  |  |  168|    154|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 74, False: 80]
  |  |  |  |  ------------------
  |  |  |  |  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|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 80]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  477|     80|			break;
  478|     80|		case BASE_ID_CERT :
  ------------------
  |  |   82|     56|#define BASE_ID_CERT	  0x20
  ------------------
  |  Branch (478:3): [True: 56, False: 235]
  ------------------
  479|     56|			rv = sc_pkcs15emu_oberthur_add_cert(p15card, file_id);
  480|     56|			LOG_TEST_RET(ctx, rv, "Cannot parse certificate info");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|      0|			break;
  482|     18|		case BASE_ID_PUB_DES :
  ------------------
  |  |   87|     18|#define BASE_ID_PUB_DES   0x70
  ------------------
  |  Branch (482:3): [True: 18, False: 273]
  ------------------
  483|     18|			break;
  484|     55|		case BASE_ID_PUB_DATA :
  ------------------
  |  |   85|     55|#define BASE_ID_PUB_DATA  0x50
  ------------------
  |  Branch (484:3): [True: 55, False: 236]
  ------------------
  485|     55|			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 0);
  486|     55|			LOG_TEST_RET(ctx, rv, "Cannot parse data info");
  ------------------
  |  |  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: 31, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  487|     24|			break;
  488|     24|		default:
  ------------------
  |  Branch (488:3): [True: 8, False: 283]
  ------------------
  489|      8|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Public object parse error");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|    291|		}
  491|    291|	}
  492|       |
  493|     88|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     88|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     88|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     88|	int _ret = r; \
  |  |  |  |  155|     88|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 88, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     88|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  157|     88|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     88|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     88|	return _ret; \
  |  |  |  |  163|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|     88|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_pubkey:
  574|    154|{
  575|    154|	struct sc_context *ctx = p15card->card->ctx;
  576|    154|	struct sc_pkcs15_pubkey_info key_info;
  577|    154|	struct sc_pkcs15_object key_obj;
  578|    154|	char ch_tmp[0x100];
  579|    154|	unsigned char *info_blob = NULL;
  580|    154|	size_t len, info_len, offs;
  581|    154|	unsigned flags;
  582|    154|	int rv;
  583|       |
  584|    154|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    154|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    154|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    154|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    154|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 154]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|    154|	sc_log(ctx, "public key(file-id:%04X,size:%X)", file_id, size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  586|       |
  587|    154|	memset(&key_info, 0, sizeof(key_info));
  588|    154|	memset(&key_obj, 0, sizeof(key_obj));
  589|       |
  590|    154|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|    154|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  591|    154|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  592|    154|	LOG_TEST_RET(ctx, rv, "Failed to add public key: read oberthur file error");
  ------------------
  |  |  174|    154|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    154|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    154|	int _ret = (r); \
  |  |  |  |  168|    154|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 143]
  |  |  |  |  ------------------
  |  |  |  |  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|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 143]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  593|       |
  594|       |	/* Flags */
  595|    143|	offs = 2;
  596|    143|	if (offs > info_len) {
  ------------------
  |  Branch (596:6): [True: 2, False: 141]
  ------------------
  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|    141|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  601|    141|	key_info.usage = sc_oberthur_decode_usage(flags);
  602|    141|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|    141|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (602:6): [True: 54, False: 87]
  ------------------
  603|     54|		key_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     54|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  604|    141|	sc_log(ctx, "Public key key-usage:%04X", key_info.usage);
  ------------------
  |  |   71|    141|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  605|       |
  606|       |	/* Label */
  607|    141|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (607:6): [True: 1, False: 140]
  ------------------
  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|    140|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  612|    140|	if (offs + 2 + len > info_len) {
  ------------------
  |  Branch (612:6): [True: 15, False: 125]
  ------------------
  613|     15|		free(info_blob);
  614|     15|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalid 'Label' length");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|    125|	} else if (len) {
  ------------------
  |  Branch (615:13): [True: 92, False: 33]
  ------------------
  616|     92|		if (len > sizeof(key_obj.label) - 1)
  ------------------
  |  Branch (616:7): [True: 50, False: 42]
  ------------------
  617|     50|			len = sizeof(key_obj.label) - 1;
  618|     92|		memcpy(key_obj.label, info_blob + offs + 2, len);
  619|     92|	}
  620|    125|	offs += 2 + len;
  621|       |
  622|       |	/* ID */
  623|    125|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (623:6): [True: 2, False: 123]
  ------------------
  624|      2|		free(info_blob);
  625|      2|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'ID'");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  626|      2|	}
  627|    123|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  628|    123|	if (len == 0
  ------------------
  |  Branch (628:6): [True: 23, False: 100]
  ------------------
  629|    100|			|| len > sizeof(key_info.id.value)
  ------------------
  |  Branch (629:7): [True: 18, False: 82]
  ------------------
  630|     82|			|| offs + 2 + len > info_len) {
  ------------------
  |  Branch (630:7): [True: 2, False: 80]
  ------------------
  631|     43|		free(info_blob);
  632|     43|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalid 'ID' length");
  ------------------
  |  |  174|     43|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     43|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     43|	int _ret = (r); \
  |  |  |  |  168|     43|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     43|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     43|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     43|		return _ret; \
  |  |  |  |  172|     43|	} \
  |  |  |  |  173|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|     43|	}
  634|     80|	memcpy(key_info.id.value, info_blob + offs + 2, len);
  635|     80|	key_info.id.len = len;
  636|       |
  637|     80|	free(info_blob);
  638|       |
  639|       |	/* Ignore Start/End dates */
  640|       |
  641|     80|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     80|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  642|     80|	sc_format_path(ch_tmp, &key_info.path);
  643|       |
  644|     80|	key_info.native = 1;
  645|     80|	key_info.key_reference = file_id & 0xFF;
  646|     80|	key_info.modulus_length = size;
  647|       |
  648|     80|	rv = sc_pkcs15emu_add_rsa_pubkey(p15card, &key_obj, &key_info);
  649|       |
  650|     80|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     80|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     80|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     80|	int _ret = r; \
  |  |  |  |  155|     80|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 80, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     80|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 80]
  |  |  |  |  ------------------
  |  |  |  |  157|     80|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     80|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     80|	return _ret; \
  |  |  |  |  163|     80|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|     80|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_cert:
  664|     56|{
  665|     56|	struct sc_context *ctx = p15card->card->ctx;
  666|     56|	struct sc_pkcs15_cert_info cinfo;
  667|     56|	struct sc_pkcs15_object cobj;
  668|     56|	unsigned char *info_blob = NULL, *cert_blob = NULL;
  669|     56|	size_t info_len, cert_len, len, offs;
  670|     56|	unsigned flags;
  671|     56|	int rv;
  672|     56|	char ch_tmp[0x20];
  673|       |
  674|     56|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     56|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  675|     56|	sc_log(ctx, "add certificate(file-id:%04X)", file_id);
  ------------------
  |  |   71|     56|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  676|       |
  677|     56|	memset(&cinfo, 0, sizeof(cinfo));
  678|     56|	memset(&cobj, 0, sizeof(cobj));
  679|       |
  680|     56|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|     56|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  681|     56|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  682|     56|	LOG_TEST_RET(ctx, rv, "Failed to add certificate: read oberthur file error");
  ------------------
  |  |  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: 21, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  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|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  683|       |
  684|     35|	if (info_len < 2) {
  ------------------
  |  Branch (684:6): [True: 1, False: 34]
  ------------------
  685|      1|		free(info_blob);
  686|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|      1|	}
  688|     34|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  689|     34|	offs = 2;
  690|       |
  691|       |	/* Label */
  692|     34|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (692:6): [True: 1, False: 33]
  ------------------
  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|     33|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  697|     33|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (697:6): [True: 1, False: 32]
  ------------------
  698|      1|		free(info_blob);
  699|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'CN' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  700|     32|	} else if (len) {
  ------------------
  |  Branch (700:13): [True: 23, False: 9]
  ------------------
  701|     23|		if (len > sizeof(cobj.label) - 1)
  ------------------
  |  Branch (701:7): [True: 9, False: 14]
  ------------------
  702|      9|			len = sizeof(cobj.label) - 1;
  703|     23|		memcpy(cobj.label, info_blob + offs + 2, len);
  704|     23|	}
  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: 13, False: 18]
  ------------------
  714|     13|		free(info_blob);
  715|     13|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'ID' length");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|     18|	} else if (len > sizeof(cinfo.id.value)) {
  ------------------
  |  Branch (716:13): [True: 1, False: 17]
  ------------------
  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|     17|	memcpy(cinfo.id.value, info_blob + offs + 2, len);
  721|     17|	cinfo.id.len = len;
  722|       |
  723|     17|	free(info_blob);
  724|       |
  725|       |	/* Ignore subject, issuer and serial */
  726|       |
  727|     17|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     17|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  728|     17|	sc_format_path(ch_tmp, &cinfo.path);
  729|     17|	rv = sc_oberthur_read_file(p15card, ch_tmp, &cert_blob, &cert_len, 1);
  730|     17|	LOG_TEST_RET(ctx, rv, "Failed to add certificate: read certificate error");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|      3|	cinfo.value.value = cert_blob;
  733|      3|	cinfo.value.len = cert_len;
  734|       |
  735|      3|	rv = sc_oberthur_get_certificate_authority(ctx, &cinfo.value, &cinfo.authority);
  736|      3|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (736:6): [True: 3, False: 0]
  ------------------
  737|      3|		free(cinfo.value.value);
  738|      3|		LOG_TEST_RET(ctx, rv, "Failed to add certificate: get certificate attributes 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  739|      3|	}
  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|      3|{
  189|      3|#ifdef ENABLE_OPENSSL
  190|      3|	X509	*x;
  191|      3|	BUF_MEM buf_mem;
  192|      3|	BIO *bio = NULL;
  193|      3|	BASIC_CONSTRAINTS *bs = NULL;
  194|       |
  195|      3|	if (!der)
  ------------------
  |  Branch (195:6): [True: 0, False: 3]
  ------------------
  196|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  197|       |
  198|      3|	buf_mem.data = malloc(der->len);
  199|      3|	if (!buf_mem.data)
  ------------------
  |  Branch (199:6): [True: 0, False: 3]
  ------------------
  200|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  201|       |
  202|      3|	memcpy(buf_mem.data, der->value, der->len);
  203|      3|	buf_mem.max = buf_mem.length = der->len;
  204|       |
  205|      3|	bio = BIO_new(BIO_s_mem());
  206|      3|	if (!bio) {
  ------------------
  |  Branch (206:6): [True: 0, False: 3]
  ------------------
  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|      3|	BIO_set_mem_buf(bio, &buf_mem, BIO_NOCLOSE);
  213|      3|	x = d2i_X509_bio(bio, 0);
  214|      3|	free(buf_mem.data);
  215|      3|	BIO_free(bio);
  216|      3|	if (!x) {
  ------------------
  |  Branch (216:6): [True: 3, False: 0]
  ------------------
  217|      3|		sc_log_openssl(ctx);
  ------------------
  |  |   72|      3|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  218|      3|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  219|      3|	}
  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|      3|}
pkcs15-oberthur.c:sc_oberthur_read_file:
  238|  1.46k|{
  239|  1.46k|	struct sc_context *ctx = p15card->card->ctx;
  240|  1.46k|	struct sc_card *card = p15card->card;
  241|  1.46k|	struct sc_file *file = NULL;
  242|  1.46k|	struct sc_path path;
  243|  1.46k|	size_t sz;
  244|  1.46k|	int rv;
  245|       |
  246|  1.46k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.46k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.46k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.46k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.46k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  247|  1.46k|	if (!in_path || !out || !out_len)
  ------------------
  |  Branch (247:6): [True: 0, False: 1.46k]
  |  Branch (247:18): [True: 0, False: 1.46k]
  |  Branch (247:26): [True: 0, False: 1.46k]
  ------------------
  248|  1.46k|		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.46k|	sc_log(ctx, "read file '%s'; verify_pin:%i", in_path, verify_pin);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  251|       |
  252|  1.46k|	*out = NULL;
  253|  1.46k|	*out_len = 0;
  254|       |
  255|  1.46k|	sc_format_path(in_path, &path);
  256|  1.46k|	rv = sc_select_file(card, &path, &file);
  257|  1.46k|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|  1.46k|#define SC_SUCCESS				0
  ------------------
  |  Branch (257:6): [True: 151, False: 1.31k]
  ------------------
  258|    151|		sc_file_free(file);
  259|    151|		LOG_TEST_RET(ctx, rv, "Cannot select oberthur file to read");
  ------------------
  |  |  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: 151, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    151|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    151|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    151|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    151|		return _ret; \
  |  |  |  |  172|    151|	} \
  |  |  |  |  173|    151|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|    151|	}
  261|       |
  262|  1.31k|	if (file->ef_structure == SC_FILE_EF_TRANSPARENT)
  ------------------
  |  |  221|  1.31k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (262:6): [True: 949, False: 367]
  ------------------
  263|    949|		sz = file->size;
  264|    367|	else
  265|    367|		sz = (file->record_length + 2) * file->record_count;
  266|       |
  267|  1.31k|	*out = calloc(1, sz);
  268|  1.31k|	if (*out == NULL) {
  ------------------
  |  Branch (268:6): [True: 0, False: 1.31k]
  ------------------
  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.31k|	if (file->ef_structure == SC_FILE_EF_TRANSPARENT)   {
  ------------------
  |  |  221|  1.31k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (273:6): [True: 949, False: 367]
  ------------------
  274|    949|		rv = sc_read_binary(card, 0, *out, sz, 0);
  275|    949|	}
  276|    367|	else	{
  277|    367|		unsigned int rec;
  278|    367|		size_t offs = 0;
  279|    367|		size_t rec_len = file->record_length;
  280|       |
  281|    367|		for (rec = 1; ; rec++)   {
  282|    367|			if (rec > file->record_count) {
  ------------------
  |  Branch (282:8): [True: 367, False: 0]
  ------------------
  283|    367|				rv = 0;
  284|    367|				break;
  285|    367|			}
  286|      0|			rv = sc_read_record(card, rec, 0, *out + offs + 2, rec_len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|      0|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  287|      0|			if (rv == SC_ERROR_RECORD_NOT_FOUND)   {
  ------------------
  |  |   52|      0|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (287:8): [True: 0, False: 0]
  ------------------
  288|      0|				rv = 0;
  289|      0|				break;
  290|      0|			}
  291|      0|			else if (rv < 0)   {
  ------------------
  |  Branch (291:13): [True: 0, False: 0]
  ------------------
  292|      0|				break;
  293|      0|			}
  294|       |
  295|      0|			rec_len = rv;
  296|       |
  297|      0|			*(*out + offs) = 'R';
  298|      0|			*(*out + offs + 1) = rv;
  299|       |
  300|      0|			offs += rv + 2;
  301|      0|		}
  302|       |
  303|    367|		sz = offs;
  304|    367|	}
  305|       |
  306|  1.31k|	sc_log(ctx, "read oberthur file result %i", rv);
  ------------------
  |  |   71|  1.31k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  307|  1.31k|	if (verify_pin && rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)   {
  ------------------
  |  |   61|  1.31k|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (307:6): [True: 1.31k, False: 0]
  |  Branch (307:20): [True: 1, False: 1.31k]
  ------------------
  308|      1|		struct sc_pkcs15_object *objs[0x10], *pin_obj = NULL;
  309|      1|		const struct sc_acl_entry *acl = sc_file_get_acl_entry(file, SC_AC_OP_READ);
  ------------------
  |  |  188|      1|#define SC_AC_OP_READ			22
  ------------------
  310|      1|		int ii, nobjs;
  311|       |
  312|      1|		if (acl == NULL) {
  ------------------
  |  Branch (312:7): [True: 1, False: 0]
  ------------------
  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|      0|		nobjs = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 0x10);
  ------------------
  |  |  445|      0|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  320|      0|		if (nobjs < 1) {
  ------------------
  |  Branch (320:7): [True: 0, False: 0]
  ------------------
  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|      0|		for (ii = 0; ii < nobjs; ii++) {
  ------------------
  |  Branch (328:16): [True: 0, False: 0]
  ------------------
  329|      0|			struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *) objs[ii]->data;
  330|      0|			sc_log(ctx, "compare PIN/ACL refs:%i/%i, method:%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__
  |  |  ------------------
  ------------------
  331|      0|				auth_info->attrs.pin.reference, acl->key_ref, auth_info->auth_method, acl->method);
  332|      0|			if (auth_info->attrs.pin.reference == (int)acl->key_ref && auth_info->auth_method == (unsigned)acl->method)   {
  ------------------
  |  Branch (332:8): [True: 0, False: 0]
  |  Branch (332:63): [True: 0, False: 0]
  ------------------
  333|      0|				pin_obj = objs[ii];
  334|      0|				break;
  335|      0|			}
  336|      0|		}
  337|       |
  338|      0|		if (!pin_obj || !pin_obj->content.value)    {
  ------------------
  |  Branch (338:7): [True: 0, False: 0]
  |  Branch (338:19): [True: 0, False: 0]
  ------------------
  339|      0|			rv = SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  340|      0|		}
  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|      0|	}
  347|       |
  348|  1.31k|	sc_file_free(file);
  349|       |
  350|  1.31k|	if (rv < 0)   {
  ------------------
  |  Branch (350:6): [True: 20, False: 1.29k]
  ------------------
  351|     20|		free(*out);
  352|     20|		*out = NULL;
  353|     20|		*out_len = 0;
  354|     20|	}
  355|       |
  356|  1.31k|	*out_len = sz;
  357|       |
  358|  1.31k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  1.31k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.31k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.31k|	int _ret = r; \
  |  |  |  |  155|  1.31k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 448, False: 867]
  |  |  |  |  ------------------
  |  |  |  |  156|    448|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 428]
  |  |  |  |  ------------------
  |  |  |  |  157|    448|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    867|	} else { \
  |  |  |  |  159|    867|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    867|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    867|	} \
  |  |  |  |  162|  1.31k|	return _ret; \
  |  |  |  |  163|  1.31k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  359|  1.31k|}

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

sc_pkcs15_decode_aodf_entry:
   86|      4|{
   87|      4|	sc_context_t *ctx = p15card->card->ctx;
   88|      4|	struct sc_pkcs15_auth_info info;
   89|      4|	int r;
   90|      4|	size_t flags_len = sizeof(info.attrs.pin.flags);
   91|      4|	size_t derived_len = sizeof(info.attrs.authkey.derived);
   92|      4|	size_t padchar_len = 1;
   93|      4|	struct sc_asn1_entry asn1_com_ao_attr[2];
   94|      4|	struct sc_asn1_entry asn1_pin_attr[10], asn1_type_pin_attr[2];
   95|      4|	struct sc_asn1_entry asn1_authkey_attr[3], asn1_type_authkey_attr[2];
   96|      4|	struct sc_asn1_entry asn1_auth_type[2];
   97|      4|	struct sc_asn1_entry asn1_auth_type_choice[4];
   98|      4|	struct sc_asn1_pkcs15_object pin_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_pin_attr };
   99|      4|	struct sc_asn1_pkcs15_object authkey_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_authkey_attr };
  100|       |
  101|      4|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  102|       |
  103|      4|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  104|      4|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  105|       |
  106|      4|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  107|       |
  108|      4|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  109|      4|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  110|       |
  111|      4|	sc_copy_asn1_entry(c_asn1_type_authkey_attr, asn1_type_authkey_attr);
  112|      4|	sc_copy_asn1_entry(c_asn1_authkey_attr, asn1_authkey_attr);
  113|       |
  114|      4|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 0);
  115|      4|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 0);	/* 'pin' */
  116|      4|	sc_format_asn1_entry(asn1_auth_type_choice + 2, &authkey_obj, NULL, 0);	/* 'authKey' */
  117|       |
  118|       |	/* pinAttributes */
  119|      4|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 0);
  120|      4|	sc_format_asn1_entry(asn1_pin_attr + 0, &info.attrs.pin.flags, &flags_len, 0);
  121|      4|	sc_format_asn1_entry(asn1_pin_attr + 1, &info.attrs.pin.type, NULL, 0);
  122|      4|	sc_format_asn1_entry(asn1_pin_attr + 2, &info.attrs.pin.min_length, NULL, 0);
  123|      4|	sc_format_asn1_entry(asn1_pin_attr + 3, &info.attrs.pin.stored_length, NULL, 0);
  124|      4|	sc_format_asn1_entry(asn1_pin_attr + 4, &info.attrs.pin.max_length, NULL, 0);
  125|      4|	sc_format_asn1_entry(asn1_pin_attr + 5, &info.attrs.pin.reference, NULL, 0);
  126|      4|	sc_format_asn1_entry(asn1_pin_attr + 6, &info.attrs.pin.pad_char, &padchar_len, 0);
  127|       |
  128|       |	/* authKeyAttributes */
  129|      4|	sc_format_asn1_entry(asn1_type_authkey_attr + 0, asn1_authkey_attr, NULL, 0);
  130|      4|	sc_format_asn1_entry(asn1_authkey_attr + 0, &info.attrs.authkey.derived, &derived_len, 0);
  131|      4|	sc_format_asn1_entry(asn1_authkey_attr + 1, &info.attrs.authkey.skey_id, NULL, 0);
  132|       |
  133|       |	/* We don't support lastPinChange yet. */
  134|      4|	sc_format_asn1_entry(asn1_pin_attr + 8, &info.path, NULL, 0);
  135|       |
  136|      4|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info.auth_id, NULL, 0);
  137|       |
  138|       |	/* Fill in defaults */
  139|      4|	memset(&info, 0, sizeof(info));
  140|      4|	info.tries_left = -1;
  141|      4|	info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      4|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  142|       |
  143|      4|	r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
  144|      4|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      4|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (144:6): [True: 1, False: 3]
  ------------------
  145|      1|		return r;
  146|      3|	LOG_TEST_RET(ctx, r, "ASN.1 decoding 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|       |
  148|      0|	if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (148:6): [True: 0, False: 0]
  ------------------
  149|      0|		sc_log(ctx, "AuthType: PIN");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  150|      0|		obj->type = SC_PKCS15_TYPE_AUTH_PIN;
  ------------------
  |  |  445|      0|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  151|      0|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  152|      0|		info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  153|       |
  154|      0|		if (info.attrs.pin.max_length == 0) {
  ------------------
  |  Branch (154:7): [True: 0, False: 0]
  ------------------
  155|      0|			if (p15card->card->max_pin_len != 0)
  ------------------
  |  Branch (155:8): [True: 0, False: 0]
  ------------------
  156|      0|				info.attrs.pin.max_length = p15card->card->max_pin_len;
  157|      0|			else if (info.attrs.pin.stored_length != 0)
  ------------------
  |  Branch (157:13): [True: 0, False: 0]
  ------------------
  158|      0|				info.attrs.pin.max_length = info.attrs.pin.type != SC_PKCS15_PIN_TYPE_BCD ?
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (158:33): [True: 0, False: 0]
  ------------------
  159|      0|					info.attrs.pin.stored_length : 2 * info.attrs.pin.stored_length;
  160|      0|			else
  161|      0|				info.attrs.pin.max_length = 8; /* shouldn't happen */
  162|      0|		}
  163|       |
  164|       |		/* OpenSC 0.11.4 and older encoded "pinReference" as a negative
  165|       |		   value. Fixed in 0.11.5 we need to add a hack, so old cards
  166|       |		   continue to work.
  167|       |		   The same invalid encoding has some models of the proprietary PKCS#15 cards.
  168|       |		*/
  169|      0|		if (info.attrs.pin.reference < 0)
  ------------------
  |  Branch (169:7): [True: 0, False: 0]
  ------------------
  170|      0|			info.attrs.pin.reference += 256;
  171|       |
  172|      0|		if (info.attrs.pin.flags & SC_PKCS15_PIN_FLAG_LOCAL)   {
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  |  Branch (172:7): [True: 0, False: 0]
  ------------------
  173|       |			/* In OpenSC pkcs#15 framework 'path' is mandatory for the 'Local' PINs.
  174|       |			 * If 'path' do not present in PinAttributes, derive it from the PKCS#15 context. */
  175|      0|			if (!info.path.len)   {
  ------------------
  |  Branch (175:8): [True: 0, False: 0]
  ------------------
  176|       |				/* Give priority to AID defined in the application DDO */
  177|      0|				if (p15card->app && p15card->app->ddo.aid.len)
  ------------------
  |  Branch (177:9): [True: 0, False: 0]
  |  Branch (177:25): [True: 0, False: 0]
  ------------------
  178|      0|					info.path.aid = p15card->app->ddo.aid;
  179|      0|				else if (p15card->file_app && p15card->file_app->path.len)
  ------------------
  |  Branch (179:14): [True: 0, False: 0]
  |  Branch (179:35): [True: 0, False: 0]
  ------------------
  180|      0|					info.path = p15card->file_app->path;
  181|      0|				else
  182|      0|					return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  183|      0|			}
  184|      0|		}
  185|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoded PIN(ref:%X,path:%s)", info.attrs.pin.reference, sc_print_path(&info.path));
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  186|      0|	}
  187|      0|	else if (asn1_auth_type_choice[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (187:11): [True: 0, False: 0]
  ------------------
  188|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|      0|	}
  190|      0|	else if (asn1_auth_type_choice[2].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (190:11): [True: 0, False: 0]
  ------------------
  191|      0|		sc_log(ctx, "AuthType: AuthKey");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  192|      0|		obj->type = SC_PKCS15_TYPE_AUTH_AUTHKEY;
  ------------------
  |  |  447|      0|#define SC_PKCS15_TYPE_AUTH_AUTHKEY		0x603
  ------------------
  193|      0|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY;
  ------------------
  |  |   96|      0|#define SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY		2
  ------------------
  194|      0|		info.auth_method = SC_AC_AUT;
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  195|      0|		if (!(asn1_authkey_attr[0].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (195:7): [True: 0, False: 0]
  ------------------
  196|      0|			info.attrs.authkey.derived = 1;
  197|      0|	}
  198|      0|	else   {
  199|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unknown authentication type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|      0|	}
  201|       |
  202|      0|	obj->data = malloc(sizeof(info));
  203|      0|	if (obj->data == NULL)
  ------------------
  |  Branch (203:6): [True: 0, False: 0]
  ------------------
  204|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|      0|	memcpy(obj->data, &info, sizeof(info));
  206|       |
  207|      0|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_SUCCESS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  208|      0|}
sc_pkcs15_verify_pin:
  299|    475|{
  300|    475|	struct sc_context *ctx = p15card->card->ctx;
  301|    475|	struct sc_pkcs15_auth_info *auth_info;
  302|    475|	int r;
  303|       |
  304|    475|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    475|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    475|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    475|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    475|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 475]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|    475|	if (!pin_obj || !pin_obj->data)
  ------------------
  |  Branch (306:6): [True: 0, False: 475]
  |  Branch (306:18): [True: 0, False: 475]
  ------------------
  307|    475|		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|    475|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  309|       |
  310|       |	/* Check the provided pin matches pin requirements */
  311|    475|	r = _validate_pin(p15card, auth_info, pinlen);
  312|       |
  313|    475|	if (r)
  ------------------
  |  Branch (313:6): [True: 165, False: 310]
  ------------------
  314|    475|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    165|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    165|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    165|	int _ret = r; \
  |  |  |  |  155|    165|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 165, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    165|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    165|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 165, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    165|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    165|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    165|	return _ret; \
  |  |  |  |  163|    165|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|       |
  316|    310|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pincode, pinlen);
  317|       |
  318|    310|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    310|#define SC_SUCCESS				0
  ------------------
  |  Branch (318:6): [True: 93, False: 217]
  ------------------
  319|     93|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  320|       |
  321|    310|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    310|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    310|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    310|	int _ret = r; \
  |  |  |  |  155|    310|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 310, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    310|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    217|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 217, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  157|    310|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    310|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    310|	return _ret; \
  |  |  |  |  163|    310|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|    310|}
_sc_pkcs15_verify_pin:
  328|    319|{
  329|    319|	return sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pincode,
  330|    319|			pinlen, NULL, NULL);
  331|    319|}
sc_pkcs15_verify_pin_with_session_pin:
  344|    319|{
  345|    319|	struct sc_context *ctx = p15card->card->ctx;
  346|    319|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  347|    319|	int r;
  348|    319|	sc_card_t *card;
  349|    319|	struct sc_pin_cmd_data data;
  350|       |
  351|    319|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    319|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    319|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    319|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    319|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 319]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|    319|	sc_log(ctx, "PIN(type:%X; method:%X; value(%p:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  353|    319|			auth_info->auth_type, auth_info->auth_method, pincode, pinlen);
  354|    319|	card = p15card->card;
  355|       |
  356|    319|	if (pinlen > SC_MAX_PIN_SIZE) {
  ------------------
  |  |   40|    319|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (356:6): [True: 0, False: 319]
  ------------------
  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|    319|	memset(&data, 0, sizeof(data));
  364|    319|	data.pin_type = auth_info->auth_method;
  365|       |
  366|    319|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    319|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (366:6): [True: 319, False: 0]
  ------------------
  367|    319|		data.pin_reference = auth_info->attrs.pin.reference;
  368|    319|		data.pin1.min_length = auth_info->attrs.pin.min_length;
  369|    319|		data.pin1.max_length = auth_info->attrs.pin.max_length;
  370|    319|		data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  371|    319|		data.pin1.pad_char = auth_info->attrs.pin.pad_char;
  372|    319|		data.pin1.data = pincode;
  373|    319|		data.pin1.len = pinlen;
  374|       |
  375|    319|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    319|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (375:7): [True: 176, False: 143]
  ------------------
  376|    176|			data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    176|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  377|       |
  378|    319|		switch (auth_info->attrs.pin.type) {
  379|      4|		case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      4|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (379:3): [True: 4, False: 315]
  ------------------
  380|      4|			data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      4|#define SC_PIN_ENCODING_BCD	1
  ------------------
  381|      4|			break;
  382|    284|		case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    284|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (382:3): [True: 284, False: 35]
  ------------------
  383|    284|			data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    284|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  384|    284|			break;
  385|     31|		default:
  ------------------
  |  Branch (385:3): [True: 31, False: 288]
  ------------------
  386|       |			/* assume/hope the card driver knows how to encode the pin */
  387|     31|			data.pin1.encoding = 0;
  388|    319|		}
  389|    319|	}
  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|    319|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    638|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (406:7): [True: 0, False: 319]
  ------------------
  407|    319|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|    319|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (407:8): [True: 0, False: 319]
  ------------------
  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|    319|	if (card->caps & SC_CARD_CAP_SESSION_PIN && sessionpin && sessionpinlen) {
  ------------------
  |  |  563|    638|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (417:6): [True: 0, False: 319]
  |  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|    319|	} else {
  424|       |		/* perform a standard verify */
  425|    319|		data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|    319|#define SC_PIN_CMD_VERIFY	0
  ------------------
  426|    319|		if (sessionpinlen)
  ------------------
  |  Branch (426:7): [True: 0, False: 319]
  ------------------
  427|      0|			*sessionpinlen = 0;
  428|    319|	}
  429|       |
  430|    319|	r = sc_lock(card);
  431|    319|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    319|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    319|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    319|	int _ret = (r); \
  |  |  |  |  168|    319|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 319]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    319|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 319]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|       |	/* the path in the pin object is optional */
  434|    319|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (434:6): [True: 7, False: 312]
  |  Branch (434:35): [True: 9, False: 303]
  ------------------
  435|     16|		r = sc_select_file(card, &auth_info->path, NULL);
  436|     16|		if (r)
  ------------------
  |  Branch (436:7): [True: 10, False: 6]
  ------------------
  437|     10|			goto out;
  438|     16|	}
  439|       |
  440|    309|	r = sc_pin_cmd(card, &data);
  441|    309|	auth_info->tries_left = data.pin1.tries_left;
  442|    309|	sc_log(ctx, "PIN cmd result %i", r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  443|    309|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    309|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:6): [True: 98, False: 211]
  ------------------
  444|     98|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  445|     98|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    196|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (445:7): [True: 0, False: 98]
  |  Branch (445:49): [True: 0, False: 0]
  ------------------
  446|      0|			*sessionpinlen = data.pin2.len;
  447|      0|		}
  448|    211|	} else {
  449|    211|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  450|    211|				NOTIFY_PIN_BAD);
  451|    211|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    422|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (451:7): [True: 0, False: 211]
  |  Branch (451:49): [True: 0, False: 0]
  ------------------
  452|      0|			*sessionpinlen = 0;
  453|      0|		}
  454|    211|	}
  455|       |
  456|    309|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
  ------------------
  |  |   94|    618|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (456:6): [True: 309, False: 0]
  ------------------
  457|    309|			&& auth_info->auth_method != SC_AC_SESSION) {
  ------------------
  |  |  159|    309|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (457:7): [True: 309, False: 0]
  ------------------
  458|    309|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  459|    309|				r == SC_SUCCESS ? NOTIFY_PIN_GOOD : NOTIFY_PIN_BAD);
  ------------------
  |  |   28|    309|#define SC_SUCCESS				0
  ------------------
  |  Branch (459:5): [True: 98, False: 211]
  ------------------
  460|    309|	}
  461|       |
  462|    319|out:
  463|    319|	sc_unlock(card);
  464|    319|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    319|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    319|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    319|	int _ret = r; \
  |  |  |  |  155|    319|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 319, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    319|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    221|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 221, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  157|    319|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    319|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    319|	return _ret; \
  |  |  |  |  163|    319|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|    319|}
sc_pkcs15_change_pin:
  476|    118|{
  477|    118|	struct sc_context *ctx = p15card->card->ctx;
  478|    118|	struct sc_pin_cmd_data data;
  479|    118|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  480|    118|	struct sc_card *card;
  481|    118|	int r;
  482|       |
  483|    118|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|    118|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    118|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (484:6): [True: 0, False: 118]
  ------------------
  485|    118|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  486|       |
  487|       |	/* make sure the pins are in valid range */
  488|    118|	r = _validate_pin(p15card, auth_info, oldpinlen);
  489|    118|	LOG_TEST_RET(ctx, r, "Old PIN value do not conform PIN policy");
  ------------------
  |  |  174|    118|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    118|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    118|	int _ret = (r); \
  |  |  |  |  168|    118|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 104]
  |  |  |  |  ------------------
  |  |  |  |  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|    118|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 104]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|       |
  491|    104|	r = _validate_pin(p15card, auth_info, newpinlen);
  492|    104|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  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: 0, False: 104]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 104]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  493|       |
  494|    104|	card = p15card->card;
  495|    104|	r = sc_lock(card);
  496|    104|	LOG_TEST_RET(ctx, r, "sc_lock() 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: 0, False: 104]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 104]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  497|       |	/* the path in the pin object is optional */
  498|    104|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (498:6): [True: 4, False: 100]
  |  Branch (498:35): [True: 3, False: 97]
  ------------------
  499|      7|		r = sc_select_file(card, &auth_info->path, NULL);
  500|      7|		if (r)
  ------------------
  |  Branch (500:7): [True: 3, False: 4]
  ------------------
  501|      3|			goto out;
  502|      7|	}
  503|       |
  504|       |	/* set pin_cmd data */
  505|    101|	memset(&data, 0, sizeof(data));
  506|    101|	data.cmd             = SC_PIN_CMD_CHANGE;
  ------------------
  |  |  416|    101|#define SC_PIN_CMD_CHANGE	1
  ------------------
  507|    101|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|    101|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  508|    101|	data.pin_reference   = auth_info->attrs.pin.reference;
  509|    101|	data.pin1.data       = oldpin;
  510|    101|	data.pin1.len        = oldpinlen;
  511|    101|	data.pin1.pad_char   = auth_info->attrs.pin.pad_char;
  512|    101|	data.pin1.min_length = auth_info->attrs.pin.min_length;
  513|    101|	data.pin1.max_length = auth_info->attrs.pin.max_length;
  514|    101|	data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  515|    101|	data.pin2.data       = newpin;
  516|    101|	data.pin2.len        = newpinlen;
  517|    101|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  518|    101|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  519|    101|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  520|    101|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  521|       |
  522|    101|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    101|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (522:6): [True: 43, False: 58]
  ------------------
  523|     43|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     43|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  524|       |
  525|    101|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (525:10): [True: 99, False: 2]
  ------------------
  526|      0|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (526:2): [True: 0, False: 101]
  ------------------
  527|      0|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  528|      0|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  529|      0|		break;
  530|     99|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|     99|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (530:2): [True: 99, False: 2]
  ------------------
  531|     99|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     99|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  532|     99|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     99|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  533|     99|		break;
  534|    101|	}
  535|       |
  536|    101|	if((!oldpin || !newpin)
  ------------------
  |  Branch (536:6): [True: 0, False: 101]
  |  Branch (536:17): [True: 0, False: 101]
  ------------------
  537|      0|			&& (p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (537:8): [True: 0, False: 0]
  ------------------
  538|      0|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|      0|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (538:8): [True: 0, False: 0]
  ------------------
  539|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  540|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (540:7): [True: 0, False: 0]
  ------------------
  541|      0|			data.pin1.prompt = "Please enter SO PIN";
  542|      0|			data.pin2.prompt = "Please enter new SO PIN";
  543|      0|		}
  544|      0|		else {
  545|      0|			data.pin1.prompt = "Please enter PIN";
  546|      0|			data.pin2.prompt = "Please enter new PIN";
  547|      0|		}
  548|      0|	}
  549|       |
  550|    101|	r = sc_pin_cmd(card, &data);
  551|    101|	auth_info->tries_left = data.pin1.tries_left;
  552|    101|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    101|#define SC_SUCCESS				0
  ------------------
  |  Branch (552:6): [True: 6, False: 95]
  ------------------
  553|      6|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  554|       |
  555|    104|out:
  556|    104|	sc_unlock(card);
  557|    104|	return r;
  558|    101|}
sc_pkcs15_get_pin_info:
  689|    930|{
  690|    930|	int r;
  691|    930|	struct sc_pin_cmd_data data;
  692|    930|	struct sc_card *card = p15card->card;
  693|    930|	struct sc_context *ctx = card->ctx;
  694|    930|	struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *) pin_obj->data;
  695|       |
  696|    930|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    930|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    930|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    930|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    930|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 930]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  697|       |
  698|    930|	r = sc_lock(card);
  699|    930|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    930|#define SC_SUCCESS				0
  ------------------
  |  Branch (699:6): [True: 0, False: 930]
  ------------------
  700|      0|		return r;
  701|       |
  702|    930|	if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    930|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (702:6): [True: 0, False: 930]
  ------------------
  703|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  704|      0|		goto out;
  705|      0|	}
  706|       |
  707|       |	/* the path in the pin object is optional */
  708|    930|	if ((pin_info->path.len > 0) || ((pin_info->path.aid.len > 0))) {
  ------------------
  |  Branch (708:6): [True: 59, False: 871]
  |  Branch (708:34): [True: 53, False: 818]
  ------------------
  709|    112|		r = sc_select_file(card, &pin_info->path, NULL);
  710|    112|		if (r)
  ------------------
  |  Branch (710:7): [True: 97, False: 15]
  ------------------
  711|     97|			goto out;
  712|    112|	}
  713|       |
  714|       |	/* Try to update PIN info from card */
  715|    833|	memset(&data, 0, sizeof(data));
  716|    833|	data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    833|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  717|    833|	data.pin_type = pin_info->auth_method;
  718|    833|	data.pin_reference = pin_info->attrs.pin.reference;
  719|       |
  720|    833|	r = sc_pin_cmd(card, &data);
  721|    833|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    833|#define SC_SUCCESS				0
  ------------------
  |  Branch (721:6): [True: 235, False: 598]
  ------------------
  722|    235|		if (data.pin1.max_tries > 0)
  ------------------
  |  Branch (722:7): [True: 1, False: 234]
  ------------------
  723|      1|			pin_info->max_tries = data.pin1.max_tries;
  724|    235|		pin_info->tries_left = data.pin1.tries_left;
  725|    235|		pin_info->logged_in = data.pin1.logged_in;
  726|    235|	}
  727|       |
  728|    930|out:
  729|    930|	sc_unlock(card);
  730|    930|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    930|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    930|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    930|	int _ret = r; \
  |  |  |  |  155|    930|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 930, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    930|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    695|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 695, False: 235]
  |  |  |  |  ------------------
  |  |  |  |  157|    930|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    930|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    930|	return _ret; \
  |  |  |  |  163|    930|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|    930|}
sc_pkcs15_free_auth_info:
  735|  6.11k|{
  736|  6.11k|	free(auth_info);
  737|  6.11k|}
sc_pkcs15_pincache_add:
  743|    197|{
  744|    197|	struct sc_context *ctx = p15card->card->ctx;
  745|    197|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  746|    197|	struct sc_pkcs15_object *obj = NULL;
  747|    197|	int r;
  748|       |
  749|    197|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    197|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    197|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    197|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    197|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 197]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  750|       |
  751|    197|	if (!pin || !pinlen)   {
  ------------------
  |  Branch (751:6): [True: 0, False: 197]
  |  Branch (751:14): [True: 0, False: 197]
  ------------------
  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|    197|	else if (!p15card->opts.use_pin_cache)   {
  ------------------
  |  Branch (755:11): [True: 2, False: 195]
  ------------------
  756|      2|		sc_log(ctx, "PIN caching not enabled");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  757|      2|		return;
  758|      2|	}
  759|    195|	else if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    195|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (759:11): [True: 0, False: 195]
  ------------------
  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|    195|	obj = p15card->obj_list;
  767|  2.91k|	while (obj != NULL) {
  ------------------
  |  Branch (767:9): [True: 2.72k, False: 189]
  ------------------
  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.72k|		if (sc_pkcs15_compare_id(&obj->auth_id, &auth_info->auth_id)) {
  ------------------
  |  Branch (773:7): [True: 267, False: 2.46k]
  ------------------
  774|       |			/* Caching is refused, if the protected object requires user consent */
  775|    267|			if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (775:8): [True: 267, False: 0]
  ------------------
  776|    267|				if (obj->user_consent > 0) {
  ------------------
  |  Branch (776:9): [True: 6, False: 261]
  ------------------
  777|      6|					sc_log(ctx, "caching refused (user consent)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  778|      6|					return;
  779|      6|				}
  780|    267|			}
  781|    267|		}
  782|       |
  783|  2.72k|		obj = obj->next;
  784|  2.72k|	}
  785|       |
  786|    189|	r = sc_pkcs15_allocate_object_content(ctx, pin_obj, pin, pinlen);
  787|    189|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|    189|#define SC_SUCCESS				0
  ------------------
  |  Branch (787:6): [True: 0, False: 189]
  ------------------
  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|    189|	pin_obj->usage_counter = 0;
  793|    189|	sc_log(ctx, "PIN(%s) cached", pin_obj->label);
  ------------------
  |  |   71|    189|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  794|    189|}
sc_pkcs15_pincache_revalidate:
  799|     10|{
  800|     10|	struct sc_context *ctx = p15card->card->ctx;
  801|     10|	sc_pkcs15_object_t *pin_obj;
  802|     10|	int r;
  803|       |
  804|     10|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     10|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     10|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     10|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     10|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  805|     10|	if (!p15card->opts.use_pin_cache)
  ------------------
  |  Branch (805:6): [True: 0, False: 10]
  ------------------
  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|     10|	if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (810:6): [True: 10, False: 0]
  ------------------
  811|     10|	    if (obj->user_consent)
  ------------------
  |  Branch (811:10): [True: 0, False: 10]
  ------------------
  812|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  813|     10|	}
  814|       |
  815|     10|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|     20|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (815:7): [True: 0, False: 10]
  ------------------
  816|     10|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  560|     10|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (816:8): [True: 0, False: 10]
  ------------------
  817|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  818|       |
  819|     10|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &obj->auth_id, &pin_obj);
  820|     10|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  |  Branch (820:6): [True: 0, False: 10]
  ------------------
  821|      0|		sc_log(ctx, "Could not find pin object for auth_id %s", sc_pkcs15_print_id(&obj->auth_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__
  |  |  ------------------
  ------------------
  822|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  823|      0|	}
  824|       |
  825|     10|	if (pin_obj->usage_counter >= p15card->opts.pin_cache_counter) {
  ------------------
  |  Branch (825:6): [True: 0, False: 10]
  ------------------
  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|     10|	if (!pin_obj->content.value || !pin_obj->content.len)
  ------------------
  |  Branch (830:6): [True: 1, False: 9]
  |  Branch (830:33): [True: 0, False: 9]
  ------------------
  831|      1|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      1|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  832|       |
  833|      9|	pin_obj->usage_counter++;
  834|      9|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  835|      9|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      9|#define SC_SUCCESS				0
  ------------------
  |  Branch (835:6): [True: 4, False: 5]
  ------------------
  836|       |		/* Ensure that wrong PIN isn't used again */
  837|      4|		sc_pkcs15_free_object_content(pin_obj);
  838|       |
  839|      4|		sc_log(ctx, "Verify PIN error %i", r);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  840|      4|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      4|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  841|      4|	}
  842|       |
  843|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  844|      5|}
sc_pkcs15_pincache_clear:
  847|  6.43k|{
  848|  6.43k|	struct sc_pkcs15_object *objs[32];
  849|  6.43k|	int i, r;
  850|       |
  851|  6.43k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  6.43k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.43k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.43k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.43k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.43k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  852|  6.43k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|  6.43k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  853|  13.0k|	for (i = 0; i < r; i++)
  ------------------
  |  Branch (853:14): [True: 6.63k, False: 6.43k]
  ------------------
  854|  6.63k|		sc_pkcs15_free_object_content(objs[i]);
  855|  6.43k|}
pkcs15-pin.c:_validate_pin:
  261|    697|{
  262|    697|	size_t max_length;
  263|    697|	if (p15card == NULL) {
  ------------------
  |  Branch (263:6): [True: 0, False: 697]
  ------------------
  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|    697|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    697|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (268:6): [True: 0, False: 697]
  ------------------
  269|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  270|       |
  271|       |	/* prevent buffer overflow from hostile card */
  272|    697|	if (auth_info->attrs.pin.stored_length > SC_MAX_PIN_SIZE)
  ------------------
  |  |   40|    697|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (272:6): [True: 0, False: 697]
  ------------------
  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|    697|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|  1.39k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (276:7): [True: 0, False: 697]
  ------------------
  277|    697|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    697|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (277:8): [True: 0, False: 697]
  ------------------
  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|    697|	max_length = auth_info->attrs.pin.max_length != 0 ? auth_info->attrs.pin.max_length : SC_MAX_PIN_SIZE;
  ------------------
  |  |   40|    697|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (282:15): [True: 697, False: 0]
  ------------------
  283|    697|	if (pinlen > max_length || pinlen < auth_info->attrs.pin.min_length)
  ------------------
  |  Branch (283:6): [True: 34, False: 663]
  |  Branch (283:29): [True: 145, False: 518]
  ------------------
  284|    179|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|    179|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  285|       |
  286|    518|	return SC_SUCCESS;
  ------------------
  |  |   28|    518|#define SC_SUCCESS				0
  ------------------
  287|    697|}

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

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

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

sc_pkcs15_decode_pukdf_entry:
  202|      8|{
  203|      8|	struct sc_context *ctx = p15card->card->ctx;
  204|      8|	struct sc_pkcs15_pubkey_info *info;
  205|      8|	int r, gostr3410_params[3];
  206|      8|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  207|      8|	size_t usage_len, af_len;
  208|      8|	struct sc_pkcs15_der *der = &obj->content;
  209|      8|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  210|      8|	struct sc_asn1_entry asn1_com_pubkey_attr[C_ASN1_COM_PUBKEY_ATTR_SIZE];
  211|      8|	struct sc_asn1_entry asn1_rsakey_value_choice[C_ASN1_RSAKEY_VALUE_CHOICE_SIZE];
  212|      8|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  213|      8|	struct sc_asn1_entry asn1_rsa_type_attr[C_ASN1_RSA_TYPE_ATTR_SIZE];
  214|      8|	struct sc_asn1_entry asn1_eckey_value_choice[C_ASN1_ECKEY_VALUE_CHOICE_SIZE];
  215|      8|	struct sc_asn1_entry asn1_eckey_attr[C_ASN1_ECKEY_ATTR_SIZE];
  216|      8|	struct sc_asn1_entry asn1_ec_type_attr[C_ASN1_EC_TYPE_ATTR_SIZE];
  217|      8|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOST3410KEY_ATTR_SIZE];
  218|      8|	struct sc_asn1_entry asn1_gostr3410_type_attr[C_ASN1_GOST3410_TYPE_ATTR_SIZE];
  219|      8|	struct sc_asn1_entry asn1_pubkey_choice[C_ASN1_PUBKEY_CHOICE_SIZE];
  220|      8|	struct sc_asn1_entry asn1_pubkey[C_ASN1_PUBKEY_SIZE];
  221|      8|	struct sc_asn1_pkcs15_object rsakey_obj = { obj, asn1_com_key_attr,
  222|      8|			asn1_com_pubkey_attr, asn1_rsa_type_attr };
  223|      8|	struct sc_asn1_pkcs15_object eckey_obj = { obj, asn1_com_key_attr,
  224|      8|			asn1_com_pubkey_attr, asn1_ec_type_attr };
  225|      8|	struct sc_asn1_pkcs15_object gostr3410key_obj =  { obj, asn1_com_key_attr,
  226|      8|			asn1_com_pubkey_attr, asn1_gostr3410_type_attr };
  227|       |
  228|      8|	info = calloc(1, sizeof *info);
  229|      8|	if (info == NULL) {
  ------------------
  |  Branch (229:6): [True: 0, False: 8]
  ------------------
  230|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  231|      0|		goto err;
  232|      0|	}
  233|      8|	usage_len = sizeof(info->usage);
  234|      8|	af_len = sizeof(info->access_flags);
  235|       |
  236|      8|	sc_copy_asn1_entry(c_asn1_pubkey, asn1_pubkey);
  237|      8|	sc_copy_asn1_entry(c_asn1_pubkey_choice, asn1_pubkey_choice);
  238|      8|	sc_copy_asn1_entry(c_asn1_rsa_type_attr, asn1_rsa_type_attr);
  239|      8|	sc_copy_asn1_entry(c_asn1_rsakey_value_choice, asn1_rsakey_value_choice);
  240|      8|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  241|      8|	sc_copy_asn1_entry(c_asn1_ec_type_attr, asn1_ec_type_attr);
  242|      8|	sc_copy_asn1_entry(c_asn1_eckey_value_choice, asn1_eckey_value_choice);
  243|      8|	sc_copy_asn1_entry(c_asn1_eckey_attr, asn1_eckey_attr);
  244|      8|	sc_copy_asn1_entry(c_asn1_gostr3410_type_attr, asn1_gostr3410_type_attr);
  245|      8|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  246|      8|	sc_copy_asn1_entry(c_asn1_com_pubkey_attr, asn1_com_pubkey_attr);
  247|      8|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  248|       |
  249|      8|	sc_format_asn1_entry(asn1_com_pubkey_attr + 0, &info->subject.value, &info->subject.len, 0);
  250|       |
  251|      8|	sc_format_asn1_entry(asn1_pubkey_choice + 0, &rsakey_obj, NULL, 0);
  252|      8|	sc_format_asn1_entry(asn1_pubkey_choice + 1, &gostr3410key_obj, NULL, 0);
  253|      8|	sc_format_asn1_entry(asn1_pubkey_choice + 2, &eckey_obj, NULL, 0);
  254|       |
  255|      8|	sc_format_asn1_entry(asn1_rsa_type_attr + 0, asn1_rsakey_attr, NULL, 0);
  256|       |
  257|      8|	sc_format_asn1_entry(asn1_rsakey_value_choice + 0, &info->path, NULL, 0);
  258|      8|	sc_format_asn1_entry(asn1_rsakey_value_choice + 1, &der->value, &der->len, 0);
  259|       |
  260|      8|	sc_format_asn1_entry(asn1_rsakey_attr + 0, asn1_rsakey_value_choice, NULL, 0);
  261|      8|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info->modulus_length, NULL, 0);
  262|       |
  263|      8|	sc_format_asn1_entry(asn1_ec_type_attr + 0, asn1_eckey_attr, NULL, 0);
  264|       |
  265|      8|	sc_format_asn1_entry(asn1_eckey_value_choice + 0, &info->path, NULL, 0);
  266|      8|	sc_format_asn1_entry(asn1_eckey_value_choice + 1, &der->value, &der->len, 0);
  267|       |
  268|      8|	sc_format_asn1_entry(asn1_eckey_attr + 0, asn1_eckey_value_choice, NULL, 0);
  269|       |
  270|      8|	sc_format_asn1_entry(asn1_gostr3410_type_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  271|       |
  272|      8|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info->path, NULL, 0);
  273|      8|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  274|      8|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  275|      8|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  276|       |
  277|      8|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info->id, NULL, 0);
  278|      8|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info->usage, &usage_len, 0);
  279|      8|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info->native, NULL, 0);
  280|      8|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info->access_flags, &af_len, 0);
  281|      8|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info->key_reference, NULL, 0);
  282|       |
  283|      8|	sc_format_asn1_entry(asn1_pubkey + 0, asn1_pubkey_choice, NULL, 0);
  284|       |
  285|       |	/* Fill in defaults */
  286|      8|	info->key_reference = -1;
  287|      8|	info->native = 1;
  288|      8|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  289|       |
  290|      8|	r = sc_asn1_decode(ctx, asn1_pubkey, *buf, *buflen, buf, buflen);
  291|      8|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      8|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (291:6): [True: 3, False: 5]
  ------------------
  292|      3|		goto err;
  293|      5|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|      0|	if (asn1_pubkey_choice[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (294:6): [True: 0, False: 0]
  ------------------
  295|      0|		obj->type = SC_PKCS15_TYPE_PUBKEY_RSA;
  ------------------
  |  |  426|      0|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  296|      0|	} else if (asn1_pubkey_choice[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (296:13): [True: 0, False: 0]
  ------------------
  297|      0|		obj->type = SC_PKCS15_TYPE_PUBKEY_GOSTR3410;
  ------------------
  |  |  427|      0|#define SC_PKCS15_TYPE_PUBKEY_GOSTR3410		0x203
  ------------------
  298|      0|		if (info->modulus_length != 0)
  ------------------
  |  Branch (298:7): [True: 0, False: 0]
  ------------------
  299|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  300|      0|		info->modulus_length = SC_PKCS15_GOSTR3410_KEYSIZE;
  ------------------
  |  |  326|      0|#define SC_PKCS15_GOSTR3410_KEYSIZE             256
  ------------------
  301|      0|		if (info->params.len != 0)
  ------------------
  |  Branch (301:7): [True: 0, False: 0]
  ------------------
  302|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  303|      0|		info->params.len = sizeof(struct sc_pkcs15_keyinfo_gostparams);
  304|      0|		info->params.data = malloc(info->params.len);
  305|      0|		if (info->params.data == NULL) {
  ------------------
  |  Branch (305:7): [True: 0, False: 0]
  ------------------
  306|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  307|      0|			goto err;
  308|      0|		}
  309|      0|		if (sizeof(*keyinfo_gostparams) != info->params.len)
  ------------------
  |  Branch (309:7): [True: 0, False: 0]
  ------------------
  310|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  311|      0|		keyinfo_gostparams = info->params.data;
  312|      0|		keyinfo_gostparams->gostr3410 = (unsigned int)gostr3410_params[0];
  313|      0|		keyinfo_gostparams->gostr3411 = (unsigned int)gostr3410_params[1];
  314|      0|		keyinfo_gostparams->gost28147 = (unsigned int)gostr3410_params[2];
  315|      0|	}
  316|      0|	else if (asn1_pubkey_choice[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (316:11): [True: 0, False: 0]
  ------------------
  317|      0|		obj->type = SC_PKCS15_TYPE_PUBKEY_EC;
  ------------------
  |  |  428|      0|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  318|      0|	}
  319|      0|	else {
  320|      0|		goto err;
  321|      0|	}
  322|       |
  323|      0|	if (!p15card->app || !p15card->app->ddo.aid.len) {
  ------------------
  |  Branch (323:6): [True: 0, False: 0]
  |  Branch (323:23): [True: 0, False: 0]
  ------------------
  324|      0|		if (!p15card->file_app) {
  ------------------
  |  Branch (324:7): [True: 0, False: 0]
  ------------------
  325|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  326|      0|			goto err;
  327|      0|		}
  328|      0|		r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info->path);
  329|      0|		if (r < 0) {
  ------------------
  |  Branch (329:7): [True: 0, False: 0]
  ------------------
  330|      0|			goto err;
  331|      0|		}
  332|      0|	}
  333|      0|	else   {
  334|      0|		info->path.aid = p15card->app->ddo.aid;
  335|      0|	}
  336|      0|	sc_log(ctx, "PubKey path '%s'", sc_print_path(&info->path));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  337|       |
  338|       |	/* OpenSC 0.11.4 and older encoded "keyReference" as a negative
  339|       |	   value. Fixed in 0.11.5 we need to add a hack, so old cards
  340|       |	   continue to work. */
  341|      0|	if (info->key_reference < -1)
  ------------------
  |  Branch (341:6): [True: 0, False: 0]
  ------------------
  342|      0|		info->key_reference += 256;
  343|       |
  344|      0|	obj->data = info;
  345|      0|	info = NULL;
  346|       |
  347|      0|	r = sc_pkcs15_decode_pubkey_direct_value(p15card, obj);
  348|      0|	if (r < 0) {
  ------------------
  |  Branch (348:6): [True: 0, False: 0]
  ------------------
  349|      0|		info = obj->data;
  350|      0|		obj->data = NULL;
  351|      0|	}
  352|      0|	LOG_TEST_GOTO_ERR(ctx, r, "Decode public key direct value failed");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|       |
  354|      8|err:
  355|      8|	if (r < 0) {
  ------------------
  |  Branch (355:6): [True: 8, False: 0]
  ------------------
  356|      8|		sc_pkcs15_free_pubkey_info(info);
  357|      8|		if (der->len) {
  ------------------
  |  Branch (357:7): [True: 0, False: 8]
  ------------------
  358|      0|			free(der->value);
  359|       |			/* der points to obj->content */
  360|      0|			obj->content.value = NULL;
  361|      0|			obj->content.len = 0;
  362|      0|		}
  363|      8|	}
  364|       |
  365|      8|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      8|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      8|	int _ret = r; \
  |  |  |  |  155|      8|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      8|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      8|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  366|      8|}
sc_pkcs15_decode_pubkey_rsa:
  563|    197|{
  564|    197|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  565|    197|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  566|    197|	int r;
  567|       |
  568|    197|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    197|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    197|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    197|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    197|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 197]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|    197|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  570|    197|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 0);
  571|       |
  572|    197|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  573|    197|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, &key->modulus.data, &key->modulus.len, 0);
  574|    197|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, &key->exponent.data, &key->exponent.len, 0);
  575|       |
  576|    197|	r = sc_asn1_decode(ctx, asn1_public_key, buf, buflen, NULL, NULL);
  577|    197|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of public key failed");
  ------------------
  |  |  174|    197|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    197|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    197|	int _ret = (r); \
  |  |  |  |  168|    197|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 174]
  |  |  |  |  ------------------
  |  |  |  |  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|    197|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 174]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|       |
  579|    174|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    174|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    174|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    174|	int _ret = r; \
  |  |  |  |  155|    174|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 174, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    174|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 174]
  |  |  |  |  ------------------
  |  |  |  |  157|    174|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    174|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    174|	return _ret; \
  |  |  |  |  163|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|    174|}
sc_pkcs15_encode_pubkey_rsa:
  586|    184|{
  587|    184|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  588|    184|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  589|    184|	int r;
  590|       |
  591|    184|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    184|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    184|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    184|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    184|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|    184|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  593|    184|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 1);
  594|       |
  595|    184|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  596|    184|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, key->modulus.data, &key->modulus.len, 1);
  597|    184|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, key->exponent.data, &key->exponent.len, 1);
  598|       |
  599|    184|	r = sc_asn1_encode(ctx, asn1_public_key, buf, buflen);
  600|    184|	LOG_TEST_RET(ctx, r, "ASN.1 encoding failed");
  ------------------
  |  |  174|    184|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    184|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    184|	int _ret = (r); \
  |  |  |  |  168|    184|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 167]
  |  |  |  |  ------------------
  |  |  |  |  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|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 167]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  601|       |
  602|    167|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 167]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  603|    167|}
sc_pkcs15_encode_pubkey:
  769|     83|{
  770|     83|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|     83|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (770:6): [True: 83, False: 0]
  ------------------
  771|     83|		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|  1.04k|{
  802|  1.04k|	int r = 0;
  803|  1.04k|	struct sc_asn1_entry  asn1_spki_key[2], asn1_spki_key_items[3];
  804|  1.04k|	struct sc_pkcs15_u8 pkey;
  805|  1.04k|	size_t key_len;
  806|       |
  807|  1.04k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.04k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.04k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  808|  1.04k|	pkey.value =  NULL;
  809|  1.04k|	pkey.len = 0;
  810|       |
  811|  1.04k|	sc_log(ctx, "Encoding public key with algorithm %lu", pubkey->algorithm);
  ------------------
  |  |   71|  1.04k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  812|  1.04k|	if (!pubkey->alg_id)   {
  ------------------
  |  Branch (812:6): [True: 1, False: 1.04k]
  ------------------
  813|      1|		pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
  814|      1|		if (!pubkey->alg_id)
  ------------------
  |  Branch (814:7): [True: 0, False: 1]
  ------------------
  815|      1|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  816|       |
  817|      1|		sc_init_oid(&pubkey->alg_id->oid);
  818|      1|		pubkey->alg_id->algorithm = pubkey->algorithm;
  819|      1|	}
  820|       |
  821|  1.04k|	switch (pubkey->algorithm) {
  822|    962|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|    962|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (822:2): [True: 962, False: 83]
  ------------------
  823|    962|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|    962|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (823:2): [True: 0, False: 1.04k]
  ------------------
  824|    962|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|    962|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (824:2): [True: 0, False: 1.04k]
  ------------------
  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|    962|		key_len = pubkey->u.ec.ecpointQ.len * 8;
  831|    962|		pkey.value = pubkey->u.ec.ecpointQ.value;
  832|    962|		pkey.len = 0; /* flag as do not delete */
  833|       |
  834|    962|		if (pubkey->u.ec.params.named_curve || pubkey->u.ec.params.der.value)   {
  ------------------
  |  Branch (834:7): [True: 960, False: 2]
  |  Branch (834:42): [True: 0, False: 2]
  ------------------
  835|    960|			struct sc_ec_parameters *ec_params = NULL;
  836|       |
  837|    960|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
  838|    960|			LOG_TEST_RET(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  174|    960|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    960|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    960|	int _ret = (r); \
  |  |  |  |  168|    960|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 960]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    960|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 960]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|       |			/* EDDSA and XEDDSA only have algo and no param in SPKI */
  841|    960|			if (pubkey->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|    960|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (841:8): [True: 960, False: 0]
  ------------------
  842|    960|				ec_params = calloc(1, sizeof(struct sc_ec_parameters));
  843|    960|				if (!ec_params)
  ------------------
  |  Branch (843:9): [True: 0, False: 960]
  ------------------
  844|    960|					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|    960|				ec_params->type = 1;
  846|    960|				ec_params->der.value = calloc(1, pubkey->u.ec.params.der.len);
  847|    960|				if (!ec_params->der.value) {
  ------------------
  |  Branch (847:9): [True: 0, False: 960]
  ------------------
  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|    960|				memcpy(ec_params->der.value, pubkey->u.ec.params.der.value, pubkey->u.ec.params.der.len);
  852|    960|				ec_params->der.len = pubkey->u.ec.params.der.len;
  853|    960|			}
  854|       |			/* This could have been already allocated: avoid memory leak */
  855|    960|			sc_asn1_clear_algorithm_id(pubkey->alg_id);
  856|    960|			pubkey->alg_id->params = ec_params; /* NULL for EDDSA and XEDDSA */
  857|    960|		}
  858|    962|		break;
  859|    962|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (859:2): [True: 0, False: 1.04k]
  ------------------
  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|     83|	default:
  ------------------
  |  Branch (865:2): [True: 83, False: 962]
  ------------------
  866|     83|		r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
  867|     83|		key_len = pkey.len * 8;
  868|     83|		break;
  869|  1.04k|	}
  870|       |
  871|  1.04k|	if (r == 0) {
  ------------------
  |  Branch (871:6): [True: 1.03k, False: 14]
  ------------------
  872|  1.03k|		sc_copy_asn1_entry(c_asn1_spki_key, asn1_spki_key);
  873|  1.03k|		sc_copy_asn1_entry(c_asn1_spki_key_items, asn1_spki_key_items);
  874|  1.03k|		sc_format_asn1_entry(asn1_spki_key + 0, asn1_spki_key_items, NULL, 1);
  875|  1.03k|		sc_format_asn1_entry(asn1_spki_key_items + 0, pubkey->alg_id, NULL, 1);
  876|  1.03k|		sc_format_asn1_entry(asn1_spki_key_items + 1, pkey.value, &key_len, 1);
  877|       |
  878|  1.03k|		r =  sc_asn1_encode(ctx, asn1_spki_key, buf, len);
  879|  1.03k|	}
  880|       |
  881|       |	/*  pkey.len == 0 is flag to not delete */
  882|  1.04k|	if (pkey.len && pkey.value)
  ------------------
  |  Branch (882:6): [True: 69, False: 976]
  |  Branch (882:18): [True: 69, False: 0]
  ------------------
  883|     69|		free(pkey.value);
  884|       |
  885|  1.04k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  1.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.04k|	int _ret = r; \
  |  |  |  |  155|  1.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.04k|	return _ret; \
  |  |  |  |  163|  1.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|  1.04k|}
sc_pkcs15_decode_pubkey:
  892|    228|{
  893|    228|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    228|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (893:6): [True: 197, False: 31]
  ------------------
  894|    197|		return sc_pkcs15_decode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
  895|     31|	if (key->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   71|     31|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (895:6): [True: 0, False: 31]
  ------------------
  896|      0|		return sc_pkcs15_decode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
  897|     31|	if (key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|     31|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (897:6): [True: 0, False: 31]
  ------------------
  898|      0|		return sc_pkcs15_decode_pubkey_ec(ctx, &key->u.ec, buf, len);
  899|     31|	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   72|     62|#define SC_ALGORITHM_EDDSA		4
  ------------------
              	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     31|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (899:6): [True: 0, False: 31]
  |  Branch (899:46): [True: 0, False: 31]
  ------------------
  900|      0|		return sc_pkcs15_decode_pubkey_eddsa(ctx, &key->u.ec, buf, len);
  901|       |
  902|     31|	sc_log(ctx, "Decoding of public key type %lu not supported", key->algorithm);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  903|     31|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     31|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  904|     31|}
sc_pkcs15_read_pubkey:
  913|     56|{
  914|     56|	struct sc_context *ctx;
  915|     56|	const struct sc_pkcs15_pubkey_info *info = NULL;
  916|     56|	struct sc_pkcs15_pubkey *pubkey = NULL;
  917|     56|	unsigned char *data = NULL;
  918|     56|	size_t	len;
  919|     56|	int	algorithm, r;
  920|     56|	int	private_obj;
  921|       |
  922|     56|	if (p15card == NULL || p15card->card == NULL || p15card->card->ops == NULL
  ------------------
  |  Branch (922:6): [True: 0, False: 56]
  |  Branch (922:25): [True: 0, False: 56]
  |  Branch (922:50): [True: 0, False: 56]
  ------------------
  923|     56|			|| obj == NULL || out == NULL) {
  ------------------
  |  Branch (923:7): [True: 0, False: 56]
  |  Branch (923:22): [True: 0, False: 56]
  ------------------
  924|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  925|      0|	}
  926|     56|	ctx = p15card->card->ctx;
  927|       |
  928|     56|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     56|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  929|     56|	sc_log(ctx, "Public key type 0x%X", obj->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  930|       |
  931|     56|	switch (obj->type) {
  932|     56|	case SC_PKCS15_TYPE_PUBKEY_RSA:
  ------------------
  |  |  426|     56|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  |  Branch (932:2): [True: 56, False: 0]
  ------------------
  933|     56|		algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|     56|#define SC_ALGORITHM_RSA		0
  ------------------
  934|     56|		break;
  935|      0|	case SC_PKCS15_TYPE_PUBKEY_GOSTR3410:
  ------------------
  |  |  427|      0|#define SC_PKCS15_TYPE_PUBKEY_GOSTR3410		0x203
  ------------------
  |  Branch (935:2): [True: 0, False: 56]
  ------------------
  936|      0|		algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  937|      0|		break;
  938|      0|	case SC_PKCS15_TYPE_PUBKEY_EC:
  ------------------
  |  |  428|      0|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  |  Branch (938:2): [True: 0, False: 56]
  ------------------
  939|      0|		algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  940|      0|		break;
  941|      0|	case SC_PKCS15_TYPE_PUBKEY_EDDSA:
  ------------------
  |  |  429|      0|#define SC_PKCS15_TYPE_PUBKEY_EDDSA		0x205
  ------------------
  |  Branch (941:2): [True: 0, False: 56]
  ------------------
  942|      0|		algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  943|      0|		break;
  944|      0|	case SC_PKCS15_TYPE_PUBKEY_XEDDSA:
  ------------------
  |  |  430|      0|#define SC_PKCS15_TYPE_PUBKEY_XEDDSA		0x206
  ------------------
  |  Branch (944:2): [True: 0, False: 56]
  ------------------
  945|      0|		algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  946|      0|		break;
  947|      0|	default:
  ------------------
  |  Branch (947:2): [True: 0, False: 56]
  ------------------
  948|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported public key 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  949|     56|	}
  950|     56|	info = (const struct sc_pkcs15_pubkey_info *) obj->data;
  951|       |
  952|     56|	pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey));
  953|     56|	if (pubkey == NULL) {
  ------------------
  |  Branch (953:6): [True: 0, False: 56]
  ------------------
  954|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  955|      0|	}
  956|     56|	pubkey->algorithm = algorithm;
  957|       |
  958|       |	/* starting from SPKI direct value
  959|       |	   in a compact form it presents complete public key data */
  960|     56|	if (info->direct.spki.value && info->direct.spki.len)   {
  ------------------
  |  Branch (960:6): [True: 0, False: 56]
  |  Branch (960:33): [True: 0, False: 0]
  ------------------
  961|      0|		sc_log(ctx, "Using direct SPKI value,  tag 0x%X", *(info->direct.spki.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__
  |  |  ------------------
  ------------------
  962|      0|		r = sc_pkcs15_pubkey_from_spki_sequence(ctx, info->direct.spki.value, info->direct.spki.len, &pubkey);
  963|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Failed to decode 'SPKI' direct value");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  964|      0|	}
  965|     56|	else if (info->direct.raw.value && info->direct.raw.len)   {
  ------------------
  |  Branch (965:11): [True: 0, False: 56]
  |  Branch (965:37): [True: 0, False: 0]
  ------------------
  966|      0|		sc_log(ctx, "Using direct RAW 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__
  |  |  ------------------
  ------------------
  967|      0|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, info->direct.raw.value, info->direct.raw.len);
  968|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Failed to decode 'RAW' direct value");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  969|      0|		sc_log(ctx, "TODO: for EC keys 'raw' data needs to be completed with referenced algorithm from TokenInfo");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  970|      0|	}
  971|     56|	else if (obj->content.value && obj->content.len)   {
  ------------------
  |  Branch (971:11): [True: 0, False: 56]
  |  Branch (971:33): [True: 0, False: 0]
  ------------------
  972|      0|		sc_log(ctx, "Using 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__
  |  |  ------------------
  ------------------
  973|      0|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, obj->content.value, obj->content.len);
  974|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Failed to decode object content value");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  975|      0|		sc_log(ctx, "TODO: for EC keys 'raw' data needs to be completed with referenced algorithm from TokenInfo");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  976|      0|	}
  977|     56|	else if (p15card->card->ops->read_public_key)   {
  ------------------
  |  Branch (977:11): [True: 0, False: 56]
  ------------------
  978|      0|		sc_log(ctx, "Call card specific 'read-public-key' handle");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  979|      0|		r = p15card->card->ops->read_public_key(p15card->card, algorithm,
  980|      0|				(struct sc_path *)&info->path, info->key_reference, (unsigned)info->modulus_length,
  981|      0|				&data, &len);
  982|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Card specific 'read-public' procedure 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  983|       |
  984|      0|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, data, len);
  985|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Decode 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  986|      0|	}
  987|     56|	else if (info->path.len)   {
  ------------------
  |  Branch (987:11): [True: 56, False: 0]
  ------------------
  988|     56|		sc_log(ctx, "Read from EF and decode");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  989|     56|		private_obj = obj->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     56|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  990|     56|		r = sc_pkcs15_read_file(p15card, &info->path, &data, &len, private_obj);
  991|     56|		LOG_TEST_GOTO_ERR(ctx, r, "Failed to read public key file.");
  ------------------
  |  |  184|     56|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     56|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     56|	int _ret = (r); \
  |  |  |  |  178|     56|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 42, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  992|       |
  993|     14|		if ((algorithm == SC_ALGORITHM_EC || algorithm == SC_ALGORITHM_EDDSA || algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   70|     28|#define SC_ALGORITHM_EC		2
  ------------------
              		if ((algorithm == SC_ALGORITHM_EC || algorithm == SC_ALGORITHM_EDDSA || algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   72|     28|#define SC_ALGORITHM_EDDSA		4
  ------------------
              		if ((algorithm == SC_ALGORITHM_EC || algorithm == SC_ALGORITHM_EDDSA || algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     14|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (993:8): [True: 0, False: 14]
  |  Branch (993:40): [True: 0, False: 14]
  |  Branch (993:75): [True: 0, False: 14]
  ------------------
  994|      0|				&& len > 0 && *data == (SC_ASN1_TAG_SEQUENCE | SC_ASN1_TAG_CONSTRUCTED))
  ------------------
  |  |  206|      0|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              				&& len > 0 && *data == (SC_ASN1_TAG_SEQUENCE | SC_ASN1_TAG_CONSTRUCTED))
  ------------------
  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (994:8): [True: 0, False: 0]
  |  Branch (994:19): [True: 0, False: 0]
  ------------------
  995|      0|			r = sc_pkcs15_pubkey_from_spki_sequence(ctx, data, len, &pubkey);
  996|     14|		else
  997|     14|			r = sc_pkcs15_decode_pubkey(ctx, pubkey, data, len);
  998|     14|		LOG_TEST_GOTO_ERR(ctx, r, "Decode public key error");
  ------------------
  |  |  184|     14|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     14|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     14|	int _ret = (r); \
  |  |  |  |  178|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 13, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  179|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     13|		goto err; \
  |  |  |  |  182|     13|	} \
  |  |  |  |  183|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  999|     14|	}
 1000|      0|	else {
 1001|      0|		r = SC_ERROR_NOT_IMPLEMENTED;
  ------------------
  |  |   97|      0|#define SC_ERROR_NOT_IMPLEMENTED		-1416
  ------------------
 1002|      0|		LOG_TEST_GOTO_ERR(ctx, r, "No way to get public key");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1003|      0|	}
 1004|       |
 1005|     56|err:
 1006|     56|	if (r) {
  ------------------
  |  Branch (1006:6): [True: 55, False: 1]
  ------------------
 1007|     55|		sc_pkcs15_free_pubkey(pubkey);
 1008|     55|	} else
 1009|      1|		*out = pubkey;
 1010|     56|	free(data);
 1011|       |
 1012|     56|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     56|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     56|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     56|	int _ret = r; \
  |  |  |  |  155|     56|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 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|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 55, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1013|     56|}
sc_pkcs15_dup_pubkey:
 1092|  2.03k|{
 1093|  2.03k|	struct sc_pkcs15_pubkey *pubkey = NULL;
 1094|  2.03k|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|  2.03k|#define SC_SUCCESS				0
  ------------------
 1095|  2.03k|	u8* alg;
 1096|  2.03k|	size_t alglen;
 1097|       |
 1098|  2.03k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.03k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.03k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1099|       |
 1100|  2.03k|	if (!key || !out) {
  ------------------
  |  Branch (1100:6): [True: 0, False: 2.03k]
  |  Branch (1100:14): [True: 0, False: 2.03k]
  ------------------
 1101|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1102|      0|	}
 1103|       |
 1104|  2.03k|	*out = NULL;
 1105|  2.03k|	pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey));
 1106|  2.03k|	if (!pubkey)
  ------------------
  |  Branch (1106:6): [True: 0, False: 2.03k]
  ------------------
 1107|  2.03k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1108|       |
 1109|  2.03k|	pubkey->algorithm = key->algorithm;
 1110|       |
 1111|  2.03k|	if (key->alg_id) {
  ------------------
  |  Branch (1111:6): [True: 2.03k, False: 0]
  ------------------
 1112|  2.03k|		rv = sc_asn1_encode_algorithm_id(ctx, &alg, &alglen,key->alg_id, 0);
 1113|  2.03k|		if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|  2.03k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1113:7): [True: 2.03k, False: 0]
  ------------------
 1114|  2.03k|			pubkey->alg_id = (struct sc_algorithm_id *)calloc(1, sizeof(struct sc_algorithm_id));
 1115|  2.03k|			if (pubkey->alg_id == NULL) {
  ------------------
  |  Branch (1115:8): [True: 0, False: 2.03k]
  ------------------
 1116|      0|				free(pubkey);
 1117|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1118|      0|			}
 1119|  2.03k|			rv = sc_asn1_decode_algorithm_id(ctx, alg, alglen, pubkey->alg_id, 0);
 1120|  2.03k|			free(alg);
 1121|  2.03k|		}
 1122|  2.03k|	}
 1123|       |
 1124|  2.03k|	switch (key->algorithm) {
 1125|    120|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    120|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1125:2): [True: 120, False: 1.91k]
  ------------------
 1126|    120|		rv = sc_pkcs15_dup_bignum(&pubkey->u.rsa.modulus, &key->u.rsa.modulus);
 1127|    120|		if (!rv)
  ------------------
  |  Branch (1127:7): [True: 120, False: 0]
  ------------------
 1128|    120|			rv = sc_pkcs15_dup_bignum(&pubkey->u.rsa.exponent, &key->u.rsa.exponent);
 1129|    120|		break;
 1130|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (1130:2): [True: 0, False: 2.03k]
  ------------------
 1131|      0|		break;
 1132|  1.91k|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|  1.91k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1132:2): [True: 1.91k, False: 120]
  ------------------
 1133|  1.91k|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|  1.91k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1133:2): [True: 0, False: 2.03k]
  ------------------
 1134|  1.91k|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|  1.91k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1134:2): [True: 0, False: 2.03k]
  ------------------
 1135|  1.91k|		pubkey->u.ec.ecpointQ.value = malloc(key->u.ec.ecpointQ.len);
 1136|  1.91k|		if (!pubkey->u.ec.ecpointQ.value) {
  ------------------
  |  Branch (1136:7): [True: 0, False: 1.91k]
  ------------------
 1137|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1138|      0|			break;
 1139|      0|		}
 1140|  1.91k|		memcpy(pubkey->u.ec.ecpointQ.value, key->u.ec.ecpointQ.value, key->u.ec.ecpointQ.len);
 1141|  1.91k|		pubkey->u.ec.ecpointQ.len = key->u.ec.ecpointQ.len;
 1142|       |
 1143|  1.91k|		if (key->u.ec.params.named_curve) {
  ------------------
  |  Branch (1143:7): [True: 1.91k, False: 4]
  ------------------
 1144|  1.91k|			rv = sc_pkcs15_fix_ec_parameters(ctx, &key->u.ec.params);
 1145|  1.91k|			if (rv)
  ------------------
  |  Branch (1145:8): [True: 0, False: 1.91k]
  ------------------
 1146|      0|				break;
 1147|  1.91k|		}
 1148|       |
 1149|  1.91k|		pubkey->u.ec.params.der.value = malloc(key->u.ec.params.der.len);
 1150|  1.91k|		if (!pubkey->u.ec.params.der.value) {
  ------------------
  |  Branch (1150:7): [True: 0, False: 1.91k]
  ------------------
 1151|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|      0|			break;
 1153|      0|		}
 1154|  1.91k|		memcpy(pubkey->u.ec.params.der.value, key->u.ec.params.der.value, key->u.ec.params.der.len);
 1155|  1.91k|		pubkey->u.ec.params.der.len = key->u.ec.params.der.len;
 1156|       |
 1157|       |		/* RFC4810 no named_curve */
 1158|  1.91k|		if ((key->algorithm != SC_ALGORITHM_EDDSA) && (key->algorithm != SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   72|  1.91k|#define SC_ALGORITHM_EDDSA		4
  ------------------
              		if ((key->algorithm != SC_ALGORITHM_EDDSA) && (key->algorithm != SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|  1.91k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1158:7): [True: 1.91k, False: 0]
  |  Branch (1158:49): [True: 1.91k, False: 0]
  ------------------
 1159|  1.91k|			if (key->u.ec.params.named_curve) {
  ------------------
  |  Branch (1159:8): [True: 1.91k, False: 4]
  ------------------
 1160|  1.91k|				pubkey->u.ec.params.named_curve = strdup(key->u.ec.params.named_curve);
 1161|  1.91k|				if (!pubkey->u.ec.params.named_curve)
  ------------------
  |  Branch (1161:9): [True: 0, False: 1.91k]
  ------------------
 1162|      0|					rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1163|  1.91k|			} else {
 1164|      4|				sc_log(ctx, "named_curve parameter missing");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1165|      4|				rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      4|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1166|      4|			}
 1167|  1.91k|		}
 1168|       |
 1169|  1.91k|		break;
 1170|      0|	default:
  ------------------
  |  Branch (1170:2): [True: 0, False: 2.03k]
  ------------------
 1171|      0|		sc_log(ctx, "Unsupported private 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__
  |  |  ------------------
  ------------------
 1172|      0|		rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1173|  2.03k|	}
 1174|       |
 1175|  2.03k|	if (rv)
  ------------------
  |  Branch (1175:6): [True: 4, False: 2.03k]
  ------------------
 1176|      4|		sc_pkcs15_free_pubkey(pubkey);
 1177|  2.03k|	else
 1178|  2.03k|		*out = pubkey;
 1179|       |
 1180|  2.03k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.03k|	int _ret = r; \
  |  |  |  |  155|  2.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.03k|	return _ret; \
  |  |  |  |  163|  2.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|  2.03k|}
sc_pkcs15_erase_pubkey:
 1187|  5.99k|{
 1188|  5.99k|	if (key == NULL) {
  ------------------
  |  Branch (1188:6): [True: 0, False: 5.99k]
  ------------------
 1189|      0|		return;
 1190|      0|	}
 1191|  5.99k|	if (key->alg_id) {
  ------------------
  |  Branch (1191:6): [True: 4.35k, False: 1.63k]
  ------------------
 1192|  4.35k|		sc_asn1_clear_algorithm_id(key->alg_id);
 1193|  4.35k|		free(key->alg_id);
 1194|  4.35k|	}
 1195|  5.99k|	switch (key->algorithm) {
  ------------------
  |  Branch (1195:10): [True: 5.95k, False: 42]
  ------------------
 1196|  1.94k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|  1.94k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1196:2): [True: 1.94k, False: 4.05k]
  ------------------
 1197|  1.94k|		free(key->u.rsa.modulus.data);
 1198|  1.94k|		free(key->u.rsa.exponent.data);
 1199|  1.94k|		break;
 1200|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (1200:2): [True: 0, False: 5.99k]
  ------------------
 1201|      0|		free(key->u.gostr3410.xy.data);
 1202|      0|		break;
 1203|  4.01k|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|  4.01k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1203:2): [True: 4.01k, False: 1.98k]
  ------------------
 1204|  4.01k|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|  4.01k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1204:2): [True: 0, False: 5.99k]
  ------------------
 1205|  4.01k|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|  4.01k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1205:2): [True: 0, False: 5.99k]
  ------------------
 1206|  4.01k|		free(key->u.ec.params.der.value);
 1207|  4.01k|		free(key->u.ec.params.named_curve);
 1208|  4.01k|		free(key->u.ec.ecpointQ.value);
 1209|  4.01k|		break;
 1210|  5.99k|	}
 1211|  5.99k|	sc_mem_clear(key, sizeof(*key));
 1212|  5.99k|}
sc_pkcs15_free_pubkey:
 1217|  11.0k|{
 1218|  11.0k|	if (!key)
  ------------------
  |  Branch (1218:6): [True: 5.08k, False: 5.99k]
  ------------------
 1219|  5.08k|		return;
 1220|  5.99k|	sc_pkcs15_erase_pubkey(key);
 1221|  5.99k|	free(key);
 1222|  5.99k|}
sc_pkcs15_free_pubkey_info:
 1227|  1.17k|{
 1228|  1.17k|	if (info) {
  ------------------
  |  Branch (1228:6): [True: 1.17k, False: 0]
  ------------------
 1229|  1.17k|		free(info->subject.value);
 1230|  1.17k|		free(info->direct.spki.value);
 1231|  1.17k|		free(info->direct.raw.value);
 1232|  1.17k|		sc_pkcs15_free_key_params(&info->params);
 1233|  1.17k|		free(info);
 1234|  1.17k|	}
 1235|  1.17k|}
sc_pkcs15_pubkey_from_spki_fields:
 1326|  2.48k|{
 1327|       |
 1328|  2.48k|	struct sc_pkcs15_pubkey *pubkey = NULL;
 1329|  2.48k|	struct sc_pkcs15_der pk = { NULL, 0 };
 1330|  2.48k|	struct sc_algorithm_id pk_alg;
 1331|  2.48k|	struct sc_asn1_entry asn1_pkinfo[C_ASN1_PKINFO_ATTR_SIZE];
 1332|  2.48k|	unsigned char *tmp_buf = NULL;
 1333|  2.48k|	int r;
 1334|       |
 1335|  2.48k|	sc_log(ctx, "sc_pkcs15_pubkey_from_spki_fields() called: %p:%zu\n%s",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1336|  2.48k|			buf, buflen, sc_dump_hex(buf, buflen));
 1337|       |
 1338|  2.48k|	if (buflen < 1) {
  ------------------
  |  Branch (1338:6): [True: 11, False: 2.47k]
  ------------------
 1339|     11|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "subjectPublicKeyInfo can not be empty");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1340|     11|	}
 1341|       |
 1342|  2.47k|	tmp_buf = malloc(buflen);
 1343|  2.47k|	if (!tmp_buf) {
  ------------------
  |  Branch (1343:6): [True: 0, False: 2.47k]
  ------------------
 1344|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1345|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|      0|	}
 1347|  2.47k|	memcpy(tmp_buf, buf, buflen);
 1348|       |
 1349|  2.47k|	if (buflen > 0 && (*tmp_buf & SC_ASN1_TAG_CONTEXT))
  ------------------
  |  |  187|  2.47k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (1349:6): [True: 2.47k, False: 0]
  |  Branch (1349:20): [True: 72, False: 2.40k]
  ------------------
 1350|     72|		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  190|     72|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
              		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  206|     72|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
 1351|       |
 1352|  2.47k|	memset(&pk_alg, 0, sizeof(pk_alg));
 1353|  2.47k|	pubkey = calloc(1, sizeof(sc_pkcs15_pubkey_t));
 1354|  2.47k|	if (pubkey == NULL) {
  ------------------
  |  Branch (1354:6): [True: 0, False: 2.47k]
  ------------------
 1355|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1356|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1357|      0|	}
 1358|       |
 1359|  2.47k|	sc_copy_asn1_entry(c_asn1_pkinfo, asn1_pkinfo);
 1360|       |
 1361|  2.47k|	sc_format_asn1_entry(asn1_pkinfo + 0, &pk_alg, NULL, 0);
 1362|  2.47k|	sc_format_asn1_entry(asn1_pkinfo + 1, &pk.value, &pk.len, 0);
 1363|       |
 1364|  2.47k|	r = sc_asn1_decode(ctx, asn1_pkinfo, tmp_buf, buflen, NULL, NULL);
 1365|  2.47k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.47k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1365:6): [True: 155, False: 2.32k]
  ------------------
 1366|    155|		sc_asn1_clear_algorithm_id(&pk_alg);
 1367|    155|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo 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: 155, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    155|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    155|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    155|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    155|		goto err; \
  |  |  |  |  182|    155|	} \
  |  |  |  |  183|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1368|    155|	}
 1369|       |
 1370|  2.32k|	pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
 1371|  2.32k|	if (pubkey->alg_id == NULL) {
  ------------------
  |  Branch (1371:6): [True: 0, False: 2.32k]
  ------------------
 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|  2.32k|	memcpy(pubkey->alg_id, &pk_alg, sizeof(struct sc_algorithm_id));
 1377|  2.32k|	pubkey->algorithm = pk_alg.algorithm;
 1378|  2.32k|	pk_alg.params = NULL;
 1379|  2.32k|	sc_log(ctx, "DEE pk_alg.algorithm=%lu", pk_alg.algorithm);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
 1380|       |
 1381|  2.32k|	if (pk.len == 0)
  ------------------
  |  Branch (1381:6): [True: 15, False: 2.30k]
  ------------------
 1382|  2.32k|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INTERNAL, "Incorrect length of key");
  ------------------
  |  |  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: 15, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|  2.30k|	pk.len = BYTES4BITS(pk.len); /* convert number of bits to bytes */
  ------------------
  |  |  146|  2.30k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 1384|       |
 1385|  2.30k|	if (pk_alg.algorithm == SC_ALGORITHM_EC)   {
  ------------------
  |  |   70|  2.30k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1385:6): [True: 2.09k, False: 214]
  ------------------
 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|  2.09k|		pubkey->u.ec.params.field_length = (pk.len - 1) / 2 * 8;
 1392|       |
 1393|  2.09k|		if (pubkey->alg_id->params) {
  ------------------
  |  Branch (1393:7): [True: 2.08k, False: 7]
  ------------------
 1394|  2.08k|			struct sc_ec_parameters *ecp = (struct sc_ec_parameters *)pubkey->alg_id->params;
 1395|       |
 1396|  2.08k|			pubkey->u.ec.params.der.value = malloc(ecp->der.len);
 1397|  2.08k|			if (pubkey->u.ec.params.der.value == NULL) {
  ------------------
  |  Branch (1397:8): [True: 0, False: 2.08k]
  ------------------
 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|  2.08k|			memcpy(pubkey->u.ec.params.der.value, ecp->der.value, ecp->der.len);
 1403|  2.08k|			pubkey->u.ec.params.der.len = ecp->der.len;
 1404|  2.08k|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1405|  2.08k|			LOG_TEST_GOTO_ERR(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  184|  2.08k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.08k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.08k|	int _ret = (r); \
  |  |  |  |  178|  2.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 53, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  179|     53|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     53|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     53|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     53|		goto err; \
  |  |  |  |  182|     53|	} \
  |  |  |  |  183|  2.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1406|  2.08k|		}
 1407|       |
 1408|  2.04k|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1409|  2.04k|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1409:7): [True: 0, False: 2.04k]
  ------------------
 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|  2.04k|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1414|  2.04k|		pubkey->u.ec.ecpointQ.len = pk.len;
 1415|  2.04k|	} else if (pk_alg.algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|    428|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1415:13): [True: 0, False: 214]
  ------------------
 1416|    214|		   pk_alg.algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|    214|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1416:6): [True: 0, False: 214]
  ------------------
 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|    214|	} else {
 1436|       |		/* Public key is expected to be encapsulated into BIT STRING */
 1437|    214|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, pk.value, pk.len);
 1438|    214|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|    214|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    214|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    214|	int _ret = (r); \
  |  |  |  |  178|    214|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 41, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     41|		goto err; \
  |  |  |  |  182|     41|	} \
  |  |  |  |  183|    214|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 173]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1439|    214|	}
 1440|       |
 1441|  2.21k|	*outpubkey = pubkey;
 1442|  2.21k|	pubkey = NULL;
 1443|       |
 1444|  2.47k|err:
 1445|  2.47k|	sc_pkcs15_free_pubkey(pubkey);
 1446|  2.47k|	free(pk.value);
 1447|  2.47k|	free(tmp_buf);
 1448|       |
 1449|  2.47k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  2.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.47k|	int _ret = r; \
  |  |  |  |  155|  2.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    249|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 249, False: 2.22k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.47k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.47k|	return _ret; \
  |  |  |  |  163|  2.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1450|  2.47k|}
sc_pkcs15_fix_ec_parameters:
 1564|  7.97k|{
 1565|  7.97k|	int rv, ii;
 1566|  7.97k|	int mapped_string = 0; /* der is printable string that can be replaced with der of OID */
 1567|       |
 1568|  7.97k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  7.97k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.97k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.97k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.97k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.97k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1569|       |
 1570|       |	/* In PKCS#11 EC parameters arrives in DER encoded form */
 1571|  7.97k|	if (ecparams->der.value && ecparams->der.len && ecparams->der.len > 2) {
  ------------------
  |  Branch (1571:6): [True: 7.97k, False: 0]
  |  Branch (1571:29): [True: 7.97k, False: 0]
  |  Branch (1571:50): [True: 7.97k, False: 0]
  ------------------
 1572|       |
 1573|  7.97k|		switch (ecparams->der.value[0]) {
 1574|  7.96k|		case 0x06: /* der.value is an OID */
  ------------------
  |  Branch (1574:3): [True: 7.96k, False: 10]
  ------------------
 1575|  70.1k|			for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1575:17): [True: 70.0k, False: 43]
  ------------------
 1576|  70.0k|				size_t len = ec_curve_infos[ii].oid_der.len;
 1577|       |
 1578|  70.0k|				if (ecparams->der.len == len &&
  ------------------
  |  Branch (1578:9): [True: 35.7k, False: 34.2k]
  ------------------
 1579|  35.7k|						memcmp(ecparams->der.value, ec_curve_infos[ii].oid_der.value, len) == 0)
  ------------------
  |  Branch (1579:7): [True: 7.92k, False: 27.8k]
  ------------------
 1580|  7.92k|					break; /* found ec_curve_infos[ii] */
 1581|  70.0k|			}
 1582|  7.96k|			break;
 1583|       |
 1584|      0|		case 0x13:
  ------------------
  |  Branch (1584:3): [True: 0, False: 7.97k]
  ------------------
 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|     10|		default:
  ------------------
  |  Branch (1609:3): [True: 10, False: 7.96k]
  ------------------
 1610|     10|			sc_log(ctx, "Unsupported ec params");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1611|     10|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1612|  7.97k|		}
 1613|       |
 1614|  7.96k|		if (ec_curve_infos[ii].name == NULL) /* end of ec_curve_info */
  ------------------
  |  Branch (1614:7): [True: 43, False: 7.92k]
  ------------------
 1615|  7.96k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported named curve");
  ------------------
  |  |  174|     43|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     43|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     43|	int _ret = (r); \
  |  |  |  |  168|     43|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     43|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     43|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     43|		return _ret; \
  |  |  |  |  172|     43|	} \
  |  |  |  |  173|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1616|       |
 1617|       |		/* ii points to entry with matching oid_der or a mapped entry with replacement oid_der */
 1618|  7.92k|		sc_log(ctx, "Found known curve '%s'", ec_curve_infos[ii].name);
  ------------------
  |  |   71|  7.92k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1619|  7.92k|		if (mapped_string) { /* free previous name if any replace below with new name */
  ------------------
  |  Branch (1619:7): [True: 0, False: 7.92k]
  ------------------
 1620|      0|			free(ecparams->named_curve);
 1621|      0|			ecparams->named_curve = NULL;
 1622|      0|		}
 1623|       |
 1624|  7.92k|		if (!ecparams->named_curve) { /* if present,keep the name as some curves have multiple names */
  ------------------
  |  Branch (1624:7): [True: 5.05k, False: 2.87k]
  ------------------
 1625|  5.05k|			ecparams->named_curve = strdup(ec_curve_infos[ii].name);
 1626|  5.05k|			if (!ecparams->named_curve)
  ------------------
  |  Branch (1626:8): [True: 0, False: 5.05k]
  ------------------
 1627|  5.05k|				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|  5.05k|			sc_log(ctx, "Curve name: '%s'", ecparams->named_curve);
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1630|  5.05k|		}
 1631|       |
 1632|       |		/* fill in object_id based on oid_der */
 1633|  7.92k|		sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1634|       |
 1635|  7.92k|		ecparams->field_length = ec_curve_infos[ii].size;
 1636|  7.92k|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1637|  7.92k|		sc_log(ctx, "Curve length %zu key_type %d", ecparams->field_length, ecparams->key_type);
  ------------------
  |  |   71|  7.92k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1638|  7.92k|		if (mapped_string) {
  ------------------
  |  Branch (1638:7): [True: 0, False: 7.92k]
  ------------------
 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|  7.92k|	} 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|  7.92k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  7.92k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.92k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.92k|	int _ret = r; \
  |  |  |  |  155|  7.92k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.92k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.92k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7.92k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.92k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.92k|	return _ret; \
  |  |  |  |  163|  7.92k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1681|  7.92k|}
pkcs15-pubkey.c:sc_pkcs15_dup_bignum:
 1018|    240|{
 1019|    240|	if (!dst || !src) {
  ------------------
  |  Branch (1019:6): [True: 0, False: 240]
  |  Branch (1019:14): [True: 0, False: 240]
  ------------------
 1020|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1021|      0|	}
 1022|       |
 1023|    240|	if (src->data && src->len)   {
  ------------------
  |  Branch (1023:6): [True: 240, False: 0]
  |  Branch (1023:19): [True: 240, False: 0]
  ------------------
 1024|    240|		dst->data = calloc(1, src->len);
 1025|    240|		if (!dst->data)
  ------------------
  |  Branch (1025:7): [True: 0, False: 240]
  ------------------
 1026|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1027|    240|		memcpy(dst->data, src->data, src->len);
 1028|    240|		dst->len = src->len;
 1029|    240|	}
 1030|       |
 1031|    240|	return 0;
 1032|    240|}

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

sc_pkcs15_decipher:
  283|    185|{
  284|    185|	sc_context_t *ctx = p15card->card->ctx;
  285|    185|	int r;
  286|    185|	sc_algorithm_info_t *alg_info = NULL;
  287|    185|	sc_security_env_t senv;
  288|    185|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  289|    185|	unsigned long pad_flags = 0, sec_flags = 0;
  290|       |
  291|    185|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    185|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    185|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    185|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    185|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|       |
  293|    185|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|    185|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|    185|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (293:6): [True: 0, False: 185]
  ------------------
  294|    185|		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|    185|	r = format_senv(p15card, obj, &senv, &alg_info);
  297|    185|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    185|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    185|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    185|	int _ret = (r); \
  |  |  |  |  168|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 174]
  |  |  |  |  ------------------
  |  |  |  |  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|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 174]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|    174|	senv.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   47|    174|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  299|       |
  300|    174|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  301|    174|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|    174|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    174|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    174|	int _ret = (r); \
  |  |  |  |  168|    174|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 174]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 174]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|    174|	senv.algorithm_flags = sec_flags;
  303|       |
  304|    174|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  305|    174|			outlen);
  306|    174|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|    174|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    174|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    174|	int _ret = (r); \
  |  |  |  |  168|    174|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 82, False: 92]
  |  |  |  |  ------------------
  |  |  |  |  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|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 92]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Strip any padding */
  309|     92|	if (pad_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 (309:6): [True: 72, False: 20]
  ------------------
  310|     72|		unsigned int s = r;
  311|     72|		unsigned int key_size = (unsigned int)alg_info->key_length;
  312|     72|		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|     72|	}
  315|     20|#ifdef ENABLE_OPENSSL
  316|     20|	else if (pad_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  108|     20|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (316:11): [True: 0, False: 20]
  ------------------
  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|     92|#endif
  334|       |	/* do not log error code to prevent side channel attack */
  335|     92|	return r;
  336|     92|}
sc_pkcs15_compute_signature:
  597|    235|{
  598|    235|	sc_context_t *ctx = p15card->card->ctx;
  599|    235|	int r;
  600|    235|	sc_security_env_t senv;
  601|    235|	sc_algorithm_info_t *alg_info;
  602|    235|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  603|    235|	u8 *buf = NULL, *tmp;
  604|    235|	size_t modlen = 0, buflen = 0;
  605|    235|	unsigned long pad_flags = 0, sec_flags = 0;
  606|       |
  607|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|    235|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  307|    235|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|    235|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  |  Branch (609:6): [True: 0, False: 235]
  ------------------
  610|    235|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)))
  ------------------
  |  |  314|    235|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  611|    235|		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|    235|	r = format_senv(p15card, obj, &senv, &alg_info);
  614|    235|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  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: 10, False: 225]
  |  |  |  |  ------------------
  |  |  |  |  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|    235|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 225]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|    225|	senv.operation = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|    225|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  616|       |
  617|    225|	switch (obj->type) {
  618|    201|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    201|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (618:3): [True: 201, False: 24]
  ------------------
  619|    201|			modlen = BYTES4BITS(prkey->modulus_length);
  ------------------
  |  |  146|    201|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  620|    201|			break;
  621|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (621:3): [True: 0, False: 225]
  ------------------
  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|     24|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     24|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (624:3): [True: 24, False: 201]
  ------------------
  625|     24|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|     24|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (625:3): [True: 0, False: 225]
  ------------------
  626|     24|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|     24|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (626:3): [True: 0, False: 225]
  ------------------
  627|     24|			modlen = BYTES4BITS(prkey->field_length) * 2;  /* 2*nLen */
  ------------------
  |  |  146|     24|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  628|     24|			break;
  629|      0|		default:
  ------------------
  |  Branch (629:3): [True: 0, False: 225]
  ------------------
  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|    225|	}
  632|       |
  633|       |	/* Probably never happens, but better make sure */
  634|    225|	if (outlen < modlen)
  ------------------
  |  Branch (634:6): [True: 0, False: 225]
  ------------------
  635|    225|		LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    225|	buflen = inlen + modlen;
  638|    225|	buf = sc_mem_secure_alloc(buflen);
  639|    225|	if (buf == NULL)
  ------------------
  |  Branch (639:6): [True: 0, False: 225]
  ------------------
  640|    225|		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|    225|	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|    225|	if (obj->type == SC_PKCS15_TYPE_PRKEY_GOSTR3410) {
  ------------------
  |  |  420|    225|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (646:6): [True: 0, False: 225]
  ------------------
  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|    225|	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|    225|	sc_log(ctx, "supported algorithm flags 0x%lX, private key usage 0x%X", alg_info->flags, prkey->usage);
  ------------------
  |  |   71|    225|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  661|    225|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|    225|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (661:6): [True: 201, False: 24]
  ------------------
  662|    201|		if ((alg_info->flags & SC_ALGORITHM_NEED_USAGE) &&
  ------------------
  |  |   95|    201|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  |  Branch (662:7): [True: 0, False: 201]
  ------------------
  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|    201|		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|    201|#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|    201|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (694:7): [True: 69, False: 132]
  ------------------
  695|     69|			!(alg_info->flags & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|     69|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (695:4): [True: 24, False: 45]
  ------------------
  696|     24|			!(alg_info->flags & SC_ALGORITHM_RSA_HASH_NONE) &&
  ------------------
  |  |  133|     24|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (696:4): [True: 0, False: 24]
  ------------------
  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|    201|	}
  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|    225|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC) {
  ------------------
  |  |  421|    225|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (715:6): [True: 24, False: 201]
  ------------------
  716|     24|		if ((alg_info->flags & SC_ALGORITHM_ECDSA_RAW)
  ------------------
  |  |  174|     24|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (716:7): [True: 24, False: 0]
  ------------------
  717|     24|				&& !(flags & SC_ALGORITHM_ECDSA_HASHES & alg_info->flags)) {
  ------------------
  |  |  181|     24|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     24|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     24|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     24|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     24|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     24|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     24|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     24|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     24|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     24|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (717:8): [True: 24, False: 0]
  ------------------
  718|     24|			sc_log(ctx, "ECDSA using SC_ALGORITHM_ECDSA_RAW flags before 0x%8.8lx", flags);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  719|     24|				flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|     24|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  720|     24|				flags &= ~SC_ALGORITHM_ECDSA_HASHES;
  ------------------
  |  |  181|     24|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     24|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     24|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     24|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     24|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     24|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     24|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     24|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     24|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     24|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|     24|		}
  722|     24|	}
  723|       |
  724|    225|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  725|    225|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    225|#define SC_SUCCESS				0
  ------------------
  |  Branch (725:6): [True: 0, False: 225]
  ------------------
  726|      0|		goto err;
  727|      0|	}
  728|       |	/* senv now has flags card or driver will do */
  729|    225|	senv.algorithm_flags = sec_flags;
  730|       |
  731|    225|	sc_log(ctx, "DEE flags:0x%8.8lx alg_info->flags:0x%8.8lx pad:0x%8.8lx sec:0x%8.8lx",
  ------------------
  |  |   71|    225|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  732|    225|		flags, alg_info->flags, pad_flags, sec_flags);
  733|       |
  734|       |	/* add the padding bytes (if necessary) */
  735|    225|	if (pad_flags != 0) {
  ------------------
  |  Branch (735:6): [True: 102, False: 123]
  ------------------
  736|    102|		size_t tmplen = buflen;
  737|       |
  738|       |		/* XXX Assuming RSA key here */
  739|    102|		r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
  740|    102|		    prkey->modulus_length, pMechanism);
  741|    102|		LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|    102|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    102|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    102|	int _ret = (r); \
  |  |  |  |  178|    102|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|    102|		inlen = tmplen;
  743|    102|	}
  744|    123|	else if ( senv.algorithm == SC_ALGORITHM_RSA &&
  ------------------
  |  |   69|    246|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (744:12): [True: 99, False: 24]
  ------------------
  745|     99|	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  103|     99|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
              	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  104|     99|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (745:12): [True: 10, False: 89]
  ------------------
  746|       |		/* Add zero-padding if input is shorter than the modulus */
  747|     10|		if (inlen < modlen) {
  ------------------
  |  Branch (747:7): [True: 9, False: 1]
  ------------------
  748|      9|			if (modlen > buflen) {
  ------------------
  |  Branch (748:8): [True: 0, False: 9]
  ------------------
  749|      0|				r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  750|      0|				goto err;
  751|      0|			}
  752|      9|			memmove(tmp+modlen-inlen, tmp, inlen);
  753|      9|			memset(tmp, 0, modlen-inlen);
  754|      9|		}
  755|     10|		inlen = modlen;
  756|     10|	}
  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|    113|	else if (senv.algorithm == SC_ALGORITHM_EC &&
  ------------------
  |  |   70|    226|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (763:11): [True: 24, False: 89]
  ------------------
  764|     24|			(senv.algorithm_flags & SC_ALGORITHM_ECDSA_HASHES) == 0) {
  ------------------
  |  |  181|     24|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     24|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     24|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     24|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     24|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     24|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     24|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     24|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     24|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     24|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     24|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (764:4): [True: 24, False: 0]
  ------------------
  765|     24|		inlen = MIN(inlen, BYTES4BITS(prkey->field_length));
  ------------------
  |  |   70|     24|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 2, False: 22]
  |  |  ------------------
  ------------------
  766|     24|	}
  767|       |
  768|       |
  769|    225|	r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen,
  770|    225|			out, outlen);
  771|    225|	LOG_TEST_GOTO_ERR(ctx, r, "use_key() failed");
  ------------------
  |  |  184|    225|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    225|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    225|	int _ret = (r); \
  |  |  |  |  178|    225|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 178, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    178|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    178|		goto err; \
  |  |  |  |  182|    178|	} \
  |  |  |  |  183|    225|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|       |
  773|       |	/* Some cards may return RSA signature as integer without leading zero bytes */
  774|       |	/* Already know outlen >= modlen and r >= 0 */
  775|     47|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA && (unsigned)r < modlen) {
  ------------------
  |  |  419|     94|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (775:6): [True: 47, False: 0]
  |  Branch (775:47): [True: 31, False: 16]
  ------------------
  776|     31|		memmove(out + modlen - r, out, r);
  777|     31|		memset(out, 0, modlen - r);
  778|     31|		r = (int)modlen;
  779|     31|	}
  780|       |
  781|    225|err:
  782|    225|	sc_mem_secure_clear_free(buf, buflen);
  ------------------
  |  | 1580|    225|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|    225|	sc_mem_clear(ptr, len); \
  |  | 1582|    225|	sc_mem_secure_free(ptr, len); \
  |  | 1583|    225|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 225]
  |  |  ------------------
  ------------------
  783|       |
  784|    225|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    225|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    225|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    225|	int _ret = r; \
  |  |  |  |  155|    225|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 178, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  156|    178|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    178|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 178, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    178|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    178|	} 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|    225|	return _ret; \
  |  |  |  |  163|    225|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|    225|}
pkcs15-sec.c:format_senv:
  175|    420|{
  176|    420|	sc_context_t *ctx = p15card->card->ctx;
  177|    420|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  178|    420|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
  179|       |
  180|    420|	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|    420|	memcpy(senv_out->supported_algos, &p15card->tokeninfo->supported_algos, sizeof(senv_out->supported_algos));
  185|       |
  186|    420|	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|    420|#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|    840|#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: 420, False: 0]
  |  Branch (186:75): [True: 0, False: 0]
  ------------------
  187|    420|		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|    420|	if (!prkey->native)
  ------------------
  |  Branch (190:6): [True: 0, False: 420]
  ------------------
  191|    420|		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|    420|	switch (obj->type) {
  194|    393|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    393|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (194:3): [True: 393, False: 27]
  ------------------
  195|    393|			*alg_info_out = sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
  196|    393|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (196:8): [True: 18, False: 375]
  ------------------
  197|     18|				sc_log(ctx, "Card does not support RSA with key length %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  198|     18|						prkey->modulus_length);
  199|     18|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|     18|			}
  201|    375|			senv_out->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|    375|#define SC_ALGORITHM_RSA		0
  ------------------
  202|    375|			senv_out->key_size_bits = prkey->modulus_length;
  203|    375|			break;
  204|       |
  205|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (205:3): [True: 0, False: 420]
  ------------------
  206|      0|			*alg_info_out = sc_card_find_gostr3410_alg(p15card->card, prkey->modulus_length);
  207|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (207:8): [True: 0, False: 0]
  ------------------
  208|      0|				sc_log(ctx, "Card does not support GOSTR3410 with key length %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  209|      0|						prkey->modulus_length);
  210|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|      0|			}
  212|      0|			senv_out->algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  213|      0|			senv_out->key_size_bits = prkey->modulus_length;
  214|      0|			break;
  215|       |
  216|      0|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|      0|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (216:3): [True: 0, False: 420]
  ------------------
  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: 420]
  ------------------
  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|     27|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     27|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (238:3): [True: 27, False: 393]
  ------------------
  239|     27|			*alg_info_out = sc_card_find_ec_alg(p15card->card, prkey->field_length, NULL);
  240|     27|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (240:8): [True: 3, False: 24]
  ------------------
  241|      3|				sc_log(ctx, "Card does not support EC with field_size %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__
  |  |  ------------------
  ------------------
  242|      3|						prkey->field_length);
  243|      3|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|      3|			}
  245|     24|			senv_out->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|     24|#define SC_ALGORITHM_EC		2
  ------------------
  246|     24|			senv_out->key_size_bits = prkey->field_length;
  247|       |
  248|     24|			senv_out->flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|     24|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  249|     24|			senv_out->algorithm_ref = prkey->field_length;
  250|     24|			break;
  251|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (251:3): [True: 0, False: 420]
  ------------------
  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: 420]
  ------------------
  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|    420|	}
  267|    399|	senv_out->flags |= SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   60|    399|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  268|       |
  269|       |	/* optional keyReference attribute (the default value is -1) */
  270|    399|	if (prkey->key_reference >= 0) {
  ------------------
  |  Branch (270:6): [True: 399, False: 0]
  ------------------
  271|    399|		senv_out->key_ref_len = 1;
  272|    399|		senv_out->key_ref[0] = prkey->key_reference & 0xFF;
  273|    399|		senv_out->flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   58|    399|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  274|    399|	}
  275|       |
  276|    399|	return SC_SUCCESS;
  ------------------
  |  |   28|    399|#define SC_SUCCESS				0
  ------------------
  277|    420|}
pkcs15-sec.c:use_key:
  133|    399|{
  134|    399|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    399|#define SC_SUCCESS				0
  ------------------
  135|    399|	int revalidated_cached_pin = 0;
  136|    399|	sc_path_t path;
  137|    399|	LOG_TEST_RET(p15card->card->ctx, get_file_path(obj, &path), "Failed to get key file path.");
  ------------------
  |  |  174|    399|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    399|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    399|	int _ret = (r); \
  |  |  |  |  168|    399|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 399]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    399|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 399]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|       |
  139|    399|	r = sc_lock(p15card->card);
  140|    399|	LOG_TEST_RET(p15card->card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    399|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    399|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    399|	int _ret = (r); \
  |  |  |  |  168|    399|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 399]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    399|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 399]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|    404|	do {
  143|    404|		if (path.len != 0 || path.aid.len != 0) {
  ------------------
  |  Branch (143:7): [True: 62, False: 342]
  |  Branch (143:24): [True: 2, False: 340]
  ------------------
  144|     64|			r = select_key_file(p15card, obj, senv);
  145|     64|			if (r < 0) {
  ------------------
  |  Branch (145:8): [True: 6, False: 58]
  ------------------
  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|     64|		}
  150|    404|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    404|#define SC_SUCCESS				0
  ------------------
  |  Branch (150:7): [True: 398, False: 6]
  ------------------
  151|    398|			r = sc_set_security_env(p15card->card, senv, 0);
  152|       |
  153|    404|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    404|#define SC_SUCCESS				0
  ------------------
  |  Branch (153:7): [True: 322, False: 82]
  ------------------
  154|    322|			r = card_command(p15card->card, in, inlen, out, outlen);
  155|       |
  156|    404|		if (revalidated_cached_pin)
  ------------------
  |  Branch (156:7): [True: 5, False: 399]
  ------------------
  157|       |			/* only re-validate once */
  158|      5|			break;
  159|    399|		if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|    399|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (159:7): [True: 10, False: 389]
  ------------------
  160|     10|			r = sc_pkcs15_pincache_revalidate(p15card, obj);
  161|     10|			if (r < 0)
  ------------------
  |  Branch (161:8): [True: 5, False: 5]
  ------------------
  162|      5|				break;
  163|      5|			revalidated_cached_pin = 1;
  164|      5|		}
  165|    399|	} while (revalidated_cached_pin);
  ------------------
  |  Branch (165:11): [True: 5, False: 389]
  ------------------
  166|       |
  167|    399|	sc_unlock(p15card->card);
  168|       |
  169|    399|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|    399|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    399|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    399|	int _ret = r; \
  |  |  |  |  155|    399|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 277, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  156|    277|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    260|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 260, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  157|    277|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    277|	} else { \
  |  |  |  |  159|    122|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    122|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    122|	} \
  |  |  |  |  162|    399|	return _ret; \
  |  |  |  |  163|    399|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|    399|}
pkcs15-sec.c:get_file_path:
   57|    463|{
   58|    463|	if (!path)
  ------------------
  |  Branch (58:6): [True: 0, False: 463]
  ------------------
   59|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   60|       |
   61|    463|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
   62|    463|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
   63|       |
   64|    463|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  416|    463|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  418|    463|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (64:6): [True: 463, False: 0]
  ------------------
   65|    463|		*path = prkey->path;
   66|    463|	}
   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|    463|	return SC_SUCCESS;
  ------------------
  |  |   28|    463|#define SC_SUCCESS				0
  ------------------
   74|    463|}
pkcs15-sec.c:select_key_file:
   80|     64|{
   81|     64|	sc_context_t *ctx = p15card->card->ctx;
   82|     64|	sc_path_t orig_path;
   83|     64|	sc_path_t path, file_id;
   84|     64|	int r;
   85|       |
   86|     64|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     64|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     64|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     64|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     64|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   87|       |
   88|     64|	LOG_TEST_RET(ctx, get_file_path(key, &orig_path), "Could not get key file path.");
  ------------------
  |  |  174|     64|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     64|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     64|	int _ret = (r); \
  |  |  |  |  168|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|     64|	memset(&path, 0, sizeof(sc_path_t));
   90|     64|	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|     64|	if (!orig_path.len && orig_path.aid.len) {
  ------------------
  |  Branch (96:6): [True: 2, False: 62]
  |  Branch (96:24): [True: 2, False: 0]
  ------------------
   97|       |		/* Private key is a SDO allocated in application DF */
   98|      2|		path = orig_path;
   99|      2|	}
  100|     62|	else if (orig_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 62]
  |  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|     62|	else if (orig_path.len > 2) {
  ------------------
  |  Branch (108:11): [True: 62, False: 0]
  ------------------
  109|     62|		path = orig_path;
  110|     62|		memcpy(file_id.value, orig_path.value + orig_path.len - 2, 2);
  111|     62|		file_id.len = 2;
  112|     62|		file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     62|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  113|     62|		senv->file_ref = file_id;
  114|     62|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|     62|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  115|     62|	}
  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|     64|	r = sc_select_file(p15card->card, &path, NULL);
  121|     64|	LOG_TEST_RET(ctx, r, "sc_select_file() failed");
  ------------------
  |  |  174|     64|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     64|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     64|	int _ret = (r); \
  |  |  |  |  168|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 58]
  |  |  |  |  ------------------
  |  |  |  |  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|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 58]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     58|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     58|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     58|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     58|	int _ret = r; \
  |  |  |  |  155|     58|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 58]
  |  |  |  |  ------------------
  |  |  |  |  157|     58|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     58|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     58|	return _ret; \
  |  |  |  |  163|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|     58|}

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

sc_pkcs15_decode_skdf_entry:
  102|      2|{
  103|      2|        struct sc_context *ctx = p15card->card->ctx;
  104|      2|        struct sc_pkcs15_skey_info info;
  105|      2|	int r, i, ii;
  106|      2|	size_t usage_len = sizeof(info.usage);
  107|      2|	size_t af_len = sizeof(info.access_flags);
  108|      2|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  109|      2|	struct sc_asn1_entry asn1_com_skey_attr[C_ASN1_COM_SKEY_ATTR_SIZE];
  110|      2|	struct sc_asn1_entry asn1_generic_skey_attr[C_ASN1_COM_SKEY_GENERIC_ATTR_SIZE];
  111|      2|	struct sc_asn1_entry asn1_generic_skey_value_attr[C_ASN1_COM_SKEY_GENERIC_VALUE_ATTR_SIZE];
  112|      2|	struct sc_asn1_entry asn1_skey_choice[C_ASN1_SKEY_CHOICE_SIZE];
  113|      2|	struct sc_asn1_entry asn1_skey[C_ASN1_SKEY_SIZE];
  114|      2|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  115|      2|	struct sc_asn1_pkcs15_object skey_des_obj = {
  116|      2|		obj, asn1_com_key_attr, asn1_com_skey_attr, asn1_generic_skey_attr
  117|      2|	};
  118|      2|	static const struct sc_object_id id_aes = { { 2, 16, 840, 1, 101, 3, 4, 1, -1 } };
  119|      2|	struct sc_object_id temp_oid;
  120|       |
  121|      2|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|      2|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      2|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      2|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2]
  |  |  ------------------
  ------------------
  122|       |
  123|      2|	sc_copy_asn1_entry(c_asn1_skey, asn1_skey);
  124|      2|	sc_copy_asn1_entry(c_asn1_skey_choice, asn1_skey_choice);
  125|      2|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  126|       |
  127|      2|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  128|      2|	sc_copy_asn1_entry(c_asn1_com_skey_attr, asn1_com_skey_attr);
  129|      2|	sc_copy_asn1_entry(c_asn1_generic_skey_attr, asn1_generic_skey_attr);
  130|      2|	sc_copy_asn1_entry(c_asn1_generic_skey_value_attr, asn1_generic_skey_value_attr);
  131|       |
  132|      2|	sc_format_asn1_entry(asn1_skey + 0, asn1_skey_choice, NULL, 0);
  133|      2|	sc_format_asn1_entry(asn1_skey_choice + 0, &skey_des_obj, NULL, 0);
  134|      2|	sc_format_asn1_entry(asn1_skey_choice + 1, &skey_des_obj, NULL, 0);
  135|      2|	sc_format_asn1_entry(asn1_skey_choice + 2, &skey_des_obj, NULL, 0);
  136|      2|	sc_format_asn1_entry(asn1_skey_choice + 3, &skey_des_obj, NULL, 0);
  137|       |
  138|      2|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info.id, NULL, 0);
  139|      2|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info.usage, &usage_len, 0);
  140|      2|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info.native, NULL, 0);
  141|      2|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info.access_flags, &af_len, 0);
  142|      2|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info.key_reference, NULL, 0);
  143|     34|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && (asn1_supported_algorithms + i)->name; i++)
  ------------------
  |  |   61|     68|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (143:12): [True: 32, False: 2]
  |  Branch (143:45): [True: 32, False: 0]
  ------------------
  144|     32|		sc_format_asn1_entry(asn1_supported_algorithms + i, &info.algo_refs[i], NULL, 0);
  145|      2|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, 0);
  146|       |
  147|      2|	sc_format_asn1_entry(asn1_com_skey_attr + 0, &info.value_len, NULL, 0);
  148|       |
  149|      2|	sc_format_asn1_entry(asn1_generic_skey_attr + 0, asn1_generic_skey_value_attr, NULL, 0);
  150|      2|	sc_format_asn1_entry(asn1_generic_skey_value_attr + 0, &info.path, NULL, 0);
  151|       |
  152|       |        /* Fill in defaults */
  153|      2|	memset(&info, 0, sizeof(info));
  154|      2|	info.native = 1;
  155|       |
  156|      2|	r = sc_asn1_decode(ctx, asn1_skey, *buf, *buflen, buf, buflen);
  157|      2|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      2|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (157:6): [True: 1, False: 1]
  ------------------
  158|      1|		return r;
  159|      1|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|      0|	if (asn1_skey_choice[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (160:6): [True: 0, False: 0]
  ------------------
  161|      0|		obj->type = SC_PKCS15_TYPE_SKEY_GENERIC;
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  162|       |
  163|       |		/* Check key type. framework-pkcs15 recognizes one type per key, and AES is the only algorithm supported for
  164|       |		* SKEY_GENERIC type keys, so just check if this key is AES compatible. */
  165|       |
  166|      0|		for (i = 0; i < SC_MAX_SUPPORTED_ALGORITHMS && info.algo_refs[i] != 0 && info.key_type == 0; i++) {
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (166:15): [True: 0, False: 0]
  |  Branch (166:50): [True: 0, False: 0]
  |  Branch (166:76): [True: 0, False: 0]
  ------------------
  167|      0|			for (ii = 0; ii < SC_MAX_SUPPORTED_ALGORITHMS && p15card->tokeninfo != 0; ii++) {
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (167:17): [True: 0, False: 0]
  |  Branch (167:53): [True: 0, False: 0]
  ------------------
  168|      0|				if (info.algo_refs[i] == p15card->tokeninfo->supported_algos[ii].reference) {
  ------------------
  |  Branch (168:9): [True: 0, False: 0]
  ------------------
  169|      0|					temp_oid = p15card->tokeninfo->supported_algos[ii].algo_id;
  170|      0|					temp_oid.value[8] = -1; /* strip off AES subtype octet*/
  171|       |
  172|      0|					if (sc_compare_oid(&id_aes, &temp_oid)) {
  ------------------
  |  Branch (172:10): [True: 0, False: 0]
  ------------------
  173|      0|						info.key_type = CKK_AES;
  ------------------
  |  |  485|      0|#define CKK_AES 0x0000001FUL
  ------------------
  174|      0|						break;
  175|      0|					}
  176|      0|				}
  177|      0|			}
  178|      0|		}
  179|      0|	}
  180|      0|	else if (asn1_skey_choice[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (180:11): [True: 0, False: 0]
  ------------------
  181|      0|		obj->type = SC_PKCS15_TYPE_SKEY_DES;
  ------------------
  |  |  434|      0|#define SC_PKCS15_TYPE_SKEY_DES			0x302
  ------------------
  182|      0|	else if (asn1_skey_choice[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (182:11): [True: 0, False: 0]
  ------------------
  183|      0|		obj->type = SC_PKCS15_TYPE_SKEY_2DES;
  ------------------
  |  |  435|      0|#define SC_PKCS15_TYPE_SKEY_2DES		0x303
  ------------------
  184|      0|	else if (asn1_skey_choice[3].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (184:11): [True: 0, False: 0]
  ------------------
  185|      0|		obj->type = SC_PKCS15_TYPE_SKEY_3DES;
  ------------------
  |  |  436|      0|#define SC_PKCS15_TYPE_SKEY_3DES		0x304
  ------------------
  186|      0|	else
  187|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported secret key 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|      0|	obj->data = malloc(sizeof(info));
  190|      0|	if (obj->data == NULL)
  ------------------
  |  Branch (190:6): [True: 0, False: 0]
  ------------------
  191|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|      0|	memcpy(obj->data, &info, sizeof(info));
  193|       |
  194|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|      0|}
sc_pkcs15_free_skey_info:
  275|     14|{
  276|     14|	if (info) {
  ------------------
  |  Branch (276:6): [True: 14, False: 0]
  ------------------
  277|     14|		free(info->data.value);
  278|     14|		free(info);
  279|     14|	}
  280|     14|}

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

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

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

sc_pkcs15_is_emulation_only:
   90|  14.9k|{
   91|  14.9k|	switch (card->type) {
   92|    674|		case SC_CARD_TYPE_GEMSAFEV1_PTEID:
  ------------------
  |  Branch (92:3): [True: 674, False: 14.3k]
  ------------------
   93|    677|		case SC_CARD_TYPE_OPENPGP_V1:
  ------------------
  |  Branch (93:3): [True: 3, False: 14.9k]
  ------------------
   94|    681|		case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (94:3): [True: 4, False: 14.9k]
  ------------------
   95|    688|		case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (95:3): [True: 7, False: 14.9k]
  ------------------
   96|    700|		case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (96:3): [True: 12, False: 14.9k]
  ------------------
   97|    700|		case SC_CARD_TYPE_SC_HSM:
  ------------------
  |  Branch (97:3): [True: 0, False: 14.9k]
  ------------------
   98|    700|		case SC_CARD_TYPE_SC_HSM_SOC:
  ------------------
  |  Branch (98:3): [True: 0, False: 14.9k]
  ------------------
   99|    700|		case SC_CARD_TYPE_DNIE_BASE:
  ------------------
  |  Branch (99:3): [True: 0, False: 14.9k]
  ------------------
  100|    700|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (100:3): [True: 0, False: 14.9k]
  ------------------
  101|    700|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (101:3): [True: 0, False: 14.9k]
  ------------------
  102|  1.39k|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (102:3): [True: 699, False: 14.2k]
  ------------------
  103|  1.39k|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (103:3): [True: 0, False: 14.9k]
  ------------------
  104|  1.55k|		case SC_CARD_TYPE_IASECC_GEMALTO:
  ------------------
  |  Branch (104:3): [True: 152, False: 14.8k]
  ------------------
  105|  1.65k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (105:3): [True: 102, False: 14.8k]
  ------------------
  106|  1.67k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (106:3): [True: 17, False: 14.9k]
  ------------------
  107|  1.67k|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (107:3): [True: 0, False: 14.9k]
  ------------------
  108|  1.67k|		case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (108:3): [True: 1, False: 14.9k]
  ------------------
  109|  1.73k|		case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (109:3): [True: 61, False: 14.9k]
  ------------------
  110|  1.88k|		case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (110:3): [True: 156, False: 14.8k]
  ------------------
  111|  1.88k|		case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (111:3): [True: 0, False: 14.9k]
  ------------------
  112|  1.88k|		case SC_CARD_TYPE_ESTEID_2018:
  ------------------
  |  Branch (112:3): [True: 0, False: 14.9k]
  ------------------
  113|  1.90k|		case SC_CARD_TYPE_CARDOS_V5_0:
  ------------------
  |  Branch (113:3): [True: 13, False: 14.9k]
  ------------------
  114|  2.70k|		case SC_CARD_TYPE_CARDOS_V5_3:
  ------------------
  |  Branch (114:3): [True: 802, False: 14.1k]
  ------------------
  115|  2.83k|		case SC_CARD_TYPE_NQ_APPLET:
  ------------------
  |  Branch (115:3): [True: 129, False: 14.8k]
  ------------------
  116|  2.83k|		case SC_CARD_TYPE_NQ_APPLET_RFID:
  ------------------
  |  Branch (116:3): [True: 0, False: 14.9k]
  ------------------
  117|  2.89k|		case SC_CARD_TYPE_STARCOS_V3_4_ESIGN:
  ------------------
  |  Branch (117:3): [True: 63, False: 14.9k]
  ------------------
  118|  2.90k|		case SC_CARD_TYPE_STARCOS_V3_5_ESIGN:
  ------------------
  |  Branch (118:3): [True: 12, False: 14.9k]
  ------------------
  119|  2.91k|		case SC_CARD_TYPE_SKEID_V3:
  ------------------
  |  Branch (119:3): [True: 4, False: 14.9k]
  ------------------
  120|  2.92k|		case SC_CARD_TYPE_EOI:
  ------------------
  |  Branch (120:3): [True: 17, False: 14.9k]
  ------------------
  121|  2.92k|		case SC_CARD_TYPE_EOI_CONTACTLESS:
  ------------------
  |  Branch (121:3): [True: 0, False: 14.9k]
  ------------------
  122|  2.92k|		case SC_CARD_TYPE_DTRUST_V4_1_STD:
  ------------------
  |  Branch (122:3): [True: 0, False: 14.9k]
  ------------------
  123|  2.92k|		case SC_CARD_TYPE_DTRUST_V4_4_STD:
  ------------------
  |  Branch (123:3): [True: 0, False: 14.9k]
  ------------------
  124|  2.92k|		case SC_CARD_TYPE_DTRUST_V4_1_MULTI:
  ------------------
  |  Branch (124:3): [True: 0, False: 14.9k]
  ------------------
  125|  2.92k|		case SC_CARD_TYPE_DTRUST_V4_1_M100:
  ------------------
  |  Branch (125:3): [True: 0, False: 14.9k]
  ------------------
  126|  2.92k|		case SC_CARD_TYPE_DTRUST_V4_4_MULTI:
  ------------------
  |  Branch (126:3): [True: 0, False: 14.9k]
  ------------------
  127|  2.92k|		case SC_CARD_TYPE_DTRUST_V5_1_STD:
  ------------------
  |  Branch (127:3): [True: 0, False: 14.9k]
  ------------------
  128|  2.92k|		case SC_CARD_TYPE_DTRUST_V5_4_STD:
  ------------------
  |  Branch (128:3): [True: 0, False: 14.9k]
  ------------------
  129|  2.92k|		case SC_CARD_TYPE_DTRUST_V5_1_MULTI:
  ------------------
  |  Branch (129:3): [True: 0, False: 14.9k]
  ------------------
  130|  2.92k|		case SC_CARD_TYPE_DTRUST_V5_1_M100:
  ------------------
  |  Branch (130:3): [True: 0, False: 14.9k]
  ------------------
  131|  2.92k|		case SC_CARD_TYPE_DTRUST_V5_4_MULTI:
  ------------------
  |  Branch (131:3): [True: 0, False: 14.9k]
  ------------------
  132|  2.92k|		case SC_CARD_TYPE_LTEID:
  ------------------
  |  Branch (132:3): [True: 0, False: 14.9k]
  ------------------
  133|  2.98k|		case SC_CARD_TYPE_CEDULAUY:
  ------------------
  |  Branch (133:3): [True: 60, False: 14.9k]
  ------------------
  134|  2.98k|			return 1;
  135|  11.9k|		default:
  ------------------
  |  Branch (135:3): [True: 11.9k, False: 2.98k]
  ------------------
  136|  11.9k|			return 0;
  137|  14.9k|	}
  138|  14.9k|}
sc_pkcs15_bind_synthetic:
  142|  14.8k|{
  143|  14.8k|	sc_context_t		*ctx = p15card->card->ctx;
  144|  14.8k|	scconf_block		*conf_block, **blocks, *blk;
  145|  14.8k|	int			i, r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  14.8k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  146|       |
  147|  14.8k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  148|  14.8k|	conf_block = NULL;
  149|       |
  150|  14.8k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
  151|       |
  152|  14.8k|	if (!conf_block) {
  ------------------
  |  Branch (152:6): [True: 14.8k, False: 0]
  ------------------
  153|       |		/* no conf file found => try builtin drivers  */
  154|  14.8k|		sc_log(ctx, "no conf file (or section), trying all builtin emulators");
  ------------------
  |  |   71|  14.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__
  |  |  ------------------
  ------------------
  155|   349k|		for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (155:15): [True: 339k, False: 9.44k]
  ------------------
  156|   339k|			sc_log(ctx, "trying %s", builtin_emulators[i].name);
  ------------------
  |  |   71|   339k|#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|   339k|			r = builtin_emulators[i].handler(p15card, aid);
  158|   339k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|   339k|#define SC_SUCCESS				0
  ------------------
  |  Branch (158:8): [True: 5.38k, False: 334k]
  ------------------
  159|       |				/* we got a hit */
  160|  5.38k|				goto out;
  161|   339k|		}
  162|  14.8k|	} 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|  14.8k|out:
  224|  14.8k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  14.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (224:6): [True: 5.38k, False: 9.44k]
  ------------------
  225|  5.38k|		p15card->magic  = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  5.38k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  226|  5.38k|		p15card->flags |= SC_PKCS15_CARD_FLAG_EMULATED;
  ------------------
  |  |  601|  5.38k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  227|  9.44k|	} else {
  228|  9.44k|		if (r != SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  9.44k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (228:7): [True: 115, False: 9.32k]
  ------------------
  229|    115|			sc_log(ctx, "Failed to load card emulator: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  230|  9.44k|	}
  231|       |
  232|  14.8k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  14.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  14.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  14.8k|	int _ret = r; \
  |  |  |  |  155|  14.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  14.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|  9.44k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.44k, False: 5.38k]
  |  |  |  |  ------------------
  |  |  |  |  157|  14.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.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|  14.8k|	return _ret; \
  |  |  |  |  163|  14.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|  14.8k|}
sc_pkcs15emu_add_pin_obj:
  369|  6.05k|{
  370|  6.05k|	sc_pkcs15_auth_info_t pin = *in_pin;
  371|       |
  372|  6.05k|	pin.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  6.05k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  373|  6.05k|	if(!pin.auth_method) /* or SC_AC_NONE */
  ------------------
  |  Branch (373:5): [True: 5.59k, False: 462]
  ------------------
  374|  5.59k|		pin.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|  5.59k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  375|       |
  376|  6.05k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_AUTH_PIN, obj, &pin);
  ------------------
  |  |  445|  6.05k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  377|  6.05k|}
sc_pkcs15emu_add_rsa_prkey:
  381|  1.41k|{
  382|  1.41k|	sc_pkcs15_prkey_info_t key = *in_key;
  383|       |
  384|  1.41k|	if (key.access_flags == 0)
  ------------------
  |  Branch (384:6): [True: 1.41k, False: 0]
  ------------------
  385|  1.41k|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|  1.41k|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  386|  1.41k|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|  1.41k|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  387|  1.41k|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|  1.41k|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  388|  1.41k|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|  1.41k|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  389|       |
  390|  1.41k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_RSA, obj, &key);
  ------------------
  |  |  419|  1.41k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  391|  1.41k|}
sc_pkcs15emu_add_rsa_pubkey:
  395|    211|{
  396|    211|	sc_pkcs15_pubkey_info_t key = *in_key;
  397|       |
  398|    211|	if (key.access_flags == 0)
  ------------------
  |  Branch (398:6): [True: 211, False: 0]
  ------------------
  399|    211|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    211|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  400|       |
  401|    211|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_RSA, obj, &key);
  ------------------
  |  |  426|    211|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  402|    211|}
sc_pkcs15emu_add_ec_prkey:
  406|    957|{
  407|    957|	sc_pkcs15_prkey_info_t key = *in_key;
  408|       |
  409|    957|	if (key.access_flags == 0)
  ------------------
  |  Branch (409:6): [True: 957, False: 0]
  ------------------
  410|    957|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|    957|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  411|    957|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|    957|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  412|    957|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|    957|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  413|    957|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|    957|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  414|       |
  415|    957|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_EC, obj, &key);
  ------------------
  |  |  421|    957|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  416|    957|}
sc_pkcs15emu_add_ec_pubkey:
  420|    958|{
  421|    958|	sc_pkcs15_pubkey_info_t key = *in_key;
  422|       |
  423|    958|	if (key.access_flags == 0)
  ------------------
  |  Branch (423:6): [True: 958, False: 0]
  ------------------
  424|    958|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    958|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  425|       |
  426|    958|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_EC, obj, &key);
  ------------------
  |  |  428|    958|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  427|    958|}
sc_pkcs15emu_add_x509_cert:
  481|  2.16k|{
  482|  2.16k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_CERT_X509, obj, cert);
  ------------------
  |  |  439|  2.16k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  483|  2.16k|}
sc_pkcs15emu_add_data_object:
  487|  4.57k|{
  488|  4.57k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, obj, data);
  ------------------
  |  |  442|  4.57k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  489|  4.57k|}
sc_pkcs15emu_object_add:
  493|  36.4k|{
  494|  36.4k|	sc_pkcs15_object_t *obj;
  495|  36.4k|	unsigned int	df_type;
  496|  36.4k|	size_t		data_len;
  497|       |
  498|  36.4k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  36.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  36.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  36.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 36.4k]
  |  |  ------------------
  ------------------
  499|       |
  500|  36.4k|	obj = calloc(1, sizeof(*obj));
  501|  36.4k|	if (!obj) {
  ------------------
  |  Branch (501:6): [True: 0, False: 36.4k]
  ------------------
  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|  36.4k|	memcpy(obj, in_obj, sizeof(*obj));
  506|  36.4k|	obj->type = type;
  507|       |
  508|  36.4k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  36.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  509|  6.05k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  6.05k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (509:2): [True: 6.05k, False: 30.4k]
  ------------------
  510|  6.05k|		df_type  = SC_PKCS15_AODF;
  ------------------
  |  |  496|  6.05k|#define SC_PKCS15_AODF			8
  ------------------
  511|  6.05k|		data_len = sizeof(struct sc_pkcs15_auth_info);
  512|  6.05k|		break;
  513|  3.67k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  3.67k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (513:2): [True: 3.67k, False: 32.8k]
  ------------------
  514|  3.67k|		df_type  = SC_PKCS15_PRKDF;
  ------------------
  |  |  488|  3.67k|#define SC_PKCS15_PRKDF			0
  ------------------
  515|  3.67k|		data_len = sizeof(struct sc_pkcs15_prkey_info);
  516|  3.67k|		break;
  517|  1.16k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.16k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (517:2): [True: 1.16k, False: 35.3k]
  ------------------
  518|  1.16k|		df_type = SC_PKCS15_PUKDF;
  ------------------
  |  |  489|  1.16k|#define SC_PKCS15_PUKDF			1
  ------------------
  519|  1.16k|		data_len = sizeof(struct sc_pkcs15_pubkey_info);
  520|  1.16k|		break;
  521|  2.52k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  2.52k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (521:2): [True: 2.52k, False: 33.9k]
  ------------------
  522|  2.52k|		df_type = SC_PKCS15_CDF;
  ------------------
  |  |  492|  2.52k|#define SC_PKCS15_CDF			4
  ------------------
  523|  2.52k|		data_len = sizeof(struct sc_pkcs15_cert_info);
  524|  2.52k|		break;
  525|  23.0k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  23.0k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (525:2): [True: 23.0k, False: 13.4k]
  ------------------
  526|  23.0k|		df_type = SC_PKCS15_DODF;
  ------------------
  |  |  495|  23.0k|#define SC_PKCS15_DODF			7
  ------------------
  527|  23.0k|		data_len = sizeof(struct sc_pkcs15_data_info);
  528|  23.0k|		break;
  529|      0|	default:
  ------------------
  |  Branch (529:2): [True: 0, False: 36.4k]
  ------------------
  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|  36.4k|	}
  534|       |
  535|  36.4k|	obj->data = calloc(1, data_len);
  536|  36.4k|	if (obj->data == NULL) {
  ------------------
  |  Branch (536:6): [True: 0, False: 36.4k]
  ------------------
  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|  36.4k|	memcpy(obj->data, data, data_len);
  541|       |
  542|  36.4k|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  543|  36.4k|	sc_pkcs15_add_object(p15card, obj);
  544|       |
  545|       |	/* release memory ownership of buffers that are now contained in `p15card` */
  546|  36.4k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  36.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  547|  6.05k|	default:
  ------------------
  |  Branch (547:2): [True: 6.05k, False: 30.4k]
  ------------------
  548|       |		/* `data`'s members copied by value, no buffer to release */
  549|  6.05k|		break;
  550|  6.05k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  3.67k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (550:2): [True: 3.67k, False: 32.8k]
  ------------------
  551|  3.67k|		((struct sc_pkcs15_prkey_info *)data)->subject.value = NULL;
  552|  3.67k|		break;
  553|  1.16k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.16k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (553:2): [True: 1.16k, False: 35.3k]
  ------------------
  554|  1.16k|		((struct sc_pkcs15_pubkey_info *)data)->subject.value = NULL;
  555|  1.16k|		((struct sc_pkcs15_pubkey_info *)data)->direct.raw.value = NULL;
  556|  1.16k|		((struct sc_pkcs15_pubkey_info *)data)->direct.spki.value = NULL;
  557|  1.16k|		break;
  558|  2.52k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  2.52k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (558:2): [True: 2.52k, False: 33.9k]
  ------------------
  559|  2.52k|		((struct sc_pkcs15_cert_info *)data)->value.value = NULL;
  560|  2.52k|		break;
  561|  23.0k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  23.0k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (561:2): [True: 23.0k, False: 13.4k]
  ------------------
  562|  23.0k|		((struct sc_pkcs15_data_info *)data)->data.value = NULL;
  563|  23.0k|		break;
  564|  36.4k|	}
  565|       |
  566|  36.4k|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  36.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  36.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  36.4k|	int _ret = r; \
  |  |  |  |  155|  36.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  36.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: 36.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  36.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  36.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|  36.4k|	return _ret; \
  |  |  |  |  163|  36.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  567|  36.4k|}
pkcs15-syn.c:sc_pkcs15emu_get_df:
  340|  36.4k|{
  341|  36.4k|	sc_pkcs15_df_t	*df;
  342|  36.4k|	sc_file_t	*file;
  343|  36.4k|	int		created = 0;
  344|       |
  345|  45.4k|	while (1) {
  ------------------
  |  Branch (345:9): [True: 45.4k, Folded]
  ------------------
  346|  69.5k|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (346:31): [True: 60.5k, False: 8.95k]
  ------------------
  347|  60.5k|			if (df->type == type) {
  ------------------
  |  Branch (347:8): [True: 36.4k, False: 24.0k]
  ------------------
  348|  36.4k|				if (created)
  ------------------
  |  Branch (348:9): [True: 8.95k, False: 27.5k]
  ------------------
  349|  8.95k|					df->enumerated = 1;
  350|  36.4k|				return df;
  351|  36.4k|			}
  352|  60.5k|		}
  353|       |
  354|  8.95k|		if (created != 0)
  ------------------
  |  Branch (354:7): [True: 0, False: 8.95k]
  ------------------
  355|      0|			return NULL;
  356|       |
  357|  8.95k|		file = sc_file_new();
  358|  8.95k|		if (!file)
  ------------------
  |  Branch (358:7): [True: 0, False: 8.95k]
  ------------------
  359|      0|			return NULL;
  360|  8.95k|		sc_format_path("11001101", &file->path);
  361|  8.95k|		sc_pkcs15_add_df(p15card, type, &file->path);
  362|  8.95k|		sc_file_free(file);
  363|  8.95k|		created++;
  364|  8.95k|	}
  365|  36.4k|}

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

sc_pkcs15_parse_tokeninfo:
  145|    556|{
  146|    556|	int r;
  147|    556|	size_t ii;
  148|    556|	u8 serial[128];
  149|    556|	size_t serial_len = sizeof(serial);
  150|    556|	u8 mnfid[SC_PKCS15_MAX_LABEL_SIZE];
  151|    556|	size_t mnfid_len  = sizeof(mnfid) - 1;
  152|    556|	u8 label[SC_PKCS15_MAX_LABEL_SIZE];
  153|    556|	size_t label_len = sizeof(label) - 1;
  154|    556|	u8 last_update[32], profile_indication[SC_PKCS15_MAX_LABEL_SIZE];
  155|    556|	size_t lupdate_len = sizeof(last_update) - 1, pi_len = sizeof(profile_indication) - 1;
  156|    556|	size_t flags_len   = sizeof(ti->flags);
  157|    556|	u8 preferred_language[64];
  158|    556|	size_t lang_length = sizeof(preferred_language) - 1;
  159|    556|	struct sc_asn1_entry asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1],
  160|    556|			asn1_algo_infos[SC_MAX_SUPPORTED_ALGORITHMS][7],
  161|    556|			asn1_algo_infos_parameters[SC_MAX_SUPPORTED_ALGORITHMS][3];
  162|    556|	size_t reference_len = sizeof(ti->supported_algos[0].reference);
  163|    556|	size_t mechanism_len = sizeof(ti->supported_algos[0].mechanism);
  164|    556|	size_t parameter_len = sizeof(ti->supported_algos[0].parameters);
  165|    556|	size_t operations_len = sizeof(ti->supported_algos[0].operations);
  166|    556|	size_t algo_ref_len = sizeof(ti->supported_algos[0].algo_ref);
  167|       |
  168|    556|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  169|    556|	struct sc_asn1_entry asn1_profile_indication[C_ASN1_PROFILE_INDICATION_SIZE];
  170|    556|	struct sc_asn1_entry asn1_toki_attrs[C_ASN1_TOKI_ATTRS_SIZE], asn1_tokeninfo[3], asn1_twlabel[3];
  171|       |
  172|    556|	memset(last_update, 0, sizeof(last_update));
  173|    556|	memset(label, 0, sizeof(label));
  174|    556|	memset(profile_indication, 0, sizeof(profile_indication));
  175|    556|	memset(mnfid, 0, sizeof(mnfid));
  176|       |
  177|    556|	sc_copy_asn1_entry(c_asn1_twlabel, asn1_twlabel);
  178|    556|	sc_copy_asn1_entry(c_asn1_toki_attrs, asn1_toki_attrs);
  179|    556|	sc_copy_asn1_entry(c_asn1_tokeninfo, asn1_tokeninfo);
  180|    556|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  181|    556|	sc_format_asn1_entry(asn1_twlabel, label, &label_len, 0);
  182|    556|	sc_copy_asn1_entry(c_asn1_profile_indication, asn1_profile_indication);
  183|       |
  184|  9.45k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++) {
  ------------------
  |  |   61|  9.45k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (184:13): [True: 8.89k, False: 556]
  ------------------
  185|  8.89k|		sc_copy_asn1_entry(c_asn1_algorithm_info, asn1_algo_infos[ii]);
  186|  8.89k|		sc_copy_asn1_entry(c_asn1_algorithm_info_parameters,
  187|  8.89k|			asn1_algo_infos_parameters[ii]);
  188|  8.89k|	}
  189|    556|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  190|       |
  191|  9.45k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++)   {
  ------------------
  |  |   61|  9.45k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (191:13): [True: 8.89k, False: 556]
  ------------------
  192|  8.89k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 0, &ti->supported_algos[ii].reference, &reference_len, 0);
  193|  8.89k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 0);
  194|  8.89k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
  195|  8.89k|			asn1_algo_infos_parameters[ii], NULL, 0);
  196|  8.89k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
  197|  8.89k|			NULL, NULL, 0);
  198|  8.89k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
  199|  8.89k|			&ti->supported_algos[ii].parameters, &parameter_len, 0);
  200|  8.89k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 3, &ti->supported_algos[ii].operations, &operations_len, 0);
  201|  8.89k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 4, &ti->supported_algos[ii].algo_id, NULL, 1);
  202|  8.89k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 5, &ti->supported_algos[ii].algo_ref, &algo_ref_len, 0);
  203|  8.89k|		sc_format_asn1_entry(asn1_supported_algorithms + ii, asn1_algo_infos[ii], NULL, 0);
  204|  8.89k|	}
  205|       |
  206|    556|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  207|    556|	sc_format_asn1_entry(asn1_last_update + 1, &ti->last_update.path, NULL, 0);
  208|       |
  209|    556|	sc_format_asn1_entry(asn1_profile_indication + 0, &ti->profile_indication.oid, NULL, 0);
  210|    556|	sc_format_asn1_entry(asn1_profile_indication + 1, profile_indication, &pi_len, 0);
  211|       |
  212|    556|	sc_format_asn1_entry(asn1_toki_attrs + 0, &ti->version, NULL, 0);
  213|    556|	sc_format_asn1_entry(asn1_toki_attrs + 1, serial, &serial_len, 0);
  214|    556|	sc_format_asn1_entry(asn1_toki_attrs + 2, mnfid, &mnfid_len, 0);
  215|    556|	sc_format_asn1_entry(asn1_toki_attrs + 3, label, &label_len, 0);
  216|    556|	sc_format_asn1_entry(asn1_toki_attrs + 4, asn1_twlabel, NULL, 0);
  217|    556|	sc_format_asn1_entry(asn1_toki_attrs + 5, &ti->flags, &flags_len, 0);
  218|    556|	sc_format_asn1_entry(asn1_toki_attrs + 6, &ti->seInfo, &ti->num_seInfo, 0);
  219|    556|	sc_format_asn1_entry(asn1_toki_attrs + 7, NULL, NULL, 0);
  220|    556|	sc_format_asn1_entry(asn1_toki_attrs + 8, asn1_supported_algorithms, NULL, 0);
  221|    556|	sc_format_asn1_entry(asn1_toki_attrs + 9, NULL, NULL, 0);
  222|    556|	sc_format_asn1_entry(asn1_toki_attrs + 10, NULL, NULL, 0);
  223|    556|	sc_format_asn1_entry(asn1_toki_attrs + 11, asn1_last_update, NULL, 0);
  224|    556|	sc_format_asn1_entry(asn1_toki_attrs + 12, preferred_language, &lang_length, 0);
  225|    556|	sc_format_asn1_entry(asn1_toki_attrs + 13, asn1_profile_indication, NULL, 0);
  226|    556|	sc_format_asn1_entry(asn1_tokeninfo, asn1_toki_attrs, NULL, 0);
  227|       |
  228|    556|	r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
  229|    556|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    556|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:6): [True: 443, False: 113]
  ------------------
  230|       |		/* The decoding could have allocated something we need to free */
  231|    443|		sc_pkcs15_clear_tokeninfo(ti);
  232|    443|		LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
  ------------------
  |  |  174|    443|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    443|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    443|	int _ret = (r); \
  |  |  |  |  168|    443|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 443, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    443|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    443|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    443|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    443|		return _ret; \
  |  |  |  |  172|    443|	} \
  |  |  |  |  173|    443|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|    443|	}
  234|       |
  235|    113|	if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0)   {
  ------------------
  |  |  147|    226|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (235:6): [True: 40, False: 73]
  |  Branch (235:52): [True: 26, False: 14]
  ------------------
  236|     26|		free(ti->serial_number);
  237|     26|		ti->serial_number = malloc(serial_len * 2 + 1);
  238|     26|		if (ti->serial_number == NULL)
  ------------------
  |  Branch (238:7): [True: 0, False: 26]
  ------------------
  239|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  240|     26|		sc_bin_to_hex(serial, serial_len, ti->serial_number, serial_len * 2 + 1, 0);
  241|     26|		sc_log(ctx, "TokenInfo.serialNunmber '%s'", ti->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  242|     26|	}
  243|       |
  244|    113|	if (ti->manufacturer_id == NULL) {
  ------------------
  |  Branch (244:6): [True: 113, False: 0]
  ------------------
  245|    113|		if (asn1_toki_attrs[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    113|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (245:7): [True: 4, False: 109]
  ------------------
  246|      4|			ti->manufacturer_id = strdup((char *) mnfid);
  247|    109|		else
  248|    109|			ti->manufacturer_id = strdup("(unknown)");
  249|    113|		if (ti->manufacturer_id == NULL)
  ------------------
  |  Branch (249:7): [True: 0, False: 113]
  ------------------
  250|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  251|    113|	}
  252|    113|	if (ti->label == NULL) {
  ------------------
  |  Branch (252:6): [True: 113, False: 0]
  ------------------
  253|    113|		if (asn1_toki_attrs[3].flags & SC_ASN1_PRESENT ||
  ------------------
  |  |  147|    226|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (253:7): [True: 1, False: 112]
  ------------------
  254|    112|		    asn1_toki_attrs[4].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    112|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (254:7): [True: 0, False: 112]
  ------------------
  255|      1|			ti->label = strdup((char *) label);
  256|    112|		else
  257|    112|			ti->label = strdup("(unknown)");
  258|    113|		if (ti->label == NULL)
  ------------------
  |  Branch (258:7): [True: 0, False: 113]
  ------------------
  259|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  260|    113|	}
  261|    113|	if (asn1_toki_attrs[11].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    113|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (261:6): [True: 1, False: 112]
  ------------------
  262|      1|		if (asn1_last_update[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      1|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (262:7): [True: 0, False: 1]
  ------------------
  263|      0|			sc_log(ctx, "LastUpdate.generalizedTime present");
  ------------------
  |  |   71|      0|#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|			ti->last_update.gtime = strdup((char *)last_update);
  265|      0|			if (ti->last_update.gtime == NULL)
  ------------------
  |  Branch (265:8): [True: 0, False: 0]
  ------------------
  266|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  267|      0|		}
  268|      1|		else if (asn1_last_update[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|      1|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (268:12): [True: 0, False: 1]
  ------------------
  269|      0|			sc_log(ctx, "LastUpdate.referencedTime present");
  ------------------
  |  |   71|      0|#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|      0|		}
  271|      1|	}
  272|    113|	if (asn1_toki_attrs[12].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    113|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:6): [True: 3, False: 110]
  ------------------
  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|    113|	sc_init_oid(&ti->profile_indication.oid);
  280|    113|	if (asn1_toki_attrs[13].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    113|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (280:6): [True: 3, False: 110]
  ------------------
  281|      3|		if (asn1_profile_indication[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      3|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (281:7): [True: 0, False: 3]
  ------------------
  282|      0|			sc_log(ctx, "ProfileIndication.oid present");
  ------------------
  |  |   71|      0|#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|      0|		}
  284|      3|		else if (asn1_profile_indication[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|      3|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (284:12): [True: 0, False: 3]
  ------------------
  285|      0|			sc_log(ctx, "ProfileIndication.name present");
  ------------------
  |  |   71|      0|#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|      0|			ti->profile_indication.name = strdup((char *)profile_indication);
  287|      0|			if (ti->profile_indication.name == NULL)
  ------------------
  |  Branch (287:8): [True: 0, False: 0]
  ------------------
  288|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  289|      0|		}
  290|      3|	}
  291|       |
  292|    113|	sc_log(ctx, "LastUpdate.path '%s'", sc_print_path(&ti->last_update.path));
  ------------------
  |  |   71|    113|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  293|    113|	sc_log(ctx, "ProfileIndication.name '%s'",  ti->profile_indication.name);
  ------------------
  |  |   71|    113|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  294|    113|	return SC_SUCCESS;
  ------------------
  |  |   28|    113|#define SC_SUCCESS				0
  ------------------
  295|    113|}
sc_pkcs15_get_lastupdate:
  541|  2.63k|{
  542|  2.63k|	struct sc_context *ctx  = p15card->card->ctx;
  543|  2.63k|	struct sc_file *file = NULL;
  544|  2.63k|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  545|  2.63k|	unsigned char *content, last_update[32] = {0};
  546|  2.63k|	size_t lupdate_len = sizeof(last_update) - 1;
  547|  2.63k|	int r, content_len;
  548|  2.63k|	size_t size;
  549|       |
  550|  2.63k|	if (p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (550:6): [True: 0, False: 2.63k]
  ------------------
  551|      0|		goto done;
  552|       |
  553|  2.63k|	if (!p15card->tokeninfo->last_update.path.len)
  ------------------
  |  Branch (553:6): [True: 2.63k, False: 0]
  ------------------
  554|  2.63k|		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|  15.2k|{
  720|  15.2k|	struct sc_pkcs15_card *p15card;
  721|       |
  722|  15.2k|	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
  723|  15.2k|	if (p15card == NULL)
  ------------------
  |  Branch (723:6): [True: 0, False: 15.2k]
  ------------------
  724|      0|		return NULL;
  725|       |
  726|  15.2k|	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  727|  15.2k|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (727:6): [True: 0, False: 15.2k]
  ------------------
  728|      0|		free(p15card);
  729|      0|		return NULL;
  730|      0|	}
  731|       |
  732|  15.2k|	p15card->magic = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  15.2k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  733|  15.2k|	return p15card;
  734|  15.2k|}
sc_pkcs15_tokeninfo_new:
  739|  11.4k|{
  740|  11.4k|	struct sc_pkcs15_tokeninfo *tokeninfo;
  741|       |
  742|  11.4k|	tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  743|  11.4k|	if (tokeninfo == NULL) {
  ------------------
  |  Branch (743:6): [True: 0, False: 11.4k]
  ------------------
  744|      0|		return NULL;
  745|      0|	}
  746|       |
  747|  11.4k|	sc_init_oid(&tokeninfo->profile_indication.oid);
  748|       |
  749|  11.4k|	return tokeninfo;
  750|  11.4k|}
sc_pkcs15_free_tokeninfo:
  781|  28.2k|{
  782|  28.2k|	if (!tokeninfo)
  ------------------
  |  Branch (782:6): [True: 1.61k, False: 26.6k]
  ------------------
  783|  1.61k|		return;
  784|       |
  785|  26.6k|	sc_pkcs15_clear_tokeninfo(tokeninfo);
  786|  26.6k|	free(tokeninfo);
  787|  26.6k|}
sc_pkcs15_free_app:
  791|  53.5k|{
  792|  53.5k|	if (p15card && p15card->app) {
  ------------------
  |  Branch (792:6): [True: 53.5k, False: 0]
  |  Branch (792:17): [True: 4.65k, False: 48.8k]
  ------------------
  793|  4.65k|		free(p15card->app->label);
  794|  4.65k|		free(p15card->app->ddo.value);
  795|  4.65k|		free(p15card->app);
  796|       |		p15card->app = NULL;
  797|  4.65k|	}
  798|  53.5k|}
sc_pkcs15_card_free:
  803|  15.2k|{
  804|  15.2k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC)
  ------------------
  |  |  519|  15.2k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (804:6): [True: 0, False: 15.2k]
  |  Branch (804:25): [True: 0, False: 15.2k]
  ------------------
  805|      0|		return;
  806|       |
  807|  15.2k|	if (p15card->ops.clear)
  ------------------
  |  Branch (807:6): [True: 803, False: 14.4k]
  ------------------
  808|    803|		p15card->ops.clear(p15card);
  809|       |
  810|       |	/* For more complicated MD data a dedicated release procedure
  811|       |	 * has to be implemented. */
  812|  15.2k|	if (p15card->md_data)
  ------------------
  |  Branch (812:6): [True: 0, False: 15.2k]
  ------------------
  813|      0|		free(p15card->md_data);
  814|       |
  815|  15.2k|	sc_pkcs15_free_app(p15card);
  816|  15.2k|	sc_pkcs15_remove_objects(p15card);
  817|  15.2k|	sc_pkcs15_remove_dfs(p15card);
  818|  15.2k|	sc_pkcs15_free_unusedspace(p15card);
  819|  15.2k|	p15card->unusedspace_read = 0;
  820|       |
  821|  15.2k|	sc_file_free(p15card->file_app);
  822|  15.2k|	sc_file_free(p15card->file_tokeninfo);
  823|  15.2k|	sc_file_free(p15card->file_odf);
  824|  15.2k|	sc_file_free(p15card->file_unusedspace);
  825|       |
  826|  15.2k|	p15card->magic = 0;
  827|  15.2k|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  828|  15.2k|	sc_pkcs15_free_app(p15card);
  829|  15.2k|	free(p15card);
  830|  15.2k|}
sc_pkcs15_card_clear:
  835|  18.8k|{
  836|  18.8k|	if (p15card == NULL)
  ------------------
  |  Branch (836:6): [True: 0, False: 18.8k]
  ------------------
  837|      0|		return;
  838|       |
  839|  18.8k|	if (p15card->ops.clear)
  ------------------
  |  Branch (839:6): [True: 758, False: 18.0k]
  ------------------
  840|    758|		p15card->ops.clear(p15card);
  841|       |
  842|  18.8k|	p15card->flags = 0;
  843|  18.8k|	p15card->tokeninfo->version = 0;
  844|  18.8k|	p15card->tokeninfo->flags   = 0;
  845|       |
  846|  18.8k|	sc_pkcs15_remove_objects(p15card);
  847|  18.8k|	sc_pkcs15_remove_dfs(p15card);
  848|       |
  849|  18.8k|	p15card->df_list = NULL;
  850|  18.8k|	sc_file_free(p15card->file_app);
  851|  18.8k|	p15card->file_app = NULL;
  852|  18.8k|	sc_file_free(p15card->file_tokeninfo);
  853|  18.8k|	p15card->file_tokeninfo = NULL;
  854|  18.8k|	sc_file_free(p15card->file_odf);
  855|  18.8k|	p15card->file_odf = NULL;
  856|  18.8k|	sc_file_free(p15card->file_unusedspace);
  857|  18.8k|	p15card->file_unusedspace = NULL;
  858|       |
  859|  18.8k|	free(p15card->tokeninfo->label);
  860|  18.8k|	p15card->tokeninfo->label = NULL;
  861|  18.8k|	free(p15card->tokeninfo->serial_number);
  862|  18.8k|	p15card->tokeninfo->serial_number = NULL;
  863|  18.8k|	free(p15card->tokeninfo->manufacturer_id);
  864|  18.8k|	p15card->tokeninfo->manufacturer_id = NULL;
  865|  18.8k|	free(p15card->tokeninfo->last_update.gtime);
  866|  18.8k|	p15card->tokeninfo->last_update.gtime = NULL;
  867|  18.8k|	free(p15card->tokeninfo->preferred_language);
  868|  18.8k|	p15card->tokeninfo->preferred_language = NULL;
  869|  18.8k|	free(p15card->tokeninfo->profile_indication.name);
  870|  18.8k|	p15card->tokeninfo->profile_indication.name = NULL;
  871|  18.8k|	if (p15card->tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (871:6): [True: 4, False: 18.8k]
  ------------------
  872|      4|		size_t i;
  873|      4|		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (873:15): [True: 0, False: 4]
  ------------------
  874|      0|			free(p15card->tokeninfo->seInfo[i]);
  875|      4|		free(p15card->tokeninfo->seInfo);
  876|      4|		p15card->tokeninfo->seInfo     = NULL;
  877|      4|		p15card->tokeninfo->num_seInfo = 0;
  878|      4|	}
  879|       |
  880|  18.8k|	sc_pkcs15_free_app(p15card);
  881|  18.8k|}
sc_find_app:
  886|  15.6k|{
  887|  15.6k|	int ii;
  888|       |
  889|  15.6k|	if (card->app_count <= 0)
  ------------------
  |  Branch (889:6): [True: 11.3k, False: 4.26k]
  ------------------
  890|  11.3k|		return NULL;
  891|       |
  892|  4.26k|	if (!aid || !aid->len)
  ------------------
  |  Branch (892:6): [True: 0, False: 4.26k]
  |  Branch (892:14): [True: 1.13k, False: 3.13k]
  ------------------
  893|  1.13k|		return card->app[0];
  894|       |
  895|  4.68k|	for (ii=0; ii < card->app_count; ii++) {
  ------------------
  |  Branch (895:13): [True: 4.68k, False: 0]
  ------------------
  896|  4.68k|		if (card->app[ii]->aid.len != aid->len)
  ------------------
  |  Branch (896:7): [True: 345, False: 4.34k]
  ------------------
  897|    345|			continue;
  898|  4.34k|		if (memcmp(card->app[ii]->aid.value, aid->value, aid->len))
  ------------------
  |  Branch (898:7): [True: 1.21k, False: 3.13k]
  ------------------
  899|  1.21k|			continue;
  900|  3.13k|		return card->app[ii];
  901|  4.34k|	}
  902|      0|	return NULL;
  903|  3.13k|}
sc_pkcs15_get_application_by_type:
  940|  12.7k|{
  941|  12.7k|	struct sc_app_info *out = NULL;
  942|  12.7k|	scconf_block *conf_block = NULL;
  943|  12.7k|	int i, rv;
  944|       |
  945|  12.7k|	if (!card)
  ------------------
  |  Branch (945:6): [True: 0, False: 12.7k]
  ------------------
  946|      0|		return NULL;
  947|       |
  948|  12.7k|	if (card->app_count < 0)   {
  ------------------
  |  Branch (948:6): [True: 12.7k, False: 0]
  ------------------
  949|  12.7k|		rv = sc_enum_apps(card);
  950|  12.7k|		if (rv < 0 && rv != SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  11.7k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (950:7): [True: 11.7k, False: 961]
  |  Branch (950:17): [True: 10.0k, False: 1.72k]
  ------------------
  951|  10.0k|			return NULL;
  952|  12.7k|	}
  953|       |
  954|  2.68k|	conf_block = sc_get_conf_block(card->ctx, "framework", "pkcs15", 1);
  955|  2.68k|	if (!conf_block)
  ------------------
  |  Branch (955:6): [True: 2.68k, False: 0]
  ------------------
  956|  2.68k|		return NULL;
  957|       |
  958|      0|	for (i = 0; i < card->app_count; i++)   {
  ------------------
  |  Branch (958:14): [True: 0, False: 0]
  ------------------
  959|      0|		struct sc_app_info *app_info = card->app[i];
  960|      0|		scconf_block **blocks = NULL;
  961|      0|		char str_path[SC_MAX_AID_STRING_SIZE];
  962|       |
  963|      0|		sc_bin_to_hex(app_info->aid.value, app_info->aid.len, str_path, sizeof(str_path), 0);
  964|      0|		blocks = scconf_find_blocks(card->ctx->conf, conf_block, "application", str_path);
  965|      0|		if (blocks)   {
  ------------------
  |  Branch (965:7): [True: 0, False: 0]
  ------------------
  966|      0|			if (blocks[0])   {
  ------------------
  |  Branch (966:8): [True: 0, False: 0]
  ------------------
  967|      0|				char *type = (char *)scconf_get_str(blocks[0], "type", app_type);
  968|      0|				if (!strcmp(type, app_type))   {
  ------------------
  |  Branch (968:9): [True: 0, False: 0]
  ------------------
  969|      0|					out = app_info;
  970|      0|					free(blocks);
  971|      0|					break;
  972|      0|				}
  973|      0|			}
  974|      0|			free(blocks);
  975|      0|		}
  976|      0|	}
  977|       |
  978|      0|	return out;
  979|  2.68k|}
sc_pkcs15_bind_internal_odf:
  983|    496|{
  984|    496|	struct sc_path tmppath;
  985|    496|	struct sc_card    *card = p15card->card;
  986|    496|	struct sc_context *ctx = card->ctx;
  987|    496|	struct sc_pkcs15_df *df;
  988|    496|	unsigned char *buf = NULL;
  989|    496|	size_t len;
  990|    496|	int    err, ok = 0;
  991|       |
  992|    496|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    496|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    496|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    496|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    496|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 496]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  993|    496|	if (p15card->file_odf == NULL) {
  ------------------
  |  Branch (993:6): [True: 474, False: 22]
  ------------------
  994|       |		/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
  995|    474|		sc_format_path("5031", &tmppath);
  996|    474|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
  997|    474|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    474|#define SC_SUCCESS				0
  ------------------
  |  Branch (997:7): [True: 0, False: 474]
  ------------------
  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|    474|		sc_log(ctx, "absolute path to EF(ODF) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|    474|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1002|    474|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1003|    474|	}
 1004|     22|	else {
 1005|     22|		tmppath = p15card->file_odf->path;
 1006|     22|		sc_file_free(p15card->file_odf);
 1007|     22|		p15card->file_odf = NULL;
 1008|     22|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1009|     22|	}
 1010|       |
 1011|    496|	if (err != SC_SUCCESS) {
  ------------------
  |  |   28|    496|#define SC_SUCCESS				0
  ------------------
  |  Branch (1011:6): [True: 245, False: 251]
  ------------------
 1012|    245|		sc_log(ctx, "EF(ODF) not found in '%s'", sc_print_path(&tmppath));
  ------------------
  |  |   71|    245|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1013|    245|		goto end;
 1014|    245|	}
 1015|       |
 1016|    251|	len = p15card->file_odf->size;
 1017|    251|	if (!len) {
  ------------------
  |  Branch (1017:6): [True: 142, False: 109]
  ------------------
 1018|    142|		sc_log(ctx, "EF(ODF) is empty");
  ------------------
  |  |   71|    142|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1019|    142|		goto end;
 1020|    142|	}
 1021|    109|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    109|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1021:6): [True: 39, False: 70]
  ------------------
 1022|     39|		sc_log(ctx, "EF(ODF) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1023|     39|		goto end;
 1024|     39|	}
 1025|     70|	buf = malloc(len);
 1026|     70|	if(buf == NULL) {
  ------------------
  |  Branch (1026:5): [True: 0, False: 70]
  ------------------
 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|     70|	err = -1; /* file state: not in cache */
 1032|     70|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1032:6): [True: 23, False: 47]
  ------------------
 1033|     23|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1034|     23|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
  |  Branch (1034:7): [True: 1, False: 22]
  ------------------
 1035|      1|			err = (int)len;
 1036|     23|	}
 1037|     70|	if (err < 0) {
  ------------------
  |  Branch (1037:6): [True: 69, False: 1]
  ------------------
 1038|     69|		err = sc_read_binary(card, 0, buf, len, 0);
 1039|     69|		if (err < 2) {
  ------------------
  |  Branch (1039:7): [True: 29, False: 40]
  ------------------
 1040|     29|			if (err < 0) {
  ------------------
  |  Branch (1040:8): [True: 25, False: 4]
  ------------------
 1041|     25|				sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1042|     25|			} else {
 1043|      4|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|      4|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1044|      4|				sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1045|      4|			}
 1046|     29|			goto end;
 1047|     29|		}
 1048|       |		/* sc_read_binary may return less than requested */
 1049|     40|		len = err;
 1050|       |
 1051|     40|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1051:7): [True: 13, False: 27]
  ------------------
 1052|     13|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1053|     13|		}
 1054|     40|	}
 1055|       |
 1056|     41|	if (parse_odf(buf, len, p15card)) {
  ------------------
  |  Branch (1056:6): [True: 20, False: 21]
  ------------------
 1057|     20|		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     20|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1058|     20|		sc_log(ctx, "Unable to parse ODF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1059|     20|		goto end;
 1060|     20|	}
 1061|     21|	free(buf);
 1062|     21|	buf = NULL;
 1063|       |
 1064|     21|	sc_log(ctx, "The following DFs were found:");
  ------------------
  |  |   71|     21|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1065|     56|	for (df = p15card->df_list; df; df = df->next)
  ------------------
  |  Branch (1065:30): [True: 35, False: 21]
  ------------------
 1066|     35|		sc_log(ctx, "  DF type %u, path %s, index %u, count %d", df->type,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1067|     21|				sc_print_path(&df->path), df->path.index, df->path.count);
 1068|       |
 1069|     21|	ok = 1;
 1070|    496|end:
 1071|    496|	if (buf != NULL)
  ------------------
  |  Branch (1071:6): [True: 49, False: 447]
  ------------------
 1072|     49|		free(buf);
 1073|    496|	if (!ok) {
  ------------------
  |  Branch (1073:6): [True: 475, False: 21]
  ------------------
 1074|    475|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|    475|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    475|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    475|	int _ret = r; \
  |  |  |  |  155|    475|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 475, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    475|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    294|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 294, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  157|    475|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    475|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    475|	return _ret; \
  |  |  |  |  163|    475|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1075|    475|	}
 1076|       |
 1077|     21|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1078|     21|}
sc_pkcs15_bind_internal_tokeninfo:
 1082|  12.9k|{
 1083|  12.9k|	struct sc_path tmppath;
 1084|  12.9k|	struct sc_card *card = p15card->card;
 1085|  12.9k|	struct sc_context *ctx = card->ctx;
 1086|  12.9k|	struct sc_pkcs15_tokeninfo tokeninfo;
 1087|  12.9k|	unsigned char *buf = NULL;
 1088|  12.9k|	size_t len;
 1089|  12.9k|	int err, ok = 0;
 1090|       |
 1091|  12.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1092|       |
 1093|  12.9k|	if (p15card->file_tokeninfo == NULL) {
  ------------------
  |  Branch (1093:6): [True: 12.9k, False: 5]
  ------------------
 1094|  12.9k|		sc_format_path("5032", &tmppath);
 1095|  12.9k|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1096|  12.9k|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|  12.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1096:7): [True: 10, False: 12.8k]
  ------------------
 1097|     10|			sc_log(ctx, "Cannot make absolute path to EF(TokenInfo); error:%i", err);
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1098|     10|			goto end;
 1099|     10|		}
 1100|  12.8k|		sc_log(ctx, "absolute path to EF(TokenInfo) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|  12.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1101|  12.8k|	}
 1102|      5|	else {
 1103|      5|		tmppath = p15card->file_tokeninfo->path;
 1104|      5|		sc_file_free(p15card->file_tokeninfo);
 1105|      5|		p15card->file_tokeninfo = NULL;
 1106|      5|	}
 1107|       |
 1108|  12.9k|	err = sc_select_file(card, &tmppath, &p15card->file_tokeninfo);
 1109|  12.9k|	if (err)   {
  ------------------
  |  Branch (1109:6): [True: 11.8k, False: 1.07k]
  ------------------
 1110|  11.8k|		sc_log(ctx, "cannot select EF(TokenInfo) file: %s", sc_strerror(err));
  ------------------
  |  |   71|  11.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1111|  11.8k|		goto end;
 1112|  11.8k|	}
 1113|       |
 1114|  1.07k|	len = p15card->file_tokeninfo->size;
 1115|  1.07k|	if (!len) {
  ------------------
  |  Branch (1115:6): [True: 384, False: 691]
  ------------------
 1116|    384|		sc_log(ctx, "EF(TokenInfo) is empty");
  ------------------
  |  |   71|    384|#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|    384|		goto end;
 1118|    384|	}
 1119|    691|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    691|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1119:6): [True: 90, False: 601]
  ------------------
 1120|     90|		sc_log(ctx, "EF(TokenInfo) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1121|     90|		goto end;
 1122|     90|	}
 1123|    601|	buf = malloc(len);
 1124|    601|	if(buf == NULL) {
  ------------------
  |  Branch (1124:5): [True: 0, False: 601]
  ------------------
 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|    601|	err = -1; /* file state: not in cache */
 1130|    601|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1130:6): [True: 189, False: 412]
  ------------------
 1131|    189|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1132|    189|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    189|#define SC_SUCCESS				0
  ------------------
  |  Branch (1132:7): [True: 1, False: 188]
  ------------------
 1133|      1|			err = (int)len;
 1134|    189|	}
 1135|    601|	if (err < 0) {
  ------------------
  |  Branch (1135:6): [True: 600, False: 1]
  ------------------
 1136|    600|		err = sc_read_binary(card, 0, buf, len, 0);
 1137|    600|		if (err <= 2) {
  ------------------
  |  Branch (1137:7): [True: 410, False: 190]
  ------------------
 1138|    410|			if (err < 0)   {
  ------------------
  |  Branch (1138:8): [True: 365, False: 45]
  ------------------
 1139|    365|				sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
  ------------------
  |  |   71|    365|#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|    365|			} else {
 1141|     45|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     45|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1142|     45|				sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1143|     45|			}
 1144|    410|			goto end;
 1145|    410|		}
 1146|       |		/* sc_read_binary may return less than requested */
 1147|    190|		len = err;
 1148|       |
 1149|    190|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1149:7): [True: 80, False: 110]
  ------------------
 1150|     80|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1151|     80|		}
 1152|    190|	}
 1153|       |
 1154|    191|	memset(&tokeninfo, 0, sizeof(tokeninfo));
 1155|    191|	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 1156|    191|	if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    191|#define SC_SUCCESS				0
  ------------------
  |  Branch (1156:6): [True: 169, False: 22]
  ------------------
 1157|    169|		sc_log(ctx, "cannot parse TokenInfo content: %s", sc_strerror(err));
  ------------------
  |  |   71|    169|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1158|    169|		goto end;
 1159|    169|	}
 1160|       |
 1161|     22|	sc_pkcs15_clear_tokeninfo(p15card->tokeninfo);
 1162|     22|	*(p15card->tokeninfo) = tokeninfo;
 1163|       |
 1164|     22|	if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
  ------------------
  |  Branch (1164:6): [True: 14, False: 8]
  |  Branch (1164:44): [True: 14, False: 0]
  ------------------
 1165|     14|		sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
 1166|     14|	}
 1167|       |
 1168|     22|	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
  ------------------
  |  Branch (1168:6): [True: 14, False: 8]
  |  Branch (1168:44): [True: 11, False: 3]
  ------------------
 1169|     11|		char *serial = calloc(1, card->serialnr.len*2 + 1);
 1170|     11|		size_t ii;
 1171|     11|		if (!serial) {
  ------------------
  |  Branch (1171:7): [True: 0, False: 11]
  ------------------
 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|    207|		for(ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (1176:12): [True: 196, False: 11]
  ------------------
 1177|    196|			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 1178|       |
 1179|     11|		p15card->tokeninfo->serial_number = serial;
 1180|     11|		sc_log(ctx, "p15card->tokeninfo->serial_number %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   71|     11|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1181|     11|	}
 1182|       |
 1183|     22|	ok = 1;
 1184|  12.9k|end:
 1185|  12.9k|	if (buf != NULL)
  ------------------
  |  Branch (1185:6): [True: 601, False: 12.3k]
  ------------------
 1186|    601|		free(buf);
 1187|  12.9k|	if (!ok) {
  ------------------
  |  Branch (1187:6): [True: 12.8k, False: 22]
  ------------------
 1188|  12.8k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  12.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.8k|	int _ret = r; \
  |  |  |  |  155|  12.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.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|  12.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.4k, False: 474]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.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|  12.8k|	return _ret; \
  |  |  |  |  163|  12.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1189|  12.8k|	}
 1190|       |
 1191|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1192|     22|}
sc_pkcs15_bind_internal:
 1196|  15.6k|{
 1197|  15.6k|	struct sc_card *card = p15card->card;
 1198|  15.6k|	struct sc_context *ctx = card->ctx;
 1199|  15.6k|	const struct sc_app_info *info = NULL;
 1200|  15.6k|	int err, ok = 0;
 1201|       |
 1202|  15.6k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  15.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  15.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  15.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  15.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 15.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|       |	/* Enumerate apps now */
 1204|  15.6k|	if (card->app_count < 0) {
  ------------------
  |  Branch (1204:6): [True: 0, False: 15.6k]
  ------------------
 1205|      0|		err = sc_enum_apps(card);
 1206|      0|		if (err != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1206:7): [True: 0, False: 0]
  ------------------
 1207|      0|			sc_log(ctx, "unable to enumerate apps: %s", sc_strerror(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__
  |  |  ------------------
  ------------------
 1208|      0|	}
 1209|  15.6k|	sc_file_free(p15card->file_app);
 1210|  15.6k|	p15card->file_app = sc_file_new();
 1211|  15.6k|	if (p15card->file_app == NULL) {
  ------------------
  |  Branch (1211:6): [True: 0, False: 15.6k]
  ------------------
 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|  15.6k|	sc_format_path("3F005015", &p15card->file_app->path);
 1217|       |
 1218|  15.6k|	info = sc_find_app(card, aid);
 1219|  15.6k|	if (info) {
  ------------------
  |  Branch (1219:6): [True: 4.26k, False: 11.3k]
  ------------------
 1220|  4.26k|		sc_log(ctx, "bind to application('%s',aid:'%s')", info->label, sc_dump_hex(info->aid.value, info->aid.len));
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 1221|  4.26k|		sc_pkcs15_free_app(p15card);
 1222|  4.26k|		p15card->app = sc_dup_app_info(info);
 1223|  4.26k|		if (!p15card->app) {
  ------------------
  |  Branch (1223:7): [True: 0, False: 4.26k]
  ------------------
 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|  4.26k|		if (info->path.len)
  ------------------
  |  Branch (1228:7): [True: 3.47k, False: 791]
  ------------------
 1229|  3.47k|			p15card->file_app->path = info->path;
 1230|       |
 1231|  4.26k|		if (info->ddo.value && info->ddo.len)
  ------------------
  |  Branch (1231:7): [True: 695, False: 3.57k]
  |  Branch (1231:26): [True: 668, False: 27]
  ------------------
 1232|    668|			parse_ddo(p15card, info->ddo.value, info->ddo.len);
 1233|       |
 1234|  11.3k|	} else if (aid) {
  ------------------
  |  Branch (1234:13): [True: 0, False: 11.3k]
  ------------------
 1235|      0|		sc_log(ctx, "Application '%s' not found", sc_dump_hex(aid->value, aid->len));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1236|      0|		err = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1237|      0|		goto end;
 1238|      0|	}
 1239|  15.6k|	sc_log(ctx, "application path '%s'", sc_print_path(&p15card->file_app->path));
  ------------------
  |  |   71|  15.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__
  |  |  ------------------
  ------------------
 1240|       |
 1241|       |	/* Check if pkcs15 directory exists */
 1242|  15.6k|	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|  15.6k|	if ((err != SC_SUCCESS) && (card->app_count < 1)) {
  ------------------
  |  |   28|  15.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1247:6): [True: 12.6k, False: 2.95k]
  |  Branch (1247:29): [True: 9.95k, False: 2.72k]
  ------------------
 1248|  9.95k|		sc_format_path("3F00", &p15card->file_app->path);
 1249|  9.95k|		err = SC_SUCCESS;
  ------------------
  |  |   28|  9.95k|#define SC_SUCCESS				0
  ------------------
 1250|  9.95k|	}
 1251|       |
 1252|  15.6k|	if (err < 0) {
  ------------------
  |  Branch (1252:6): [True: 2.72k, False: 12.9k]
  ------------------
 1253|  2.72k|		sc_log(ctx, "Cannot select application path");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1254|  2.72k|		goto end;
 1255|  2.72k|	}
 1256|       |
 1257|  12.9k|	err = sc_pkcs15_bind_internal_tokeninfo(p15card);
 1258|  12.9k|	if (err < 0) {
  ------------------
  |  Branch (1258:6): [True: 12.4k, False: 496]
  ------------------
 1259|  12.4k|		sc_log(ctx, "Cannot bind tokeninfo");
  ------------------
  |  |   71|  12.4k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1260|  12.4k|		goto end;
 1261|  12.4k|	}
 1262|       |
 1263|    496|	err = sc_pkcs15_bind_internal_odf(p15card);
 1264|    496|	if (err < 0) {
  ------------------
  |  Branch (1264:6): [True: 294, False: 202]
  ------------------
 1265|    294|		sc_log(ctx, "Cannot bind ODF");
  ------------------
  |  |   71|    294|#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|    294|		goto end;
 1267|    294|	}
 1268|       |
 1269|    202|	ok = 1;
 1270|  15.6k|end:
 1271|  15.6k|	if (!ok) {
  ------------------
  |  Branch (1271:6): [True: 15.4k, False: 202]
  ------------------
 1272|  15.4k|		sc_pkcs15_card_clear(p15card);
 1273|  15.4k|		if (err == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  15.4k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (1273:7): [True: 1.79k, False: 13.6k]
  ------------------
 1274|  1.79k|			err = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  1.79k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1275|  15.4k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  15.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.4k|	int _ret = r; \
  |  |  |  |  155|  15.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.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|  15.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.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|  15.4k|	return _ret; \
  |  |  |  |  163|  15.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1276|  15.4k|	}
 1277|       |
 1278|    202|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    202|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    202|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    202|	int _ret = r; \
  |  |  |  |  155|    202|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 202, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    202|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 202]
  |  |  |  |  ------------------
  |  |  |  |  157|    202|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    202|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    202|	return _ret; \
  |  |  |  |  163|    202|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1279|    202|}
pkcs15_get_default_use_file_cache:
 1282|  14.9k|{
 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|  14.9k|	const char *card_drivers_with_file_cache[] = {
 1289|  14.9k|			"atrust-acos",
 1290|  14.9k|			"belpic",
 1291|  14.9k|			"cac1",
 1292|  14.9k|			"cac",
 1293|  14.9k|			"cedulauy",
 1294|  14.9k|			"coolkey",
 1295|  14.9k|			"edo",
 1296|  14.9k|			"esteid2018",
 1297|  14.9k|			"esteid2025",
 1298|  14.9k|			"flex",
 1299|  14.9k|			"cyberflex",
 1300|  14.9k|			"gemsafeV1",
 1301|  14.9k|			"idprime",
 1302|  14.9k|			"itacns",
 1303|  14.9k|			"jpki",
 1304|  14.9k|			"MaskTech",
 1305|  14.9k|			"mcrd",
 1306|  14.9k|			"myeid",
 1307|  14.9k|			"npa",
 1308|  14.9k|			"nqapplet",
 1309|  14.9k|			"tcos",
 1310|  14.9k|			"dtrust",
 1311|  14.9k|			"lteid",
 1312|  14.9k|	};
 1313|       |
 1314|  14.9k|	if (NULL == card || NULL == card->driver || NULL == card->driver->short_name)
  ------------------
  |  Branch (1314:6): [True: 0, False: 14.9k]
  |  Branch (1314:22): [True: 0, False: 14.9k]
  |  Branch (1314:46): [True: 0, False: 14.9k]
  ------------------
 1315|      0|		return "no";
 1316|   287k|	for (size_t i = 0; i < (sizeof card_drivers_with_file_cache / sizeof *card_drivers_with_file_cache); i++) {
  ------------------
  |  Branch (1316:21): [True: 277k, False: 9.47k]
  ------------------
 1317|   277k|		if (0 == strcmp(card->driver->short_name, card_drivers_with_file_cache[i]))
  ------------------
  |  Branch (1317:7): [True: 5.51k, False: 272k]
  ------------------
 1318|  5.51k|			return "public";
 1319|   277k|	}
 1320|       |
 1321|  9.47k|	return "no";
 1322|  14.9k|}
sc_pkcs15_bind:
 1327|  14.9k|{
 1328|  14.9k|	struct sc_pkcs15_card *p15card = NULL;
 1329|  14.9k|	struct sc_context *ctx;
 1330|  14.9k|	scconf_block *conf_block = NULL;
 1331|  14.9k|	int r, emu_first, enable_emu;
 1332|  14.9k|	const char *use_file_cache;
 1333|  14.9k|	const char *pin_protected_certificate, *private_certificate;
 1334|       |
 1335|  14.9k|	if (card == NULL || p15card_out == NULL) {
  ------------------
  |  Branch (1335:6): [True: 0, False: 14.9k]
  |  Branch (1335:22): [True: 0, False: 14.9k]
  ------------------
 1336|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1337|      0|	}
 1338|  14.9k|	ctx = card->ctx;
 1339|       |
 1340|  14.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  14.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  14.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  14.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  14.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 14.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|  14.9k|	sc_log(ctx, "application(aid:'%s')", aid ? sc_dump_hex(aid->value, aid->len) : "empty");
  ------------------
  |  |   71|  29.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.67k, False: 11.3k]
  |  |  ------------------
  ------------------
 1342|       |
 1343|  14.9k|	p15card = sc_pkcs15_card_new();
 1344|  14.9k|	if (p15card == NULL)
  ------------------
  |  Branch (1344:6): [True: 0, False: 14.9k]
  ------------------
 1345|  14.9k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|       |
 1347|  14.9k|	p15card->card = card;
 1348|  14.9k|	p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  14.9k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1349|  14.9k|	use_file_cache = pkcs15_get_default_use_file_cache(card);
 1350|  14.9k|	p15card->opts.use_pin_cache = 1;
 1351|  14.9k|	p15card->opts.pin_cache_counter = 10;
 1352|  14.9k|	p15card->opts.pin_cache_ignore_user_consent = 0;
 1353|  14.9k|	pin_protected_certificate = "protect";
 1354|  14.9k|	private_certificate = "";
 1355|       |
 1356|  14.9k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1357|  14.9k|	if (conf_block) {
  ------------------
  |  Branch (1357:6): [True: 0, False: 14.9k]
  ------------------
 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|  14.9k|	if (0 == strcmp(use_file_cache, "yes")) {
  ------------------
  |  Branch (1368:6): [True: 0, False: 14.9k]
  ------------------
 1369|      0|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_ALL_FILES;
  ------------------
  |  |  606|      0|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
 1370|  14.9k|	} else if (0 == strcmp(use_file_cache, "public")) {
  ------------------
  |  Branch (1370:13): [True: 5.51k, False: 9.47k]
  ------------------
 1371|  5.51k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_PUBLIC_FILES;
  ------------------
  |  |  605|  5.51k|#define SC_PKCS15_OPTS_CACHE_PUBLIC_FILES		1
  ------------------
 1372|  9.47k|	} else if (0 == strcmp(use_file_cache, "no")) {
  ------------------
  |  Branch (1372:13): [True: 9.47k, False: 0]
  ------------------
 1373|  9.47k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  9.47k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1374|  9.47k|	}
 1375|       |
 1376|  14.9k|	if (0 == strcmp(pin_protected_certificate, "protect")) {
  ------------------
  |  Branch (1376:6): [True: 14.9k, False: 0]
  ------------------
 1377|  14.9k|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|  14.9k|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1378|  14.9k|	} 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|  14.9k|	if (0 == strcmp(private_certificate, "protect")) {
  ------------------
  |  Branch (1384:6): [True: 0, False: 14.9k]
  ------------------
 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|  14.9k|	} else if (0 == strcmp(private_certificate, "ignore")) {
  ------------------
  |  Branch (1386:13): [True: 0, False: 14.9k]
  ------------------
 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|  14.9k|	} else if (0 == strcmp(private_certificate, "declassify")) {
  ------------------
  |  Branch (1388:13): [True: 0, False: 14.9k]
  ------------------
 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|  14.9k|	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|  14.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__
  |  |  ------------------
  ------------------
 1392|  14.9k|			p15card->opts.use_file_cache, p15card->opts.use_pin_cache, p15card->opts.pin_cache_counter,
 1393|  14.9k|			p15card->opts.pin_cache_ignore_user_consent, p15card->opts.pin_protected_certificate);
 1394|       |
 1395|  14.9k|	r = sc_lock(card);
 1396|  14.9k|	if (r) {
  ------------------
  |  Branch (1396:6): [True: 0, False: 14.9k]
  ------------------
 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|  14.9k|	enable_emu = scconf_get_bool(conf_block, "enable_pkcs15_emulation", 1);
 1403|  14.9k|	if (enable_emu) {
  ------------------
  |  Branch (1403:6): [True: 14.9k, False: 0]
  ------------------
 1404|  14.9k|		sc_log(ctx, "PKCS#15 emulation enabled");
  ------------------
  |  |   71|  14.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__
  |  |  ------------------
  ------------------
 1405|  14.9k|		emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
 1406|  14.9k|		if (emu_first || sc_pkcs15_is_emulation_only(card)) {
  ------------------
  |  Branch (1406:7): [True: 0, False: 14.9k]
  |  Branch (1406:20): [True: 2.98k, False: 11.9k]
  ------------------
 1407|  2.98k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1408|  2.98k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  2.98k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1408:8): [True: 861, False: 2.12k]
  ------------------
 1409|    861|				goto done;
 1410|  2.12k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1411|  2.12k|			if (r < 0)
  ------------------
  |  Branch (1411:8): [True: 2.08k, False: 40]
  ------------------
 1412|  2.08k|				goto error;
 1413|  11.9k|		} else {
 1414|  11.9k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1415|  11.9k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  11.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1415:8): [True: 151, False: 11.8k]
  ------------------
 1416|    151|				goto done;
 1417|  11.8k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1418|  11.8k|			if (r < 0)
  ------------------
  |  Branch (1418:8): [True: 7.31k, False: 4.52k]
  ------------------
 1419|  7.31k|				goto error;
 1420|  11.8k|		}
 1421|  14.9k|	}
 1422|      0|	else {
 1423|      0|		r = sc_pkcs15_bind_internal(p15card, aid);
 1424|      0|		if (r < 0)
  ------------------
  |  Branch (1424:7): [True: 0, False: 0]
  ------------------
 1425|      0|			goto error;
 1426|      0|	}
 1427|  5.57k|done:
 1428|  5.57k|	*p15card_out = p15card;
 1429|  5.57k|	sc_unlock(card);
 1430|  5.57k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  5.57k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.57k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.57k|	int _ret = r; \
  |  |  |  |  155|  5.57k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.57k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5.57k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.57k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.57k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.57k|	return _ret; \
  |  |  |  |  163|  5.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1431|  9.40k|error:
 1432|  9.40k|	sc_unlock(card);
 1433|  9.40k|	sc_pkcs15_card_free(p15card);
 1434|  9.40k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  9.40k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.40k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.40k|	int _ret = r; \
  |  |  |  |  155|  9.40k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.40k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.40k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.40k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.40k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.40k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.40k|	return _ret; \
  |  |  |  |  163|  9.40k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1435|  9.40k|}
sc_pkcs15_unbind:
 1440|  5.57k|{
 1441|  5.57k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC) {
  ------------------
  |  |  519|  5.57k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (1441:6): [True: 0, False: 5.57k]
  |  Branch (1441:25): [True: 0, False: 5.57k]
  ------------------
 1442|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1443|      0|	}
 1444|       |
 1445|  5.57k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  5.57k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.57k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.57k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.57k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.57k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1446|  5.57k|	if (p15card->dll_handle)
  ------------------
  |  Branch (1446:6): [True: 0, False: 5.57k]
  ------------------
 1447|      0|		sc_dlclose(p15card->dll_handle);
 1448|  5.57k|	sc_pkcs15_pincache_clear(p15card);
 1449|  5.57k|	sc_pkcs15_card_free(p15card);
 1450|  5.57k|	return 0;
 1451|  5.57k|}
sc_pkcs15_get_objects:
 1539|  92.5k|{
 1540|  92.5k|	return sc_pkcs15_get_objects_cond(p15card, type, NULL, NULL, ret, ret_size);
 1541|  92.5k|}
sc_pkcs15_search_objects:
 1722|     49|{
 1723|     49|	return __sc_pkcs15_search_objects(p15card,
 1724|     49|			sk->class_mask, sk->type,
 1725|     49|			compare_obj_key, sk,
 1726|     49|			ret, ret_size);
 1727|     49|}
sc_pkcs15_get_objects_cond:
 1734|  93.4k|{
 1735|  93.4k|	return __sc_pkcs15_search_objects(p15card, 0, type,
 1736|  93.4k|			func, func_arg, ret, ret_size);
 1737|  93.4k|}
sc_pkcs15_find_object_by_id:
 1743|  1.31k|{
 1744|  1.31k|	struct sc_pkcs15_search_key sk;
 1745|  1.31k|	int	r;
 1746|       |
 1747|  1.31k|	memset(&sk, 0, sizeof(sk));
 1748|  1.31k|	sk.id = id;
 1749|       |
 1750|  1.31k|	r = __sc_pkcs15_search_objects(p15card, 0, type, compare_obj_key, &sk, out, 1);
 1751|  1.31k|	if (r < 0)
  ------------------
  |  Branch (1751:6): [True: 0, False: 1.31k]
  ------------------
 1752|      0|		return r;
 1753|  1.31k|	if (r == 0)
  ------------------
  |  Branch (1753:6): [True: 1.14k, False: 171]
  ------------------
 1754|  1.14k|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  1.14k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1755|    171|	return 0;
 1756|  1.31k|}
sc_pkcs15_find_cert_by_id:
 1762|  1.30k|{
 1763|  1.30k|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, id, out);
  ------------------
  |  |  438|  1.30k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 1764|  1.30k|}
sc_pkcs15_find_pin_by_auth_id:
 1794|     10|{
 1795|     10|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_AUTH, id, out);
  ------------------
  |  |  444|     10|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1796|     10|}
sc_pkcs15_find_so_pin:
 1853|    942|{
 1854|    942|	struct sc_pkcs15_search_key sk;
 1855|       |
 1856|    942|	memset(&sk, 0, sizeof(sk));
 1857|    942|	sk.flags_mask = sk.flags_value = SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   61|    942|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
 1858|       |
 1859|    942|	return find_by_key(p15card, SC_PKCS15_TYPE_AUTH_PIN, &sk, out);
  ------------------
  |  |  445|    942|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
 1860|    942|}
sc_pkcs15_find_pin_by_flags:
 1867|  8.35k|{
 1868|  8.35k|	struct sc_context *ctx = p15card->card->ctx;
 1869|  8.35k|	struct sc_pkcs15_object *auths[SC_PKCS15_MAX_PINS];
 1870|  8.35k|	int r, i, num, idx = 0;
 1871|       |
 1872|  8.35k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  8.35k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  8.35k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  8.35k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  8.35k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1873|  8.35k|	sc_log(ctx, "Find PIN flags:0x%X, mask:0x%X, index:%i", flags, mask, index ? *index : -1);
  ------------------
  |  |   71|  16.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 8.35k]
  |  |  ------------------
  ------------------
 1874|  8.35k|	if (index)
  ------------------
  |  Branch (1874:6): [True: 0, False: 8.35k]
  ------------------
 1875|      0|		idx = *index;
 1876|       |	/* Get authentication PKCS#15 objects that are present in the given application */
 1877|  8.35k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, auths, SC_PKCS15_MAX_PINS);
  ------------------
  |  |  445|  8.35k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
              	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, auths, SC_PKCS15_MAX_PINS);
  ------------------
  |  |   34|  8.35k|#define SC_PKCS15_MAX_PINS		8
  ------------------
 1878|  8.35k|	if (r < 0)
  ------------------
  |  Branch (1878:6): [True: 0, False: 8.35k]
  ------------------
 1879|      0|		return r;
 1880|  8.35k|	num = r;
 1881|       |
 1882|  10.7k|	for (i=idx; i<num; i++)   {
  ------------------
  |  Branch (1882:14): [True: 6.21k, False: 4.52k]
  ------------------
 1883|  6.21k|		struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *)(*(auths + i))->data;
 1884|       |
 1885|  6.21k|		if (!pin_info || pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  6.21k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1885:7): [True: 0, False: 6.21k]
  |  Branch (1885:20): [True: 0, False: 6.21k]
  ------------------
 1886|      0|			continue;
 1887|       |
 1888|  6.21k|		if ((pin_info->attrs.pin.flags & mask) != flags)
  ------------------
  |  Branch (1888:7): [True: 2.38k, False: 3.83k]
  ------------------
 1889|  2.38k|			continue;
 1890|       |
 1891|  3.83k|		if (out)
  ------------------
  |  Branch (1891:7): [True: 3.83k, False: 0]
  ------------------
 1892|  3.83k|			*out = *(auths + i);
 1893|  3.83k|		if (index)
  ------------------
  |  Branch (1893:7): [True: 0, False: 3.83k]
  ------------------
 1894|      0|			*index = i;
 1895|       |
 1896|  3.83k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.83k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.83k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.83k|	int _ret = r; \
  |  |  |  |  155|  3.83k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.83k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.83k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.83k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.83k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.83k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.83k|	return _ret; \
  |  |  |  |  163|  3.83k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1897|  3.83k|	}
 1898|       |
 1899|  4.52k|	LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  4.52k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.52k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.52k|	int _ret = r; \
  |  |  |  |  155|  4.52k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.52k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.52k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.52k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.52k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.52k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.52k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.52k|	return _ret; \
  |  |  |  |  163|  4.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1900|  4.52k|}
sc_pkcs15_add_object:
 1986|  36.5k|{
 1987|  36.5k|	struct sc_pkcs15_object *p = p15card->obj_list;
 1988|       |
 1989|  36.5k|	if (!obj)
  ------------------
  |  Branch (1989:6): [True: 0, False: 36.5k]
  ------------------
 1990|      0|		return 0;
 1991|  36.5k|	obj->next = obj->prev = NULL;
 1992|  36.5k|	if (p15card->obj_list == NULL) {
  ------------------
  |  Branch (1992:6): [True: 4.96k, False: 31.5k]
  ------------------
 1993|  4.96k|		p15card->obj_list = obj;
 1994|  4.96k|		return 0;
 1995|  4.96k|	}
 1996|   393k|	while (p->next != NULL)
  ------------------
  |  Branch (1996:9): [True: 362k, False: 31.5k]
  ------------------
 1997|   362k|		p = p->next;
 1998|  31.5k|	p->next = obj;
 1999|  31.5k|	obj->prev = p;
 2000|       |
 2001|  31.5k|	return 0;
 2002|  36.5k|}
sc_pkcs15_free_object:
 2037|  36.5k|{
 2038|  36.5k|	if (!obj)
  ------------------
  |  Branch (2038:6): [True: 0, False: 36.5k]
  ------------------
 2039|      0|		return;
 2040|  36.5k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  36.5k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 2041|  3.67k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  3.67k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2041:2): [True: 3.67k, False: 32.8k]
  ------------------
 2042|  3.67k|		sc_pkcs15_free_prkey_info((sc_pkcs15_prkey_info_t *)obj->data);
 2043|  3.67k|		break;
 2044|  1.16k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.16k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (2044:2): [True: 1.16k, False: 35.3k]
  ------------------
 2045|       |		/* This is normally passed to framework-pkcs15,
 2046|       |		 * but if something fails on the way, it would not get freed */
 2047|  1.16k|		if (obj->emulated) {
  ------------------
  |  Branch (2047:7): [True: 1.02k, False: 144]
  ------------------
 2048|  1.02k|			sc_pkcs15_free_pubkey(obj->emulated);
 2049|  1.02k|		}
 2050|  1.16k|		sc_pkcs15_free_pubkey_info((sc_pkcs15_pubkey_info_t *)obj->data);
 2051|  1.16k|		break;
 2052|  2.52k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  2.52k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (2052:2): [True: 2.52k, False: 34.0k]
  ------------------
 2053|  2.52k|		sc_pkcs15_free_cert_info((sc_pkcs15_cert_info_t *)obj->data);
 2054|  2.52k|		break;
 2055|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2055:2): [True: 0, False: 36.5k]
  ------------------
 2056|      0|		sc_pkcs15_free_skey_info((sc_pkcs15_skey_info_t *)obj->data);
 2057|      0|		break;
 2058|  23.0k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  23.0k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2058:2): [True: 23.0k, False: 13.4k]
  ------------------
 2059|  23.0k|		sc_pkcs15_free_data_info((sc_pkcs15_data_info_t *)obj->data);
 2060|  23.0k|		break;
 2061|  6.11k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  6.11k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2061:2): [True: 6.11k, False: 30.4k]
  ------------------
 2062|  6.11k|		sc_pkcs15_free_auth_info((sc_pkcs15_auth_info_t *)obj->data);
 2063|  6.11k|		break;
 2064|      0|	default:
  ------------------
  |  Branch (2064:2): [True: 0, False: 36.5k]
  ------------------
 2065|      0|		free(obj->data);
 2066|  36.5k|	}
 2067|       |
 2068|  36.5k|	sc_pkcs15_free_object_content(obj);
 2069|       |
 2070|  36.5k|	free(obj);
 2071|  36.5k|}
sc_pkcs15_add_df:
 2076|  9.11k|{
 2077|  9.11k|	struct sc_pkcs15_df *p, *newdf;
 2078|       |
 2079|  9.11k|	newdf = calloc(1, sizeof(struct sc_pkcs15_df));
 2080|  9.11k|	if (newdf == NULL)
  ------------------
  |  Branch (2080:6): [True: 0, False: 9.11k]
  ------------------
 2081|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2082|  9.11k|	newdf->path = *path;
 2083|  9.11k|	newdf->type = type;
 2084|       |
 2085|  9.11k|	if (p15card->df_list == NULL) {
  ------------------
  |  Branch (2085:6): [True: 4.98k, False: 4.13k]
  ------------------
 2086|  4.98k|		p15card->df_list = newdf;
 2087|  4.98k|		return 0;
 2088|  4.98k|	}
 2089|       |
 2090|  4.13k|	p = p15card->df_list;
 2091|  6.59k|	while (p->next != NULL)
  ------------------
  |  Branch (2091:9): [True: 2.46k, False: 4.13k]
  ------------------
 2092|  2.46k|		p = p->next;
 2093|  4.13k|	p->next = newdf;
 2094|  4.13k|	newdf->prev = p;
 2095|       |
 2096|  4.13k|	return 0;
 2097|  9.11k|}
sc_pkcs15_parse_df:
 2192|    288|{
 2193|    288|	struct sc_context *ctx = p15card->card->ctx;
 2194|    288|	unsigned char *buf;
 2195|    288|	const unsigned char *p;
 2196|    288|	size_t bufsize;
 2197|    288|	int r;
 2198|    288|	struct sc_pkcs15_object *obj = NULL;
 2199|    288|	int (* func)(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
 2200|    288|		     const u8 **nbuf, size_t *nbufsize) = NULL;
 2201|       |
 2202|    288|	sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
  ------------------
  |  |   71|    288|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2203|       |
 2204|    288|	if (df->enumerated)
  ------------------
  |  Branch (2204:6): [True: 0, False: 288]
  ------------------
 2205|    288|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2206|       |
 2207|    288|	switch (df->type) {
  ------------------
  |  Branch (2207:10): [True: 283, False: 5]
  ------------------
 2208|    138|	case SC_PKCS15_PRKDF:
  ------------------
  |  |  488|    138|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (2208:2): [True: 138, False: 150]
  ------------------
 2209|    138|		func = sc_pkcs15_decode_prkdf_entry;
 2210|    138|		break;
 2211|     59|	case SC_PKCS15_PUKDF:
  ------------------
  |  |  489|     59|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (2211:2): [True: 59, False: 229]
  ------------------
 2212|     59|		func = sc_pkcs15_decode_pukdf_entry;
 2213|     59|		break;
 2214|      5|	case SC_PKCS15_SKDF:
  ------------------
  |  |  491|      5|#define SC_PKCS15_SKDF			3
  ------------------
  |  Branch (2214:2): [True: 5, False: 283]
  ------------------
 2215|      5|		func = sc_pkcs15_decode_skdf_entry;
 2216|      5|		break;
 2217|     17|	case SC_PKCS15_CDF:
  ------------------
  |  |  492|     17|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (2217:2): [True: 17, False: 271]
  ------------------
 2218|     19|	case SC_PKCS15_CDF_TRUSTED:
  ------------------
  |  |  493|     19|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
  |  Branch (2218:2): [True: 2, False: 286]
  ------------------
 2219|     24|	case SC_PKCS15_CDF_USEFUL:
  ------------------
  |  |  494|     24|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
  |  Branch (2219:2): [True: 5, False: 283]
  ------------------
 2220|     24|		func = sc_pkcs15_decode_cdf_entry;
 2221|     24|		break;
 2222|      4|	case SC_PKCS15_DODF:
  ------------------
  |  |  495|      4|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (2222:2): [True: 4, False: 284]
  ------------------
 2223|      4|		func = sc_pkcs15_decode_dodf_entry;
 2224|      4|		break;
 2225|     53|	case SC_PKCS15_AODF:
  ------------------
  |  |  496|     53|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (2225:2): [True: 53, False: 235]
  ------------------
 2226|     53|		func = sc_pkcs15_decode_aodf_entry;
 2227|     53|		break;
 2228|    288|	}
 2229|    288|	if (func == NULL) {
  ------------------
  |  Branch (2229:6): [True: 5, False: 283]
  ------------------
 2230|      5|		sc_log(ctx, "unknown DF type: %d", df->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2231|      5|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2232|      5|	}
 2233|    283|	r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, 0);
 2234|    283|	LOG_TEST_RET(ctx, r, "pkcs15 read file failed");
  ------------------
  |  |  174|    283|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    283|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    283|	int _ret = (r); \
  |  |  |  |  168|    283|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 243, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  169|    243|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    243|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    243|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    243|		return _ret; \
  |  |  |  |  172|    243|	} \
  |  |  |  |  173|    283|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2235|       |
 2236|     40|	p = buf;
 2237|     40|	while (bufsize && *p != 0x00) {
  ------------------
  |  Branch (2237:9): [True: 33, False: 7]
  |  Branch (2237:20): [True: 30, False: 3]
  ------------------
 2238|       |
 2239|     30|		obj = calloc(1, sizeof(struct sc_pkcs15_object));
 2240|     30|		if (obj == NULL) {
  ------------------
  |  Branch (2240:7): [True: 0, False: 30]
  ------------------
 2241|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2242|      0|			goto ret;
 2243|      0|		}
 2244|     30|		r = func(p15card, obj, &p, &bufsize);
 2245|     30|		if (r) {
  ------------------
  |  Branch (2245:7): [True: 30, False: 0]
  ------------------
 2246|     30|			free(obj);
 2247|     30|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|     30|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (2247:8): [True: 9, False: 21]
  ------------------
 2248|      9|				r = 0;
 2249|      9|				break;
 2250|      9|			}
 2251|     21|			sc_log(ctx, "%s: Error decoding DF entry", 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__
  |  |  ------------------
  ------------------
 2252|     21|			goto ret;
 2253|     30|		}
 2254|       |
 2255|      0|		obj->df = df;
 2256|      0|		r = sc_pkcs15_add_object(p15card, obj);
 2257|      0|		if (r) {
  ------------------
  |  Branch (2257:7): [True: 0, False: 0]
  ------------------
 2258|      0|			if (obj->data)
  ------------------
  |  Branch (2258:8): [True: 0, False: 0]
  ------------------
 2259|      0|				free(obj->data);
 2260|      0|			free(obj);
 2261|      0|			sc_log(ctx, "%s: Error adding object", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2262|      0|			goto ret;
 2263|      0|		}
 2264|      0|		while (bufsize > 0 && *p == 00) {
  ------------------
  |  Branch (2264:10): [True: 0, False: 0]
  |  Branch (2264:25): [True: 0, False: 0]
  ------------------
 2265|      0|			bufsize--;
 2266|      0|			p++;
 2267|      0|		}
 2268|     19|	};
 2269|       |
 2270|     19|	if (r > 0)
  ------------------
  |  Branch (2270:6): [True: 0, False: 19]
  ------------------
 2271|      0|		r = 0;
 2272|     40|ret:
 2273|     40|	df->enumerated = 1;
 2274|     40|	free(buf);
 2275|     40|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|     40|}
sc_pkcs15_read_file:
 2528|  13.0k|{
 2529|  13.0k|	struct sc_context *ctx;
 2530|  13.0k|	struct sc_file *file = NULL;
 2531|  13.0k|	unsigned char *data = NULL;
 2532|  13.0k|	size_t	len = 0, offset = 0;
 2533|  13.0k|	int	r;
 2534|       |
 2535|  13.0k|	if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
  ------------------
  |  Branch (2535:6): [True: 0, False: 13.0k]
  |  Branch (2535:25): [True: 0, False: 13.0k]
  |  Branch (2535:50): [True: 0, False: 13.0k]
  |  Branch (2535:69): [True: 0, False: 13.0k]
  ------------------
 2536|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2537|      0|	}
 2538|  13.0k|	ctx = p15card->card->ctx;
 2539|       |
 2540|  13.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2541|  13.0k|	sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
  ------------------
  |  |   71|  13.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2542|       |
 2543|  13.0k|	r = -1; /* file state: not in cache */
 2544|  13.0k|	if (p15card->opts.use_file_cache
  ------------------
  |  Branch (2544:6): [True: 5.37k, False: 7.64k]
  ------------------
 2545|  5.37k|	    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|  5.37k|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2545:10): [True: 0, False: 5.37k]
  |  Branch (2545:77): [True: 5.37k, False: 0]
  ------------------
 2546|  5.37k|		r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len);
 2547|       |
 2548|  5.37k|		if (!r && in_path->aid.len > 0 && in_path->len >= 2)   {
  ------------------
  |  Branch (2548:7): [True: 733, False: 4.64k]
  |  Branch (2548:13): [True: 151, False: 582]
  |  Branch (2548:37): [True: 151, False: 0]
  ------------------
 2549|    151|			struct sc_path parent = *in_path;
 2550|       |
 2551|    151|			parent.len -= 2;
 2552|    151|			parent.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    151|#define SC_PATH_TYPE_PATH		2
  ------------------
 2553|    151|			r = sc_select_file(p15card->card, &parent, NULL);
 2554|    151|		}
 2555|  5.37k|	}
 2556|       |
 2557|  13.0k|	if (r) {
  ------------------
  |  Branch (2557:6): [True: 12.3k, False: 683]
  ------------------
 2558|  12.3k|		r = sc_lock(p15card->card);
 2559|  12.3k|		if (r)
  ------------------
  |  Branch (2559:7): [True: 0, False: 12.3k]
  ------------------
 2560|      0|			goto fail;
 2561|  12.3k|		r = sc_select_file(p15card->card, in_path, &file);
 2562|  12.3k|		if (r)
  ------------------
  |  Branch (2562:7): [True: 9.11k, False: 3.22k]
  ------------------
 2563|  9.11k|			goto fail_unlock;
 2564|       |
 2565|       |		/* Handle the case where the ASN.1 Path object specified
 2566|       |		 * index and length values */
 2567|       |
 2568|  3.22k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  3.22k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2568:7): [True: 67, False: 3.16k]
  ------------------
 2569|       |
 2570|       |			// in_path->index: record_no
 2571|       |			// in_path->count: ignored!
 2572|       |
 2573|     67|			if(file->record_length > 0) {
  ------------------
  |  Branch (2573:7): [True: 55, False: 12]
  ------------------
 2574|     55|				if(file->record_length > MAX_FILE_SIZE) {
  ------------------
  |  |  220|     55|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2574:8): [True: 0, False: 55]
  ------------------
 2575|      0|					len = MAX_FILE_SIZE;
  ------------------
  |  |  220|      0|#define MAX_FILE_SIZE 65535
  ------------------
 2576|      0|					sc_log(ctx, "  record size truncated, encoded length: %zu", file->record_length);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2577|     55|				} else {
 2578|     55|					len = file->record_length;
 2579|     55|				}
 2580|     55|			} else {
 2581|     12|				len = MAX_FILE_SIZE;
  ------------------
  |  |  220|     12|#define MAX_FILE_SIZE 65535
  ------------------
 2582|     12|			}
 2583|       |
 2584|     67|			if ((in_path->index <= 0) || (in_path->index > (int)(file->record_count))) {
  ------------------
  |  Branch (2584:8): [True: 11, False: 56]
  |  Branch (2584:33): [True: 10, False: 46]
  ------------------
 2585|     21|				sc_log(ctx, "  record number out of bounds: %d", in_path->index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2586|     21|				r = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     21|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
 2587|     21|				goto fail_unlock;
 2588|     21|			}
 2589|       |
 2590|  3.16k|		} else {
 2591|       |
 2592|  3.16k|			if (in_path->count < 0) {
  ------------------
  |  Branch (2592:8): [True: 1.91k, False: 1.24k]
  ------------------
 2593|  1.91k|				if (file->size)
  ------------------
  |  Branch (2593:9): [True: 1.74k, False: 164]
  ------------------
 2594|  1.74k|					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|  1.74k|#define MAX_FILE_SIZE 65535
  ------------------
              					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|      8|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2594:12): [True: 8, False: 1.74k]
  ------------------
 2595|    164|				else
 2596|    164|					len = 1024;
 2597|  1.91k|				offset = 0;
 2598|  1.91k|			}
 2599|  1.24k|			else {
 2600|  1.24k|				offset = in_path->index;
 2601|  1.24k|				len = in_path->count;
 2602|       |				/* Make sure we're within proper bounds */
 2603|  1.24k|				if (offset >= file->size || offset + len > file->size) {
  ------------------
  |  Branch (2603:9): [True: 29, False: 1.22k]
  |  Branch (2603:33): [True: 29, False: 1.19k]
  ------------------
 2604|     58|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     58|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2605|     58|					goto fail_unlock;
 2606|     58|				}
 2607|  1.24k|			}
 2608|  3.16k|		}
 2609|       |
 2610|  3.15k|		free(data);
 2611|  3.15k|		data = malloc(len);
 2612|  3.15k|		if (data == NULL) {
  ------------------
  |  Branch (2612:7): [True: 0, False: 3.15k]
  ------------------
 2613|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2614|      0|			goto fail_unlock;
 2615|      0|		}
 2616|       |
 2617|  3.15k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE_TLV) {
  ------------------
  |  |  225|  3.15k|#define SC_FILE_EF_LINEAR_VARIABLE_TLV	0x05
  ------------------
  |  Branch (2617:7): [True: 83, False: 3.06k]
  ------------------
 2618|     83|			unsigned int i;
 2619|     83|			size_t l, record_len;
 2620|     83|			unsigned char *head = data;
 2621|       |
 2622|  1.01k|			for (i=1; ; i++) {
 2623|  1.01k|				l = len - (head - data);
 2624|  1.01k|				if (l > 256) {
  ------------------
  |  Branch (2624:9): [True: 271, False: 743]
  ------------------
 2625|    271|					l = 256;
 2626|    271|				}
 2627|  1.01k|				r = sc_read_record(p15card->card, i, 0, head, l, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  1.01k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2628|  1.01k|				if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.01k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (2628:9): [True: 1, False: 1.01k]
  ------------------
 2629|      1|					break;
 2630|  1.01k|				if (r < 0) {
  ------------------
  |  Branch (2630:9): [True: 56, False: 957]
  ------------------
 2631|     56|					goto fail_unlock;
 2632|     56|				}
 2633|    957|				if (r < 2)
  ------------------
  |  Branch (2633:9): [True: 25, False: 932]
  ------------------
 2634|     25|					break;
 2635|    932|				record_len = head[1];
 2636|    932|				if (record_len != 0xff) {
  ------------------
  |  Branch (2636:9): [True: 908, False: 24]
  ------------------
 2637|    908|					memmove(head, head+2, r-2);
 2638|    908|					head += (r-2);
 2639|    908|				}
 2640|     24|				else {
 2641|     24|					if (r < 4)
  ------------------
  |  Branch (2641:10): [True: 1, False: 23]
  ------------------
 2642|      1|						break;
 2643|     23|					memmove(head, head+4, r-4);
 2644|     23|					head += (r-4);
 2645|     23|				}
 2646|    932|			}
 2647|     27|			len = head-data;
 2648|     27|		}
 2649|  3.06k|		else if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  3.06k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2649:12): [True: 46, False: 3.02k]
  ------------------
 2650|     46|			r = sc_read_record(p15card->card, in_path->index, (unsigned)offset, data, len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|     46|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2651|     46|			if (r < 0) {
  ------------------
  |  Branch (2651:8): [True: 11, False: 35]
  ------------------
 2652|     11|				goto fail_unlock;
 2653|     11|			}
 2654|       |			/* sc_read_record may return less than requested */
 2655|     35|			len = r;
 2656|     35|		}
 2657|  3.02k|		else {
 2658|  3.02k|			unsigned long flags = 0;
 2659|  3.02k|			r = sc_read_binary(p15card->card, (unsigned)offset, data, len, &flags);
 2660|  3.02k|			if (r < 0) {
  ------------------
  |  Branch (2660:8): [True: 652, False: 2.36k]
  ------------------
 2661|    652|				goto fail_unlock;
 2662|    652|			}
 2663|       |			/* sc_read_binary may return less than requested */
 2664|  2.36k|			len = r;
 2665|       |
 2666|  2.36k|			if (flags & SC_FILE_FLAG_COMPRESSED_AUTO
  ------------------
  |  |  230|  4.73k|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  |  Branch (2666:8): [True: 159, False: 2.21k]
  ------------------
 2667|  2.21k|			    || flags & SC_FILE_FLAG_COMPRESSED_ZLIB
  ------------------
  |  |  231|  4.57k|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2667:11): [True: 0, False: 2.21k]
  ------------------
 2668|  2.21k|			    || flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|  2.21k|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2668:11): [True: 0, False: 2.21k]
  ------------------
 2669|    159|				unsigned char *decompressed_buf = NULL;
 2670|    159|				size_t decompressed_len = 0;
 2671|    159|				r = decompress_file(p15card->card, data, len, &decompressed_buf, &decompressed_len, flags);
 2672|    159|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
  |  Branch (2672:9): [True: 159, False: 0]
  ------------------
 2673|    159|					goto fail_unlock;
 2674|    159|				}
 2675|      0|				free(data);
 2676|      0|				data = decompressed_buf;
 2677|      0|				len = decompressed_len;
 2678|      0|			}
 2679|  2.36k|		}
 2680|  2.27k|		sc_unlock(p15card->card);
 2681|       |
 2682|  2.27k|		sc_file_free(file);
 2683|       |
 2684|  2.27k|		if (p15card->opts.use_file_cache && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|    681|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2684:7): [True: 681, False: 1.59k]
  |  Branch (2684:40): [True: 0, False: 681]
  |  Branch (2684:107): [True: 681, False: 0]
  ------------------
 2685|    681|			sc_pkcs15_cache_file(p15card, in_path, data, len);
 2686|    681|		}
 2687|  2.27k|		if (len == 0) {
  ------------------
  |  Branch (2687:7): [True: 335, False: 1.93k]
  ------------------
 2688|    335|			free(data);
 2689|    335|			data = NULL;
 2690|    335|		}
 2691|  2.27k|	}
 2692|  2.95k|	*buf = data;
 2693|  2.95k|	*buflen = len;
 2694|  2.95k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.95k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.95k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.95k|	int _ret = r; \
  |  |  |  |  155|  2.95k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.95k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.95k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.95k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.95k|	return _ret; \
  |  |  |  |  163|  2.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2695|       |
 2696|  10.0k|fail_unlock:
 2697|  10.0k|	sc_unlock(p15card->card);
 2698|  10.0k|fail:
 2699|  10.0k|	free(data);
 2700|  10.0k|	sc_file_free(file);
 2701|  10.0k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  10.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.0k|	int _ret = r; \
  |  |  |  |  155|  10.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  10.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  10.0k|	return _ret; \
  |  |  |  |  163|  10.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2702|  10.0k|}
sc_pkcs15_compare_id:
 2707|  46.6k|{
 2708|  46.6k|	if (id1 == NULL || id2 == NULL)
  ------------------
  |  Branch (2708:6): [True: 0, False: 46.6k]
  |  Branch (2708:21): [True: 0, False: 46.6k]
  ------------------
 2709|      0|		return 0;
 2710|  46.6k|	if (id1->len != id2->len)
  ------------------
  |  Branch (2710:6): [True: 4.14k, False: 42.4k]
  ------------------
 2711|  4.14k|		return 0;
 2712|  42.4k|	return memcmp(id1->value, id2->value, id1->len) == 0;
 2713|  46.6k|}
sc_pkcs15_format_id:
 2718|   105k|{
 2719|   105k|	size_t len;
 2720|       |
 2721|   105k|	if (!id)
  ------------------
  |  Branch (2721:6): [True: 0, False: 105k]
  ------------------
 2722|      0|		return;
 2723|   105k|	len = sizeof(id->value);
 2724|       |
 2725|   105k|	if (sc_hex_to_bin(str, id->value, &len) != SC_SUCCESS)
  ------------------
  |  |   28|   105k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2725:6): [True: 149, False: 105k]
  ------------------
 2726|    149|		id->len = 0;
 2727|   105k|	else
 2728|   105k|		id->len = len;
 2729|   105k|}
sc_pkcs15_print_id:
 2734|  16.4k|{
 2735|  16.4k|	static char buffer[256];
 2736|       |
 2737|  16.4k|	sc_bin_to_hex(id->value, id->len, buffer, sizeof(buffer), '\0');
 2738|  16.4k|	return buffer;
 2739|  16.4k|}
sc_pkcs15_make_absolute_path:
 2752|  13.4k|{
 2753|       |	/* nothing to do if child has valid 'aid' */
 2754|  13.4k|	if (child->aid.len)
  ------------------
  |  Branch (2754:6): [True: 0, False: 13.4k]
  ------------------
 2755|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2756|       |
 2757|  13.4k|	if (parent->aid.len)   {
  ------------------
  |  Branch (2757:6): [True: 0, False: 13.4k]
  ------------------
 2758|      0|		sc_path_t ppath;
 2759|       |
 2760|       |		/* child inherits parent's 'aid' */
 2761|      0|		child->aid = parent->aid;
 2762|      0|		if (!parent->len)
  ------------------
  |  Branch (2762:7): [True: 0, False: 0]
  ------------------
 2763|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2764|       |
 2765|       |		/* parent has valid 'path' -- concatenate it with the child's one */
 2766|      0|		memcpy(&ppath, parent, sizeof(sc_path_t));
 2767|      0|		ppath.aid.len = 0;
 2768|      0|		ppath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 2769|      0|		return sc_concatenate_path(child, &ppath, child);
 2770|       |
 2771|      0|	}
 2772|  13.4k|	else if (parent->type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  13.4k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2772:11): [True: 1.20k, False: 12.2k]
  ------------------
 2773|       |		/* child inherits parent's 'DF NAME' as 'aid' */
 2774|  1.20k|		if (parent->len > sizeof(child->aid.value))
  ------------------
  |  Branch (2774:7): [True: 0, False: 1.20k]
  ------------------
 2775|      0|			return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 2776|       |
 2777|  1.20k|		memcpy(child->aid.value, parent->value, parent->len);
 2778|  1.20k|		child->aid.len = parent->len;
 2779|       |
 2780|  1.20k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.20k|#define SC_SUCCESS				0
  ------------------
 2781|  1.20k|	}
 2782|       |
 2783|       |	/* a 0 length path stays a 0 length path */
 2784|  12.2k|	if (child->len == 0)
  ------------------
  |  Branch (2784:6): [True: 7, False: 12.2k]
  ------------------
 2785|      7|		return SC_SUCCESS;
  ------------------
  |  |   28|      7|#define SC_SUCCESS				0
  ------------------
 2786|       |
 2787|  12.2k|	if (sc_compare_path_prefix(sc_get_mf_path(), child))
  ------------------
  |  Branch (2787:6): [True: 40, False: 12.2k]
  ------------------
 2788|     40|		return SC_SUCCESS;
  ------------------
  |  |   28|     40|#define SC_SUCCESS				0
  ------------------
 2789|       |
 2790|  12.2k|	return sc_concatenate_path(child, parent, child);
 2791|  12.2k|}
sc_pkcs15_free_object_content:
 2795|  43.3k|{
 2796|  43.3k|	if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (2796:6): [True: 189, False: 43.1k]
  |  Branch (2796:28): [True: 189, False: 0]
  ------------------
 2797|    189|		if (obj->content_free) {
  ------------------
  |  Branch (2797:7): [True: 189, False: 0]
  ------------------
 2798|    189|			obj->content_free(obj->content.value, obj->content.len);
 2799|    189|		} else {
 2800|      0|			free(obj->content.value);
 2801|      0|		}
 2802|    189|	}
 2803|       |	obj->content.value = NULL;
 2804|  43.3k|	obj->content.len = 0;
 2805|  43.3k|}
sc_pkcs15_allocate_object_content:
 2811|    189|{
 2812|    189|	unsigned char *tmp_buf;
 2813|       |
 2814|    189|	if (!obj)
  ------------------
  |  Branch (2814:6): [True: 0, False: 189]
  ------------------
 2815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2816|       |
 2817|    189|	if (!value || !len)   {
  ------------------
  |  Branch (2817:6): [True: 0, False: 189]
  |  Branch (2817:16): [True: 0, False: 189]
  ------------------
 2818|      0|		sc_pkcs15_free_object_content(obj);
 2819|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2820|      0|	}
 2821|       |
 2822|       |	/* Need to pass by temporary variable,
 2823|       |	 * because 'value' and 'content.value' pointers can be the sames.
 2824|       |	 */
 2825|    189|	if (SC_PKCS15_TYPE_AUTH & obj->type
  ------------------
  |  |  444|    189|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2825:6): [True: 189, False: 0]
  ------------------
 2826|      0|			|| SC_PKCS15_TYPE_SKEY & obj->type
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2826:7): [True: 0, False: 0]
  ------------------
 2827|    189|			|| SC_PKCS15_TYPE_PRKEY & obj->type) {
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2827:7): [True: 0, False: 0]
  ------------------
 2828|    189|		tmp_buf = sc_mem_secure_alloc(len);
 2829|    189|		obj->content_free = sc_mem_secure_free;
 2830|    189|	} else {
 2831|      0|		tmp_buf = malloc(len);
 2832|      0|	}
 2833|    189|	if (!tmp_buf)
  ------------------
  |  Branch (2833:6): [True: 0, False: 189]
  ------------------
 2834|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2835|       |
 2836|    189|	memcpy(tmp_buf, value, len);
 2837|       |
 2838|    189|	sc_pkcs15_free_object_content(obj);
 2839|       |
 2840|    189|	obj->content.value = tmp_buf;
 2841|    189|	obj->content.len = len;
 2842|       |
 2843|    189|	return SC_SUCCESS;
  ------------------
  |  |   28|    189|#define SC_SUCCESS				0
  ------------------
 2844|    189|}
sc_pkcs15_free_key_params:
 3137|  4.86k|{
 3138|  4.86k|	if (!params)
  ------------------
  |  Branch (3138:6): [True: 0, False: 4.86k]
  ------------------
 3139|      0|		return;
 3140|  4.86k|	if (params->data && params->free_params)
  ------------------
  |  Branch (3140:6): [True: 0, False: 4.86k]
  |  Branch (3140:22): [True: 0, False: 0]
  ------------------
 3141|      0|		params->free_params(params->data);
 3142|  4.86k|	else if (params->data)
  ------------------
  |  Branch (3142:11): [True: 0, False: 4.86k]
  ------------------
 3143|      0|		free(params->data);
 3144|       |
 3145|       |	params->data = NULL;
 3146|  4.86k|}
pkcs15.c:sc_pkcs15_clear_tokeninfo:
  754|  27.1k|{
  755|  27.1k|	if (!tokeninfo)
  ------------------
  |  Branch (755:6): [True: 0, False: 27.1k]
  ------------------
  756|      0|		return;
  757|       |
  758|  27.1k|	free(tokeninfo->label);
  759|  27.1k|	tokeninfo->label = NULL;
  760|  27.1k|	free(tokeninfo->serial_number);
  761|  27.1k|	tokeninfo->serial_number = NULL;
  762|  27.1k|	free(tokeninfo->manufacturer_id);
  763|  27.1k|	tokeninfo->manufacturer_id = NULL;
  764|  27.1k|	free(tokeninfo->last_update.gtime);
  765|  27.1k|	tokeninfo->last_update.gtime = NULL;
  766|  27.1k|	free(tokeninfo->preferred_language);
  767|  27.1k|	tokeninfo->preferred_language = NULL;
  768|  27.1k|	free(tokeninfo->profile_indication.name);
  769|  27.1k|	tokeninfo->profile_indication.name = NULL;
  770|  27.1k|	if (tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (770:6): [True: 4, False: 27.1k]
  ------------------
  771|      4|		unsigned i;
  772|      4|		for (i = 0; i < tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (772:15): [True: 0, False: 4]
  ------------------
  773|      0|			free(tokeninfo->seInfo[i]);
  774|      4|		free(tokeninfo->seInfo);
  775|       |		tokeninfo->seInfo = NULL;
  776|      4|	}
  777|  27.1k|}
pkcs15.c:parse_odf:
  621|     41|{
  622|     41|	const unsigned char *p = buf;
  623|     41|	size_t left = buflen;
  624|     41|	int r, i, type;
  625|     41|	struct sc_path path;
  626|     41|	struct sc_asn1_entry asn1_obj_or_path[] = {
  627|     41|		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  174|     41|#define SC_ASN1_PATH			256
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  141|     41|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  162|     41|#define SC_ASN1_SEQUENCE                16
  ------------------
  628|     41|		{ NULL, 0, 0, 0, NULL, NULL }
  629|     41|	};
  630|     41|	struct sc_asn1_entry asn1_odf[10];
  631|       |
  632|     41|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  633|    410|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (633:14): [True: 369, False: 41]
  ------------------
  634|    369|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  635|     76|	while (left > 0) {
  ------------------
  |  Branch (635:9): [True: 60, False: 16]
  ------------------
  636|     60|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left, &p, &left);
  637|     60|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     60|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (637:7): [True: 5, False: 55]
  ------------------
  638|      5|			break;
  639|     55|		if (r < 0)
  ------------------
  |  Branch (639:7): [True: 20, False: 35]
  ------------------
  640|     20|			return r;
  641|     35|		type = r;
  642|     35|		if (p15card->file_app) {
  ------------------
  |  Branch (642:7): [True: 35, False: 0]
  ------------------
  643|     35|			r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &path);
  644|     35|			if (r < 0)
  ------------------
  |  Branch (644:8): [True: 0, False: 35]
  ------------------
  645|      0|				return r;
  646|     35|			r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  647|     35|			if (r)
  ------------------
  |  Branch (647:8): [True: 0, False: 35]
  ------------------
  648|      0|				return r;
  649|     35|		}
  650|     35|	}
  651|     21|	return 0;
  652|     41|}
pkcs15.c:sc_dup_app_info:
  908|  4.26k|{
  909|  4.26k|	struct sc_app_info *out = calloc(1, sizeof(struct sc_app_info));
  910|       |
  911|  4.26k|	if (!out)
  ------------------
  |  Branch (911:6): [True: 0, False: 4.26k]
  ------------------
  912|      0|		return NULL;
  913|       |
  914|  4.26k|	memcpy(out, info, sizeof(struct sc_app_info));
  915|       |
  916|  4.26k|	if (info->label) {
  ------------------
  |  Branch (916:6): [True: 102, False: 4.16k]
  ------------------
  917|    102|		out->label = strdup(info->label);
  918|    102|		if (!out->label) {
  ------------------
  |  Branch (918:7): [True: 0, False: 102]
  ------------------
  919|      0|			free(out);
  920|      0|			return NULL;
  921|      0|		}
  922|    102|	} else
  923|  4.16k|		out->label = NULL;
  924|       |
  925|  4.26k|	out->ddo.value = malloc(info->ddo.len);
  926|  4.26k|	if (!out->ddo.value) {
  ------------------
  |  Branch (926:6): [True: 0, False: 4.26k]
  ------------------
  927|      0|		free(out->label);
  928|      0|		free(out);
  929|      0|		return NULL;
  930|      0|	}
  931|  4.26k|	memcpy(out->ddo.value, info->ddo.value, info->ddo.len);
  932|  4.26k|	out->ddo.len = info->ddo.len;
  933|       |
  934|  4.26k|	return out;
  935|  4.26k|}
pkcs15.c:parse_ddo:
  473|    668|{
  474|    668|	struct sc_context *ctx = p15card->card->ctx;
  475|    668|	struct sc_asn1_entry asn1_ddo[7];
  476|    668|	sc_path_t odf_path, ti_path, us_path;
  477|    668|	struct sc_iid iid;
  478|    668|	struct sc_aid aid;
  479|    668|	int r;
  480|       |
  481|    668|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    668|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    668|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    668|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    668|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 668]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|       |
  483|    668|	iid.len = sizeof(iid.value);
  484|    668|	aid.len = sizeof(aid.value);
  485|       |
  486|    668|	sc_copy_asn1_entry(c_asn1_ddo, asn1_ddo);
  487|    668|	sc_format_asn1_entry(asn1_ddo + 1, &odf_path, NULL, 0);
  488|    668|	sc_format_asn1_entry(asn1_ddo + 2, &ti_path, NULL, 0);
  489|    668|	sc_format_asn1_entry(asn1_ddo + 3, &us_path, NULL, 0);
  490|    668|	sc_format_asn1_entry(asn1_ddo + 4, iid.value, &iid.len, 0);
  491|    668|	sc_format_asn1_entry(asn1_ddo + 5, aid.value, &aid.len, 0);
  492|       |
  493|    668|	r = sc_asn1_decode(ctx, asn1_ddo, buf, buflen, NULL, NULL);
  494|    668|	LOG_TEST_RET(ctx, r, "DDO parsing failed");
  ------------------
  |  |  174|    668|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    668|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    668|	int _ret = (r); \
  |  |  |  |  168|    668|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 146, False: 522]
  |  |  |  |  ------------------
  |  |  |  |  169|    146|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    146|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    146|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    146|		return _ret; \
  |  |  |  |  172|    146|	} \
  |  |  |  |  173|    668|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 522]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  495|       |
  496|    522|	if (asn1_ddo[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    522|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (496:6): [True: 146, False: 376]
  ------------------
  497|    146|		sc_file_free(p15card->file_odf);
  498|    146|		p15card->file_odf = sc_file_new();
  499|    146|		if (p15card->file_odf == NULL)
  ------------------
  |  Branch (499:7): [True: 0, False: 146]
  ------------------
  500|      0|			goto mem_err;
  501|    146|		p15card->file_odf->path = odf_path;
  502|    146|	}
  503|    522|	if (asn1_ddo[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    522|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (503:6): [True: 24, False: 498]
  ------------------
  504|     24|		sc_file_free(p15card->file_tokeninfo);
  505|     24|		p15card->file_tokeninfo = sc_file_new();
  506|     24|		if (p15card->file_tokeninfo == NULL)
  ------------------
  |  Branch (506:7): [True: 0, False: 24]
  ------------------
  507|      0|			goto mem_err;
  508|     24|		p15card->file_tokeninfo->path = ti_path;
  509|     24|	}
  510|    522|	if (asn1_ddo[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    522|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (510:6): [True: 28, False: 494]
  ------------------
  511|     28|		sc_file_free(p15card->file_unusedspace);
  512|     28|		p15card->file_unusedspace = sc_file_new();
  513|     28|		if (p15card->file_unusedspace == NULL)
  ------------------
  |  Branch (513:7): [True: 0, False: 28]
  ------------------
  514|      0|			goto mem_err;
  515|     28|		p15card->file_unusedspace->path = us_path;
  516|     28|	}
  517|    522|	if (asn1_ddo[4].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    522|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (517:6): [True: 33, False: 489]
  ------------------
  518|     33|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.IID '%s'", sc_dump_hex(iid.value, iid.len));
  ------------------
  |  |   70|     33|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  519|     33|		memcpy(&p15card->app->ddo.iid, &iid, sizeof(struct sc_iid));
  520|     33|	}
  521|    522|	if (asn1_ddo[5].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    522|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (521:6): [True: 46, False: 476]
  ------------------
  522|     46|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.AID '%s'", sc_dump_hex(aid.value, aid.len));
  ------------------
  |  |   70|     46|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|     46|		memcpy(&p15card->app->ddo.aid, &aid, sizeof(struct sc_aid));
  524|     46|	}
  525|       |
  526|    522|	fix_authentic_ddo(p15card);
  527|    522|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    522|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    522|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    522|	int _ret = r; \
  |  |  |  |  155|    522|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 522, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    522|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 522]
  |  |  |  |  ------------------
  |  |  |  |  157|    522|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    522|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    522|	return _ret; \
  |  |  |  |  163|    522|} 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|    522|{
  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|    522|	if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)   {
  ------------------
  |  Branch (463:6): [True: 11, False: 511]
  ------------------
  464|     11|		sc_file_free(p15card->file_odf);
  465|     11|		p15card->file_odf = NULL;
  466|     11|		sc_file_free(p15card->file_tokeninfo);
  467|       |		p15card->file_tokeninfo = NULL;
  468|     11|	}
  469|    522|}
pkcs15.c:__sc_pkcs15_search_objects:
 1458|  94.8k|{
 1459|  94.8k|	struct sc_pkcs15_object *obj = NULL;
 1460|  94.8k|	struct sc_pkcs15_df	*df = NULL;
 1461|  94.8k|	unsigned int	df_mask = 0;
 1462|  94.8k|	size_t		match_count = 0;
 1463|  94.8k|	int r;
 1464|       |
 1465|  94.8k|	if (type)
  ------------------
  |  Branch (1465:6): [True: 94.7k, False: 49]
  ------------------
 1466|  94.7k|		class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
  ------------------
  |  |  449|  94.7k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
 1467|       |
 1468|       |	/* Make sure the class mask we have makes sense */
 1469|  94.8k|	if (class_mask == 0
  ------------------
  |  Branch (1469:6): [True: 0, False: 94.8k]
  ------------------
 1470|  94.8k|			|| (class_mask & ~(
  ------------------
  |  Branch (1470:7): [True: 0, False: 94.8k]
  ------------------
 1471|  94.8k|					SC_PKCS15_SEARCH_CLASS_PRKEY |
  ------------------
  |  |  450|  94.8k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
 1472|  94.8k|					SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|  94.8k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1473|  94.8k|					SC_PKCS15_SEARCH_CLASS_SKEY |
  ------------------
  |  |  452|  94.8k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
 1474|  94.8k|					SC_PKCS15_SEARCH_CLASS_CERT |
  ------------------
  |  |  453|  94.8k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
 1475|  94.8k|					SC_PKCS15_SEARCH_CLASS_DATA |
  ------------------
  |  |  454|  94.8k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1476|  94.8k|					SC_PKCS15_SEARCH_CLASS_AUTH))) {
  ------------------
  |  |  455|  94.8k|#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|  94.8k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PRKEY)
  ------------------
  |  |  450|  94.8k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  |  Branch (1480:6): [True: 27.6k, False: 67.1k]
  ------------------
 1481|  27.6k|		df_mask |= (1 << SC_PKCS15_PRKDF);
  ------------------
  |  |  488|  27.6k|#define SC_PKCS15_PRKDF			0
  ------------------
 1482|  94.8k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PUBKEY)
  ------------------
  |  |  451|  94.8k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
  |  Branch (1482:6): [True: 27.6k, False: 67.1k]
  ------------------
 1483|  27.6k|		df_mask |= (1 << SC_PKCS15_PUKDF) | (1 << SC_PKCS15_PUKDF_TRUSTED);
  ------------------
  |  |  489|  27.6k|#define SC_PKCS15_PUKDF			1
  ------------------
              		df_mask |= (1 << SC_PKCS15_PUKDF) | (1 << SC_PKCS15_PUKDF_TRUSTED);
  ------------------
  |  |  490|  27.6k|#define SC_PKCS15_PUKDF_TRUSTED		2
  ------------------
 1484|  94.8k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_CERT)
  ------------------
  |  |  453|  94.8k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
  |  Branch (1484:6): [True: 6.87k, False: 87.9k]
  ------------------
 1485|  6.87k|		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  492|  6.87k|#define SC_PKCS15_CDF			4
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  493|  6.87k|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  494|  6.87k|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
 1486|  94.8k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_DATA)
  ------------------
  |  |  454|  94.8k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
  |  Branch (1486:6): [True: 5.92k, False: 88.8k]
  ------------------
 1487|  5.92k|		df_mask |= (1 << SC_PKCS15_DODF);
  ------------------
  |  |  495|  5.92k|#define SC_PKCS15_DODF			7
  ------------------
 1488|  94.8k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_AUTH)
  ------------------
  |  |  455|  94.8k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
  |  Branch (1488:6): [True: 21.2k, False: 73.5k]
  ------------------
 1489|  21.2k|		df_mask |= (1 << SC_PKCS15_AODF);
  ------------------
  |  |  496|  21.2k|#define SC_PKCS15_AODF			8
  ------------------
 1490|  94.8k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_SKEY)
  ------------------
  |  |  452|  94.8k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
  |  Branch (1490:6): [True: 5.52k, False: 89.2k]
  ------------------
 1491|  5.52k|		df_mask |= (1 << SC_PKCS15_SKDF);
  ------------------
  |  |  491|  5.52k|#define SC_PKCS15_SKDF			3
  ------------------
 1492|       |
 1493|       |	/* Make sure all the DFs we want to search have been
 1494|       |	 * enumerated. */
 1495|   234k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (1495:30): [True: 139k, False: 94.8k]
  ------------------
 1496|   139k|		if (!(df_mask & (1 << df->type)))   {
  ------------------
  |  Branch (1496:7): [True: 112k, False: 26.2k]
  ------------------
 1497|   112k|			continue;
 1498|   112k|		}
 1499|  26.2k|		if (df->enumerated)
  ------------------
  |  Branch (1499:7): [True: 25.9k, False: 248]
  ------------------
 1500|  25.9k|			continue;
 1501|       |		/* Enumerate the DF's, so p15card->obj_list is populated. */
 1502|    248|		if (p15card->ops.parse_df)
  ------------------
  |  Branch (1502:7): [True: 6, False: 242]
  ------------------
 1503|      6|			r = p15card->ops.parse_df(p15card, df);
 1504|    242|		else
 1505|    242|			r = sc_pkcs15_parse_df(p15card, df);
 1506|    248|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|    248|#define SC_SUCCESS				0
  ------------------
  |  Branch (1506:7): [True: 236, False: 12]
  ------------------
 1507|    236|			continue;
 1508|    248|	}
 1509|       |
 1510|       |	/* And now loop over all objects */
 1511|   644k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (1511:32): [True: 549k, False: 94.5k]
  ------------------
 1512|       |		/* Check object type */
 1513|   549k|		if (!(class_mask & SC_PKCS15_TYPE_TO_CLASS(obj->type)))
  ------------------
  |  |  449|   549k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
  |  Branch (1513:7): [True: 478k, False: 70.9k]
  ------------------
 1514|   478k|			continue;
 1515|  70.9k|		if (type != 0
  ------------------
  |  Branch (1515:7): [True: 70.6k, False: 298]
  ------------------
 1516|  70.6k|		 && obj->type != type
  ------------------
  |  Branch (1516:7): [True: 19.6k, False: 51.0k]
  ------------------
 1517|  19.6k|		 && (obj->type & SC_PKCS15_TYPE_CLASS_MASK) != type)
  ------------------
  |  |  416|  19.6k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1517:7): [True: 18.0k, False: 1.58k]
  ------------------
 1518|  18.0k|			continue;
 1519|       |
 1520|       |		/* Potential candidate, apply search function */
 1521|  52.9k|		if (func != NULL && func(obj, func_arg) <= 0)
  ------------------
  |  Branch (1521:7): [True: 3.06k, False: 49.8k]
  |  Branch (1521:23): [True: 2.48k, False: 581]
  ------------------
 1522|  2.48k|			continue;
 1523|       |		/* Okay, we have a match. */
 1524|  50.4k|		match_count++;
 1525|  50.4k|		if (!ret || ret_size <= 0)
  ------------------
  |  Branch (1525:7): [True: 298, False: 50.1k]
  |  Branch (1525:15): [True: 0, False: 50.1k]
  ------------------
 1526|    298|			continue;
 1527|  50.1k|		ret[match_count-1] = obj;
 1528|  50.1k|		if (ret_size <= match_count)
  ------------------
  |  Branch (1528:7): [True: 283, False: 49.8k]
  ------------------
 1529|    283|			break;
 1530|  50.1k|	}
 1531|       |
 1532|  94.8k|	return (int)match_count;
 1533|  94.8k|}
pkcs15.c:compare_obj_key:
 1678|  3.06k|{
 1679|  3.06k|	struct sc_pkcs15_search_key *sk = (struct sc_pkcs15_search_key *) arg;
 1680|       |
 1681|  3.06k|	if (sk->id && !compare_obj_id(obj, sk->id))
  ------------------
  |  Branch (1681:6): [True: 1.58k, False: 1.48k]
  |  Branch (1681:16): [True: 1.41k, False: 171]
  ------------------
 1682|  1.41k|		return 0;
 1683|  1.65k|	if (sk->app_oid && !sc_obj_app_oid(obj, sk->app_oid))
  ------------------
  |  Branch (1683:6): [True: 0, False: 1.65k]
  |  Branch (1683:21): [True: 0, False: 0]
  ------------------
 1684|      0|		return 0;
 1685|  1.65k|	if (sk->usage_mask && !compare_obj_usage(obj, sk->usage_mask, sk->usage_value))
  ------------------
  |  Branch (1685:6): [True: 0, False: 1.65k]
  |  Branch (1685:24): [True: 0, False: 0]
  ------------------
 1686|      0|		return 0;
 1687|  1.65k|	if (sk->flags_mask && !compare_obj_flags(obj, sk->flags_mask, sk->flags_value))
  ------------------
  |  Branch (1687:6): [True: 1.18k, False: 469]
  |  Branch (1687:24): [True: 1.07k, False: 112]
  ------------------
 1688|  1.07k|		return 0;
 1689|    581|	if (sk->match_reference && !compare_obj_reference(obj, sk->reference))
  ------------------
  |  Branch (1689:6): [True: 0, False: 581]
  |  Branch (1689:29): [True: 0, False: 0]
  ------------------
 1690|      0|		return 0;
 1691|    581|	if (sk->path && !compare_obj_path(obj, sk->path))
  ------------------
  |  Branch (1691:6): [True: 0, False: 581]
  |  Branch (1691:18): [True: 0, False: 0]
  ------------------
 1692|      0|		return 0;
 1693|    581|	if (
 1694|    581|		sk->app_label && sk->label &&
  ------------------
  |  Branch (1694:3): [True: 0, False: 581]
  |  Branch (1694:20): [True: 0, False: 0]
  ------------------
 1695|      0|		!compare_obj_data_name(obj, sk->app_label, sk->label)
  ------------------
  |  Branch (1695:3): [True: 0, False: 0]
  ------------------
 1696|    581|	) {
 1697|      0|		return 0;
 1698|      0|	}
 1699|       |
 1700|    581|	return 1;
 1701|    581|}
pkcs15.c:compare_obj_id:
 1546|  1.58k|{
 1547|  1.58k|	void *data = obj->data;
 1548|       |
 1549|  1.58k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  1.58k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1549:10): [True: 1.58k, False: 0]
  ------------------
 1550|  1.57k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.57k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1550:2): [True: 1.57k, False: 10]
  ------------------
 1551|  1.57k|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_cert_info *) data)->id, id);
 1552|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1552:2): [True: 0, False: 1.58k]
  ------------------
 1553|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_prkey_info *) data)->id, id);
 1554|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1554:2): [True: 0, False: 1.58k]
  ------------------
 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.58k]
  ------------------
 1557|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_skey_info *) data)->id, id);
 1558|     10|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|     10|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1558:2): [True: 10, False: 1.57k]
  ------------------
 1559|     10|		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.58k]
  ------------------
 1561|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_data_info *) data)->id, id);
 1562|  1.58k|	}
 1563|      0|	return 0;
 1564|  1.58k|}
pkcs15.c:compare_obj_flags:
 1598|  1.18k|{
 1599|  1.18k|	struct sc_pkcs15_auth_info *auth_info;
 1600|  1.18k|	unsigned int	flags;
 1601|       |
 1602|  1.18k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  1.18k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 1603|  1.18k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  1.18k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1603:2): [True: 1.18k, False: 0]
  ------------------
 1604|  1.18k|		auth_info = (struct sc_pkcs15_auth_info *) obj->data;
 1605|  1.18k|		if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  1.18k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1605:7): [True: 0, False: 1.18k]
  ------------------
 1606|      0|			return 0;
 1607|  1.18k|		flags = auth_info->attrs.pin.flags;
 1608|  1.18k|		break;
 1609|      0|	default:
  ------------------
  |  Branch (1609:2): [True: 0, False: 1.18k]
  ------------------
 1610|      0|		return 0;
 1611|  1.18k|	}
 1612|  1.18k|	return !((flags ^ value) & mask);
 1613|  1.18k|}
pkcs15.c:find_by_key:
 1707|    942|{
 1708|    942|	int r;
 1709|       |
 1710|    942|	r = sc_pkcs15_get_objects_cond(p15card, type, compare_obj_key, sk, out, 1);
 1711|    942|	if (r < 0)
  ------------------
  |  Branch (1711:6): [True: 0, False: 942]
  ------------------
 1712|      0|		return r;
 1713|    942|	if (r == 0)
  ------------------
  |  Branch (1713:6): [True: 830, False: 112]
  ------------------
 1714|    830|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    830|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1715|    112|	return 0;
 1716|    942|}
pkcs15.c:sc_pkcs15_remove_objects:
 2021|  34.0k|{
 2022|  34.0k|	struct sc_pkcs15_object *cur = NULL, *next = NULL;
 2023|       |
 2024|  34.0k|	if (!p15card || !p15card->obj_list)
  ------------------
  |  Branch (2024:6): [True: 0, False: 34.0k]
  |  Branch (2024:18): [True: 29.0k, False: 4.96k]
  ------------------
 2025|  29.0k|		return;
 2026|  41.5k|	for (cur = p15card->obj_list; cur; cur = next)   {
  ------------------
  |  Branch (2026:32): [True: 36.5k, False: 4.96k]
  ------------------
 2027|  36.5k|		next = cur->next;
 2028|  36.5k|		sc_pkcs15_free_object(cur);
 2029|  36.5k|	}
 2030|       |
 2031|       |	p15card->obj_list = NULL;
 2032|  4.96k|}
pkcs15.c:sc_pkcs15_remove_dfs:
 2102|  34.0k|{
 2103|  34.0k|	struct sc_pkcs15_df *cur = NULL, *next = NULL;
 2104|       |
 2105|  34.0k|	if (!p15card || !p15card->df_list)
  ------------------
  |  Branch (2105:6): [True: 0, False: 34.0k]
  |  Branch (2105:18): [True: 29.0k, False: 4.98k]
  ------------------
 2106|  29.0k|		return;
 2107|       |
 2108|  14.0k|	for (cur = p15card->df_list; cur; cur = next)   {
  ------------------
  |  Branch (2108:31): [True: 9.11k, False: 4.98k]
  ------------------
 2109|  9.11k|		next = cur->next;
 2110|  9.11k|		free(cur);
 2111|  9.11k|	}
 2112|       |
 2113|       |	p15card->df_list = NULL;
 2114|  4.98k|}
pkcs15.c:sc_pkcs15_free_unusedspace:
 2337|  15.2k|{
 2338|  15.2k|	struct sc_pkcs15_unusedspace *cur = NULL, *next = NULL;
 2339|       |
 2340|  15.2k|	if (!p15card || !p15card->unusedspace_list)
  ------------------
  |  Branch (2340:6): [True: 0, False: 15.2k]
  |  Branch (2340:18): [True: 15.2k, False: 0]
  ------------------
 2341|  15.2k|		return;
 2342|      0|	for (cur = p15card->unusedspace_list; cur; cur = next)   {
  ------------------
  |  Branch (2342:40): [True: 0, False: 0]
  ------------------
 2343|      0|		next = cur->next;
 2344|      0|		free(cur);
 2345|      0|	}
 2346|       |
 2347|       |	p15card->unusedspace_list = NULL;
 2348|      0|}
pkcs15.c:decompress_file:
 2477|    159|{
 2478|    159|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    159|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    159|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    159|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    159|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2479|    159|#ifdef ENABLE_ZLIB
 2480|    159|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
 2481|    159|	int method = 0;
 2482|       |
 2483|    159|	if (flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|    159|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2483:6): [True: 0, False: 159]
  ------------------
 2484|      0|		method = COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
 2485|    159|	} else if (flags & SC_FILE_FLAG_COMPRESSED_ZLIB) {
  ------------------
  |  |  231|    159|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2485:13): [True: 0, False: 159]
  ------------------
 2486|      0|		method = COMPRESSION_ZLIB;
  ------------------
  |  |   27|      0|#define COMPRESSION_ZLIB	1
  ------------------
 2487|    159|	} else {
 2488|    159|		method = COMPRESSION_AUTO;
  ------------------
  |  |   26|    159|#define COMPRESSION_AUTO	0
  ------------------
 2489|    159|	}
 2490|       |
 2491|    159|	rv = sc_decompress_alloc(out, outlen, buf, buflen, method);
 2492|    159|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
  |  Branch (2492:6): [True: 159, False: 0]
  ------------------
 2493|    159|		sc_log(card->ctx,  "Decompression failed: %d", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2494|    159|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|    159|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    159|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    159|	int _ret = r; \
  |  |  |  |  155|    159|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    159|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    159|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    159|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    159|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    159|	return _ret; \
  |  |  |  |  163|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|    159|	}
 2496|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2497|       |#else
 2498|       |	sc_log(card->ctx, "Compression not supported, no zlib");
 2499|       |	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2500|       |#endif
 2501|      0|}

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

openssl.c:sc_evp_md:
  120|  36.5k|{
  121|  36.5k|	return (EVP_MD *)EVP_get_digestbyname(algorithm);
  122|  36.5k|}
openssl.c:sc_evp_md_free:
  125|  73.0k|{
  126|  73.0k|	return;
  127|  73.0k|}
openssl.c:sc_evp_pkey_ctx_new:
  130|     17|{
  131|       |	return EVP_PKEY_CTX_new(pkey, NULL);
  132|     17|}
card-epass2003.c:sc_evp_cipher:
  135|  2.04k|{
  136|  2.04k|	return (EVP_CIPHER *)EVP_get_cipherbyname(algorithm);
  137|  2.04k|}
card-epass2003.c:sc_evp_cipher_free:
  140|  2.04k|{
  141|  2.04k|	return;
  142|  2.04k|}

sc_get_version:
   59|  15.7k|{
   60|  15.7k|    return sc_version;
   61|  15.7k|}
sc_hex_to_bin:
   64|   379k|{
   65|   379k|	const char *sc_hex_to_bin_separators = " :";
   66|   379k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (66:6): [True: 149, False: 379k]
  |  Branch (66:20): [True: 0, False: 379k]
  |  Branch (66:35): [True: 0, False: 379k]
  ------------------
   67|    149|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    149|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   68|    149|	}
   69|       |
   70|   379k|	int byte_needs_nibble = 0;
   71|   379k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   379k|#define SC_SUCCESS				0
  ------------------
   72|   379k|	size_t left = *outlen;
   73|   379k|	u8 byte = 0;
   74|  5.93M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (74:9): [True: 5.55M, False: 379k]
  |  Branch (74:24): [True: 5.55M, False: 0]
  ------------------
   75|  5.55M|		char c = *in++;
   76|  5.55M|		u8 nibble;
   77|  5.55M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (77:12): [True: 5.55M, False: 0]
  |  Branch (77:24): [True: 2.99M, False: 2.56M]
  ------------------
   78|  2.99M|			nibble = c - '0';
   79|  2.56M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (79:12): [True: 488k, False: 2.07M]
  |  Branch (79:24): [True: 488k, False: 0]
  ------------------
   80|   488k|			nibble = c - 'a' + 10;
   81|  2.07M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (81:12): [True: 727k, False: 1.34M]
  |  Branch (81:24): [True: 727k, False: 0]
  ------------------
   82|   727k|			nibble = c - 'A' + 10;
   83|  1.34M|		else {
   84|  1.34M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (84:8): [True: 1.34M, False: 0]
  ------------------
   85|  1.34M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (85:9): [True: 0, False: 1.34M]
  ------------------
   86|      0|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   87|      0|					goto err;
   88|      0|				}
   89|  1.34M|				continue;
   90|  1.34M|			}
   91|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|      0|			goto err;
   93|  1.34M|		}
   94|       |
   95|  4.20M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (95:7): [True: 2.10M, False: 2.10M]
  ------------------
   96|  2.10M|			byte |= nibble;
   97|  2.10M|			*out++ = (u8) byte;
   98|  2.10M|			left--;
   99|  2.10M|			byte_needs_nibble = 0;
  100|  2.10M|		} else {
  101|  2.10M|			byte  = nibble << 4;
  102|  2.10M|			byte_needs_nibble = 1;
  103|  2.10M|		}
  104|  4.20M|	}
  105|       |
  106|   379k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (106:6): [True: 12.0k, False: 367k]
  |  Branch (106:25): [True: 6.75k, False: 5.24k]
  |  Branch (106:51): [True: 6.75k, False: 0]
  ------------------
  107|       |		/* no output written so far, but we have a valid nibble in the upper
  108|       |		 * bits. Allow this special case. */
  109|  6.75k|		*out = (u8) byte>>4;
  110|  6.75k|		left--;
  111|  6.75k|		byte_needs_nibble = 0;
  112|  6.75k|	}
  113|       |
  114|       |	/* for ease of implementation we only accept completely hexed bytes. */
  115|   379k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (115:6): [True: 0, False: 379k]
  ------------------
  116|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  117|      0|		goto err;
  118|      0|	}
  119|       |
  120|       |	/* skip all trailing separators to see if we missed something */
  121|   379k|	while (*in != '\0') {
  ------------------
  |  Branch (121:9): [True: 0, False: 379k]
  ------------------
  122|      0|		if (NULL == strchr(sc_hex_to_bin_separators, (int) *in))
  ------------------
  |  Branch (122:7): [True: 0, False: 0]
  ------------------
  123|      0|			break;
  124|      0|		in++;
  125|      0|	}
  126|   379k|	if (*in != '\0') {
  ------------------
  |  Branch (126:6): [True: 0, False: 379k]
  ------------------
  127|      0|		r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  128|      0|		goto err;
  129|      0|	}
  130|       |
  131|   379k|err:
  132|   379k|	*outlen -= left;
  133|   379k|	return r;
  134|   379k|}
sc_bin_to_hex:
  138|   366k|{
  139|   366k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (139:6): [True: 0, False: 366k]
  |  Branch (139:20): [True: 0, False: 366k]
  ------------------
  140|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  141|      0|	}
  142|       |
  143|   366k|	if (in_sep > 0) {
  ------------------
  |  Branch (143:6): [True: 347k, False: 19.5k]
  ------------------
  144|   347k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (144:7): [True: 0, False: 347k]
  |  Branch (144:29): [True: 0, False: 347k]
  ------------------
  145|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  146|   347k|	} else {
  147|  19.5k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (147:7): [True: 11, False: 19.5k]
  ------------------
  148|     11|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     11|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  149|  19.5k|	}
  150|       |
  151|   366k|	const char hex[] = "0123456789abcdef";
  152|  3.71M|	while (in_len) {
  ------------------
  |  Branch (152:9): [True: 3.35M, False: 366k]
  ------------------
  153|  3.35M|		unsigned char value = *in++;
  154|  3.35M|		*out++ = hex[(value >> 4) & 0xF];
  155|  3.35M|		*out++ = hex[ value       & 0xF];
  156|  3.35M|		in_len--;
  157|  3.35M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (157:7): [True: 3.12M, False: 229k]
  |  Branch (157:17): [True: 3.10M, False: 17.6k]
  ------------------
  158|  3.10M|			*out++ = (char)in_sep;
  159|  3.35M|	}
  160|   366k|	*out = '\0';
  161|       |
  162|   366k|	return SC_SUCCESS;
  ------------------
  |  |   28|   366k|#define SC_SUCCESS				0
  ------------------
  163|   366k|}
ulong2bebytes:
  189|  69.9k|{
  190|  69.9k|	if (buf != NULL) {
  ------------------
  |  Branch (190:6): [True: 69.9k, False: 0]
  ------------------
  191|  69.9k|		buf[3] = (u8) (x & 0xff);
  192|  69.9k|		buf[2] = (u8) ((x >> 8) & 0xff);
  193|  69.9k|		buf[1] = (u8) ((x >> 16) & 0xff);
  194|  69.9k|		buf[0] = (u8) ((x >> 24) & 0xff);
  195|  69.9k|	}
  196|  69.9k|	return buf;
  197|  69.9k|}
ushort2bebytes:
  200|     62|{
  201|     62|	if (buf != NULL) {
  ------------------
  |  Branch (201:6): [True: 62, False: 0]
  ------------------
  202|     62|		buf[1] = (u8) (x & 0xff);
  203|     62|		buf[0] = (u8) ((x >> 8) & 0xff);
  204|     62|	}
  205|     62|	return buf;
  206|     62|}
bebytes2ulong:
  209|   112k|{
  210|   112k|	if (buf == NULL)
  ------------------
  |  Branch (210:6): [True: 0, False: 112k]
  ------------------
  211|      0|		return 0UL;
  212|   112k|	return (unsigned long)buf[0] << 24
  213|   112k|		| (unsigned long)buf[1] << 16
  214|   112k|		| (unsigned long)buf[2] << 8
  215|   112k|		| (unsigned long)buf[3];
  216|   112k|}
bebytes2ushort:
  219|   121k|{
  220|   121k|	if (buf == NULL)
  ------------------
  |  Branch (220:6): [True: 0, False: 121k]
  ------------------
  221|      0|		return 0U;
  222|   121k|	return (unsigned short)buf[0] << 8
  223|   121k|		| (unsigned short)buf[1];
  224|   121k|}
lebytes2ushort:
  227|  4.21k|{
  228|  4.21k|	if (buf == NULL)
  ------------------
  |  Branch (228:6): [True: 0, False: 4.21k]
  ------------------
  229|      0|		return 0U;
  230|  4.21k|	return (unsigned short)buf[1] << 8
  231|  4.21k|		| (unsigned short)buf[0];
  232|  4.21k|}
lebytes2ulong:
  235|    758|{
  236|    758|	if (buf == NULL)
  ------------------
  |  Branch (236:6): [True: 0, False: 758]
  ------------------
  237|      0|		return 0UL;
  238|    758|	return (unsigned long)buf[3] << 24
  239|    758|		| (unsigned long)buf[2] << 16
  240|    758|		| (unsigned long)buf[1] << 8
  241|    758|		| (unsigned long)buf[0];
  242|    758|}
set_string:
  245|  15.5k|{
  246|  15.5k|	if (strp == NULL) {
  ------------------
  |  Branch (246:6): [True: 0, False: 15.5k]
  ------------------
  247|      0|		return;
  248|      0|	}
  249|       |
  250|  15.5k|	free(*strp);
  251|  15.5k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (251:10): [True: 15.5k, False: 0]
  ------------------
  252|  15.5k|}
sc_init_oid:
  255|  69.4k|{
  256|  69.4k|	int ii;
  257|       |
  258|  69.4k|	if (!oid)
  ------------------
  |  Branch (258:6): [True: 0, False: 69.4k]
  ------------------
  259|      0|		return;
  260|  1.18M|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|  1.18M|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (260:13): [True: 1.11M, False: 69.4k]
  ------------------
  261|  1.11M|		oid->value[ii] = -1;
  262|  69.4k|}
sc_format_oid:
  265|  25.7k|{
  266|  25.7k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  25.7k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  267|  25.7k|	const char *p;
  268|  25.7k|	char       *q;
  269|       |
  270|  25.7k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (270:6): [True: 0, False: 25.7k]
  |  Branch (270:21): [True: 0, False: 25.7k]
  ------------------
  271|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  272|       |
  273|  25.7k|	sc_init_oid(oid);
  274|       |
  275|  25.7k|	p = in;
  276|   231k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   231k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (276:13): [True: 231k, False: 0]
  ------------------
  277|   231k|		oid->value[ii] = (int)strtol(p, &q, 10);
  278|   231k|		if (!*q)
  ------------------
  |  Branch (278:7): [True: 25.7k, False: 205k]
  ------------------
  279|  25.7k|			break;
  280|       |
  281|   205k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (281:9): [True: 205k, False: 0]
  |  Branch (281:24): [True: 205k, False: 0]
  ------------------
  282|      0|			goto out;
  283|       |
  284|   205k|		p = q + 1;
  285|   205k|	}
  286|       |
  287|  25.7k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (287:6): [True: 0, False: 25.7k]
  ------------------
  288|      0|		goto out;
  289|       |
  290|  25.7k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  25.7k|#define SC_SUCCESS				0
  ------------------
  291|  25.7k|out:
  292|  25.7k|	if (ret)
  ------------------
  |  Branch (292:6): [True: 0, False: 25.7k]
  ------------------
  293|      0|		sc_init_oid(oid);
  294|       |
  295|  25.7k|	return ret;
  296|  25.7k|}
sc_compare_oid:
  299|   126k|{
  300|   126k|	int i;
  301|       |
  302|   126k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (302:6): [True: 0, False: 126k]
  |  Branch (302:22): [True: 0, False: 126k]
  ------------------
  303|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  304|      0|	}
  305|       |
  306|   363k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|   363k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (306:14): [True: 363k, False: 0]
  ------------------
  307|   363k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (307:7): [True: 122k, False: 241k]
  ------------------
  308|   122k|			return 0;
  309|   241k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (309:7): [True: 4.46k, False: 236k]
  ------------------
  310|  4.46k|			break;
  311|   241k|	}
  312|       |
  313|  4.46k|	return 1;
  314|   126k|}
sc_valid_oid:
  318|  28.8k|{
  319|  28.8k|	int ii;
  320|       |
  321|  28.8k|	if (!oid)
  ------------------
  |  Branch (321:6): [True: 0, False: 28.8k]
  ------------------
  322|      0|		return 0;
  323|  28.8k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (323:6): [True: 0, False: 28.8k]
  |  Branch (323:29): [True: 0, False: 28.8k]
  ------------------
  324|      0|		return 0;
  325|  28.8k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (325:6): [True: 0, False: 28.8k]
  |  Branch (325:27): [True: 0, False: 28.8k]
  ------------------
  326|      0|		return 0;
  327|  28.8k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  28.8k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (327:12): [True: 28.8k, False: 0]
  ------------------
  328|  28.8k|		if (oid->value[ii])
  ------------------
  |  Branch (328:7): [True: 28.8k, False: 0]
  ------------------
  329|  28.8k|			break;
  330|  28.8k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  28.8k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (330:6): [True: 0, False: 28.8k]
  ------------------
  331|      0|		return 0;
  332|  28.8k|	return 1;
  333|  28.8k|}
sc_detect_card_presence:
  337|  1.16k|{
  338|  1.16k|	int r;
  339|  1.16k|	LOG_FUNC_CALLED(reader->ctx);
  ------------------
  |  |  151|  1.16k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.16k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.16k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.16k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.16k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  340|  1.16k|	if (reader->ops->detect_card_presence == NULL)
  ------------------
  |  Branch (340:6): [True: 1.16k, False: 0]
  ------------------
  341|  1.16k|		LOG_FUNC_RETURN(reader->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  1.16k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.16k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.16k|	int _ret = r; \
  |  |  |  |  155|  1.16k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.16k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.16k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.16k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.16k|	return _ret; \
  |  |  |  |  163|  1.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|       |
  343|      0|	r = reader->ops->detect_card_presence(reader);
  344|       |
  345|       |	// Check that we get sane return value from backend
  346|       |	// detect_card_presence should return 0 if no card is present.
  347|      0|	if (r && !(r & SC_READER_CARD_PRESENT))
  ------------------
  |  |  366|      0|#define SC_READER_CARD_PRESENT		0x00000001
  ------------------
  |  Branch (347:6): [True: 0, False: 0]
  |  Branch (347:11): [True: 0, False: 0]
  ------------------
  348|      0|		LOG_FUNC_RETURN(reader->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|       |
  350|      0|	LOG_FUNC_RETURN(reader->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|}
sc_path_set:
  355|  25.3k|{
  356|  25.3k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  25.3k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (356:6): [True: 0, False: 25.3k]
  |  Branch (356:22): [True: 0, False: 25.3k]
  |  Branch (356:36): [True: 0, False: 25.3k]
  |  Branch (356:51): [True: 0, False: 25.3k]
  ------------------
  357|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  358|       |
  359|  25.3k|	memset(path, 0, sizeof(*path));
  360|  25.3k|	memcpy(path->value, id, id_len);
  361|  25.3k|	path->len   = id_len;
  362|  25.3k|	path->type  = type;
  363|  25.3k|	path->index = idx;
  364|  25.3k|	path->count = count;
  365|       |
  366|  25.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  25.3k|#define SC_SUCCESS				0
  ------------------
  367|  25.3k|}
sc_format_path:
  370|   171k|{
  371|   171k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   171k|#define SC_PATH_TYPE_PATH		2
  ------------------
  372|       |
  373|   171k|	if (path) {
  ------------------
  |  Branch (373:6): [True: 171k, False: 0]
  ------------------
  374|   171k|		memset(path, 0, sizeof(*path));
  375|   171k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (375:7): [True: 60, False: 171k]
  |  Branch (375:22): [True: 0, False: 171k]
  ------------------
  376|     60|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     60|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  377|     60|			str++;
  378|     60|		}
  379|   171k|		path->len = sizeof(path->value);
  380|   171k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (380:7): [True: 171k, False: 0]
  ------------------
  381|   171k|			path->type = type;
  382|   171k|		}
  383|   171k|		path->count = -1;
  384|   171k|	}
  385|   171k|}
sc_append_path_id:
  393|  37.1k|{
  394|  37.1k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  37.1k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (394:6): [True: 0, False: 37.1k]
  ------------------
  395|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  396|  37.1k|	memcpy(dest->value + dest->len, id, idlen);
  397|  37.1k|	dest->len += idlen;
  398|  37.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  37.1k|#define SC_SUCCESS				0
  ------------------
  399|  37.1k|}
sc_append_file_id:
  402|  37.1k|{
  403|  37.1k|	u8 id[2] = { fid >> 8, fid & 0xff };
  404|       |
  405|  37.1k|	return sc_append_path_id(dest, id, 2);
  406|  37.1k|}
sc_concatenate_path:
  409|  16.1k|{
  410|  16.1k|	sc_path_t tpath;
  411|       |
  412|  16.1k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (412:6): [True: 0, False: 16.1k]
  |  Branch (412:19): [True: 0, False: 16.1k]
  |  Branch (412:33): [True: 0, False: 16.1k]
  ------------------
  413|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  414|       |
  415|  16.1k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  32.2k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  16.1k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (415:6): [True: 0, False: 16.1k]
  |  Branch (415:42): [True: 0, False: 16.1k]
  ------------------
  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|  16.1k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  16.1k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (419:6): [True: 10, False: 16.1k]
  ------------------
  420|     10|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     10|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  421|       |
  422|  16.1k|	memset(&tpath, 0, sizeof(sc_path_t));
  423|  16.1k|	memcpy(tpath.value, p1->value, p1->len);
  424|  16.1k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  425|  16.1k|	tpath.len  = p1->len + p2->len;
  426|  16.1k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  16.1k|#define SC_PATH_TYPE_PATH		2
  ------------------
  427|       |	/* use 'index' and 'count' entry of the second path object */
  428|  16.1k|	tpath.index = p2->index;
  429|  16.1k|	tpath.count = p2->count;
  430|       |	/* the result is currently always as path */
  431|  16.1k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  16.1k|#define SC_PATH_TYPE_PATH		2
  ------------------
  432|       |
  433|  16.1k|	*d = tpath;
  434|       |
  435|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  436|  16.1k|}
sc_print_path:
  439|   215k|{
  440|   215k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  441|       |
  442|   215k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   215k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 0, False: 215k]
  ------------------
  443|      0|		buffer[0] = '\0';
  444|       |
  445|   215k|	return buffer;
  446|   215k|}
sc_path_print:
  449|   314k|{
  450|   314k|	size_t i;
  451|       |
  452|   314k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (452:6): [True: 0, False: 314k]
  |  Branch (452:21): [True: 0, False: 314k]
  ------------------
  453|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  454|       |
  455|   314k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (455:6): [True: 1.60k, False: 313k]
  ------------------
  456|  1.60k|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|  1.60k|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  457|       |
  458|   313k|	buf[0] = '\0';
  459|   313k|	if (path->aid.len)   {
  ------------------
  |  Branch (459:6): [True: 132k, False: 180k]
  ------------------
  460|  1.08M|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (460:15): [True: 949k, False: 132k]
  ------------------
  461|   949k|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  462|   132k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  463|   132k|	}
  464|       |
  465|  1.25M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (465:14): [True: 939k, False: 313k]
  ------------------
  466|   939k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  467|   313k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   180k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (467:6): [True: 180k, False: 132k]
  |  Branch (467:24): [True: 34.4k, False: 145k]
  ------------------
  468|  34.4k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  469|       |
  470|   313k|	return SC_SUCCESS;
  ------------------
  |  |   28|   313k|#define SC_SUCCESS				0
  ------------------
  471|   314k|}
sc_compare_path:
  474|  14.8k|{
  475|  14.8k|	return path1->len == path2->len
  ------------------
  |  Branch (475:9): [True: 14.1k, False: 700]
  ------------------
  476|  14.1k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (476:6): [True: 40, False: 14.1k]
  ------------------
  477|  14.8k|}
sc_compare_path_prefix:
  480|  12.2k|{
  481|  12.2k|	sc_path_t tpath;
  482|       |
  483|  12.2k|	if (prefix->len > path->len)
  ------------------
  |  Branch (483:6): [True: 1, False: 12.2k]
  ------------------
  484|      1|		return 0;
  485|       |
  486|  12.2k|	tpath     = *path;
  487|  12.2k|	tpath.len = prefix->len;
  488|       |
  489|  12.2k|	return sc_compare_path(&tpath, prefix);
  490|  12.2k|}
sc_get_mf_path:
  493|  16.0k|{
  494|  16.0k|	static const sc_path_t mf_path = {
  495|  16.0k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  496|  16.0k|		0,
  497|  16.0k|		0,
  498|  16.0k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  16.0k|#define SC_PATH_TYPE_PATH		2
  ------------------
  499|  16.0k|		{{0},0}
  500|  16.0k|	};
  501|  16.0k|	return &mf_path;
  502|  16.0k|}
sc_file_add_acl_entry:
  506|   164k|{
  507|   164k|	sc_acl_entry_t *p, *_new;
  508|       |
  509|   164k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   164k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (509:6): [True: 0, False: 164k]
  |  Branch (509:22): [True: 0, False: 164k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|      0|	}
  512|       |
  513|   164k|	switch (method) {
  514|  45.1k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  45.1k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (514:2): [True: 45.1k, False: 119k]
  ------------------
  515|  45.1k|		sc_file_clear_acl_entries(file, operation);
  516|  45.1k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  517|  45.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  45.1k|#define SC_SUCCESS				0
  ------------------
  518|  28.1k|	case SC_AC_NONE:
  ------------------
  |  |  150|  28.1k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (518:2): [True: 28.1k, False: 136k]
  ------------------
  519|  28.1k|		sc_file_clear_acl_entries(file, operation);
  520|  28.1k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  521|  28.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  28.1k|#define SC_SUCCESS				0
  ------------------
  522|    915|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|    915|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (522:2): [True: 915, False: 163k]
  ------------------
  523|    915|		sc_file_clear_acl_entries(file, operation);
  524|    915|		file->acl[operation] = (sc_acl_entry_t *) 3;
  525|    915|		return SC_SUCCESS;
  ------------------
  |  |   28|    915|#define SC_SUCCESS				0
  ------------------
  526|  90.5k|	default:
  ------------------
  |  Branch (526:2): [True: 90.5k, False: 74.2k]
  ------------------
  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|  90.5k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (530:7): [True: 15, False: 90.5k]
  ------------------
  531|     15|			return SC_SUCCESS;
  ------------------
  |  |   28|     15|#define SC_SUCCESS				0
  ------------------
  532|  90.5k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (532:7): [True: 996, False: 89.5k]
  ------------------
  533|  89.5k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (533:7): [True: 13, False: 89.5k]
  ------------------
  534|  1.00k|			file->acl[operation] = NULL;
  535|   164k|	}
  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|   117k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (539:33): [True: 30.1k, False: 87.5k]
  ------------------
  540|  30.1k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (540:7): [True: 27.0k, False: 3.07k]
  |  Branch (540:32): [True: 3.01k, False: 24.0k]
  ------------------
  541|  3.01k|			return SC_SUCCESS;
  ------------------
  |  |   28|  3.01k|#define SC_SUCCESS				0
  ------------------
  542|  30.1k|	}
  543|       |
  544|  87.5k|	_new = malloc(sizeof(sc_acl_entry_t));
  545|  87.5k|	if (_new == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 87.5k]
  ------------------
  546|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  547|  87.5k|	_new->method = method;
  548|  87.5k|	_new->key_ref = (unsigned)key_ref;
  549|  87.5k|	_new->next = NULL;
  550|       |
  551|  87.5k|	p = file->acl[operation];
  552|  87.5k|	if (p == NULL) {
  ------------------
  |  Branch (552:6): [True: 81.8k, False: 5.67k]
  ------------------
  553|  81.8k|		file->acl[operation] = _new;
  554|  81.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  81.8k|#define SC_SUCCESS				0
  ------------------
  555|  81.8k|	}
  556|  24.9k|	while (p->next != NULL)
  ------------------
  |  Branch (556:9): [True: 19.2k, False: 5.67k]
  ------------------
  557|  19.2k|		p = p->next;
  558|  5.67k|	p->next = _new;
  559|       |
  560|  5.67k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.67k|#define SC_SUCCESS				0
  ------------------
  561|  87.5k|}
sc_file_get_acl_entry:
  565|   331k|{
  566|   331k|	sc_acl_entry_t *p;
  567|   331k|	static const sc_acl_entry_t e_never = {
  568|   331k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   331k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   331k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  569|   331k|	};
  570|   331k|	static const sc_acl_entry_t e_none = {
  571|   331k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   331k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   331k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  572|   331k|	};
  573|   331k|	static const sc_acl_entry_t e_unknown = {
  574|   331k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   331k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   331k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  575|   331k|	};
  576|       |
  577|   331k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   331k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (577:6): [True: 0, False: 331k]
  |  Branch (577:22): [True: 0, False: 331k]
  ------------------
  578|      0|		return NULL;
  579|      0|	}
  580|       |
  581|   331k|	p = file->acl[operation];
  582|   331k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (582:6): [True: 551, False: 331k]
  ------------------
  583|    551|		return &e_never;
  584|   331k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (584:6): [True: 536, False: 330k]
  ------------------
  585|    536|		return &e_none;
  586|   330k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (586:6): [True: 143, False: 330k]
  ------------------
  587|    143|		return &e_unknown;
  588|       |
  589|   330k|	return file->acl[operation];
  590|   330k|}
sc_file_clear_acl_entries:
  593|  3.06M|{
  594|  3.06M|	sc_acl_entry_t *e;
  595|       |
  596|  3.06M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  3.06M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (596:6): [True: 0, False: 3.06M]
  |  Branch (596:22): [True: 0, False: 3.06M]
  ------------------
  597|      0|		return;
  598|      0|	}
  599|       |
  600|  3.06M|	e = file->acl[operation];
  601|  3.06M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (601:6): [True: 45.1k, False: 3.01M]
  ------------------
  602|  3.01M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (602:6): [True: 27.1k, False: 2.98M]
  ------------------
  603|  2.98M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (603:6): [True: 902, False: 2.98M]
  ------------------
  604|  73.2k|		file->acl[operation] = NULL;
  605|  73.2k|		return;
  606|  73.2k|	}
  607|       |
  608|  3.07M|	while (e != NULL) {
  ------------------
  |  Branch (608:9): [True: 87.5k, False: 2.98M]
  ------------------
  609|  87.5k|		sc_acl_entry_t *tmp = e->next;
  610|  87.5k|		free(e);
  611|  87.5k|		e = tmp;
  612|  87.5k|	}
  613|       |	file->acl[operation] = NULL;
  614|  2.98M|}
sc_file_new:
  617|  96.3k|{
  618|  96.3k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  619|  96.3k|	if (file == NULL)
  ------------------
  |  Branch (619:6): [True: 0, False: 96.3k]
  ------------------
  620|      0|		return NULL;
  621|       |
  622|  96.3k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  96.3k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  623|  96.3k|	return file;
  624|  96.3k|}
sc_file_free:
  627|   288k|{
  628|   288k|	unsigned int i;
  629|   288k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (629:6): [True: 191k, False: 96.3k]
  |  Branch (629:22): [True: 0, False: 96.3k]
  ------------------
  630|   191k|		return;
  631|  96.3k|	file->magic = 0;
  632|  3.08M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  3.08M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (632:14): [True: 2.98M, False: 96.3k]
  ------------------
  633|  2.98M|		sc_file_clear_acl_entries(file, i);
  634|  96.3k|	if (file->sec_attr)
  ------------------
  |  Branch (634:6): [True: 1.16k, False: 95.1k]
  ------------------
  635|  1.16k|		free(file->sec_attr);
  636|  96.3k|	if (file->prop_attr)
  ------------------
  |  Branch (636:6): [True: 649, False: 95.6k]
  ------------------
  637|    649|		free(file->prop_attr);
  638|  96.3k|	if (file->type_attr)
  ------------------
  |  Branch (638:6): [True: 2.83k, False: 93.5k]
  ------------------
  639|  2.83k|		free(file->type_attr);
  640|  96.3k|	if (file->encoded_content)
  ------------------
  |  Branch (640:6): [True: 0, False: 96.3k]
  ------------------
  641|      0|		free(file->encoded_content);
  642|  96.3k|	free(file);
  643|  96.3k|}
sc_file_dup:
  646|  10.6k|{
  647|  10.6k|	sc_file_t *newf;
  648|  10.6k|	const sc_acl_entry_t *e;
  649|  10.6k|	unsigned int op;
  650|       |
  651|  10.6k|	if (!dest)
  ------------------
  |  Branch (651:6): [True: 0, False: 10.6k]
  ------------------
  652|      0|		return;
  653|  10.6k|	*dest = NULL;
  654|  10.6k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (654:6): [True: 0, False: 10.6k]
  ------------------
  655|      0|		return;
  656|  10.6k|	newf = sc_file_new();
  657|  10.6k|	if (newf == NULL)
  ------------------
  |  Branch (657:6): [True: 0, False: 10.6k]
  ------------------
  658|      0|		return;
  659|  10.6k|	*dest = newf;
  660|       |
  661|  10.6k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  662|  10.6k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  663|  10.6k|	newf->namelen = src->namelen;
  664|  10.6k|	newf->type    = src->type;
  665|  10.6k|	newf->shareable    = src->shareable;
  666|  10.6k|	newf->ef_structure = src->ef_structure;
  667|  10.6k|	newf->size    = src->size;
  668|  10.6k|	newf->id      = src->id;
  669|  10.6k|	newf->status  = src->status;
  670|   342k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   342k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (670:15): [True: 331k, False: 10.6k]
  ------------------
  671|   331k|		newf->acl[op] = NULL;
  672|   331k|		e = sc_file_get_acl_entry(src, op);
  673|   331k|		if (e != NULL) {
  ------------------
  |  Branch (673:7): [True: 2.86k, False: 328k]
  ------------------
  674|  2.86k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (674:8): [True: 0, False: 2.86k]
  ------------------
  675|      0|				goto err;
  676|  2.86k|		}
  677|   331k|	}
  678|  10.6k|	newf->record_length = src->record_length;
  679|  10.6k|	newf->record_count  = src->record_count;
  680|       |
  681|  10.6k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (681:6): [True: 0, False: 10.6k]
  ------------------
  682|      0|		goto err;
  683|  10.6k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (683:6): [True: 0, False: 10.6k]
  ------------------
  684|      0|		goto err;
  685|  10.6k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (685:6): [True: 0, False: 10.6k]
  ------------------
  686|      0|		goto err;
  687|  10.6k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (687:6): [True: 0, False: 10.6k]
  ------------------
  688|      0|		goto err;
  689|  10.6k|	return;
  690|  10.6k|err:
  691|      0|	sc_file_free(newf);
  692|       |	*dest = NULL;
  693|      0|}
sc_file_set_sec_attr:
  697|  12.0k|{
  698|  12.0k|	u8 *tmp;
  699|  12.0k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (699:6): [True: 0, False: 12.0k]
  ------------------
  700|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  701|      0|	}
  702|       |
  703|  12.0k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (703:6): [True: 10.6k, False: 1.38k]
  |  Branch (703:26): [True: 143, False: 1.24k]
  ------------------
  704|  10.8k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (704:7): [True: 66, False: 10.7k]
  ------------------
  705|     66|			free(file->sec_attr);
  706|  10.8k|		file->sec_attr = NULL;
  707|  10.8k|		file->sec_attr_len = 0;
  708|  10.8k|		return 0;
  709|  10.8k|	 }
  710|  1.24k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  711|  1.24k|	if (!tmp) {
  ------------------
  |  Branch (711:6): [True: 0, False: 1.24k]
  ------------------
  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.24k|	file->sec_attr = tmp;
  719|  1.24k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  720|  1.24k|	file->sec_attr_len = sec_attr_len;
  721|       |
  722|  1.24k|	return 0;
  723|  1.24k|}
sc_file_set_prop_attr:
  727|  11.5k|{
  728|  11.5k|	u8 *tmp;
  729|  11.5k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (729:6): [True: 0, False: 11.5k]
  ------------------
  730|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  731|      0|	}
  732|       |
  733|  11.5k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (733:6): [True: 10.6k, False: 925]
  |  Branch (733:27): [True: 149, False: 776]
  ------------------
  734|  10.7k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (734:7): [True: 68, False: 10.7k]
  ------------------
  735|     68|			free(file->prop_attr);
  736|  10.7k|		file->prop_attr = NULL;
  737|  10.7k|		file->prop_attr_len = 0;
  738|  10.7k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.7k|#define SC_SUCCESS				0
  ------------------
  739|  10.7k|	 }
  740|    776|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  741|    776|	if (!tmp) {
  ------------------
  |  Branch (741:6): [True: 0, False: 776]
  ------------------
  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|    776|	file->prop_attr = tmp;
  749|    776|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  750|    776|	file->prop_attr_len = prop_attr_len;
  751|       |
  752|    776|	return SC_SUCCESS;
  ------------------
  |  |   28|    776|#define SC_SUCCESS				0
  ------------------
  753|    776|}
sc_file_set_type_attr:
  757|  13.3k|{
  758|  13.3k|	u8 *tmp;
  759|  13.3k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (759:6): [True: 0, False: 13.3k]
  ------------------
  760|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  761|      0|	}
  762|       |
  763|  13.3k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (763:6): [True: 10.1k, False: 3.22k]
  |  Branch (763:27): [True: 0, False: 3.22k]
  ------------------
  764|  10.1k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (764:7): [True: 0, False: 10.1k]
  ------------------
  765|      0|			free(file->type_attr);
  766|  10.1k|		file->type_attr = NULL;
  767|  10.1k|		file->type_attr_len = 0;
  768|  10.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.1k|#define SC_SUCCESS				0
  ------------------
  769|  10.1k|	 }
  770|  3.22k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  771|  3.22k|	if (!tmp) {
  ------------------
  |  Branch (771:6): [True: 0, False: 3.22k]
  ------------------
  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.22k|	file->type_attr = tmp;
  779|  3.22k|	memcpy(file->type_attr, type_attr, type_attr_len);
  780|  3.22k|	file->type_attr_len = type_attr_len;
  781|       |
  782|  3.22k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.22k|#define SC_SUCCESS				0
  ------------------
  783|  3.22k|}
sc_file_set_content:
  788|  10.6k|{
  789|  10.6k|	u8 *tmp;
  790|  10.6k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (790:6): [True: 0, False: 10.6k]
  ------------------
  791|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  792|      0|	}
  793|       |
  794|  10.6k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (794:6): [True: 10.6k, False: 0]
  |  Branch (794:25): [True: 0, False: 0]
  ------------------
  795|  10.6k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (795:7): [True: 0, False: 10.6k]
  ------------------
  796|      0|			free(file->encoded_content);
  797|  10.6k|		file->encoded_content = NULL;
  798|  10.6k|		file->encoded_content_len = 0;
  799|  10.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.6k|#define SC_SUCCESS				0
  ------------------
  800|  10.6k|	}
  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|   154k|int sc_file_valid(const sc_file_t *file) {
  820|   154k|	if (file == NULL)
  ------------------
  |  Branch (820:6): [True: 0, False: 154k]
  ------------------
  821|      0|		return 0;
  822|   154k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   57|   154k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  823|   154k|}
_sc_parse_atr:
  826|  15.7k|{
  827|  15.7k|	u8 *p = reader->atr.value;
  828|  15.7k|	int atr_len = (int) reader->atr.len;
  829|  15.7k|	int n_hist, x;
  830|  15.7k|	int tx[4] = {-1, -1, -1, -1};
  831|  15.7k|	int i, FI, DI;
  832|  15.7k|	const int Fi_table[] = {
  833|  15.7k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  834|  15.7k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  835|  15.7k|	const int f_table[] = {
  836|  15.7k|		40, 50, 60, 80, 120, 160, 200, -1,
  837|  15.7k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  838|  15.7k|	const int Di_table[] = {
  839|  15.7k|		-1, 1, 2, 4, 8, 16, 32, -1,
  840|  15.7k|		12, 20, -1, -1, -1, -1, -1, -1 };
  841|       |
  842|  15.7k|	reader->atr_info.hist_bytes_len = 0;
  843|  15.7k|	reader->atr_info.hist_bytes = NULL;
  844|       |
  845|  15.7k|	if (atr_len == 0) {
  ------------------
  |  Branch (845:6): [True: 4.37k, False: 11.3k]
  ------------------
  846|  4.37k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  4.37k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  847|  4.37k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  4.37k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  848|  4.37k|	}
  849|       |
  850|  11.3k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (850:6): [True: 1.24k, False: 10.1k]
  |  Branch (850:22): [True: 1.07k, False: 163]
  ------------------
  851|  1.07k|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   71|  1.07k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  852|  1.07k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.07k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  853|  1.07k|	}
  854|  10.3k|	n_hist = p[1] & 0x0F;
  855|  10.3k|	x = p[1] >> 4;
  856|  10.3k|	p += 2;
  857|  10.3k|	atr_len -= 2;
  858|  51.5k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (858:14): [True: 41.2k, False: 10.3k]
  |  Branch (858:23): [True: 41.2k, False: 10]
  ------------------
  859|  41.2k|                if (x & (1 << i)) {
  ------------------
  |  Branch (859:21): [True: 27.0k, False: 14.1k]
  ------------------
  860|  27.0k|                        tx[i] = *p;
  861|  27.0k|                        p++;
  862|  27.0k|                        atr_len--;
  863|  27.0k|                } else
  864|  14.1k|                        tx[i] = -1;
  865|  41.2k|        }
  866|  10.3k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (866:6): [True: 8.95k, False: 1.36k]
  ------------------
  867|  8.95k|		reader->atr_info.FI = FI = tx[0] >> 4;
  868|  8.95k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  869|  8.95k|		reader->atr_info.Fi = Fi_table[FI];
  870|  8.95k|		reader->atr_info.f = f_table[FI];
  871|  8.95k|		reader->atr_info.Di = Di_table[DI];
  872|  8.95k|	} else {
  873|  1.36k|		reader->atr_info.Fi = -1;
  874|  1.36k|		reader->atr_info.f = -1;
  875|  1.36k|		reader->atr_info.Di = -1;
  876|  1.36k|	}
  877|  10.3k|	if (tx[2] >= 0)
  ------------------
  |  Branch (877:6): [True: 6.42k, False: 3.88k]
  ------------------
  878|  6.42k|		reader->atr_info.N = tx[3];
  879|  3.88k|	else
  880|  3.88k|		reader->atr_info.N = -1;
  881|  22.2k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (881:9): [True: 12.4k, False: 9.78k]
  |  Branch (881:22): [True: 12.0k, False: 489]
  |  Branch (881:38): [True: 11.9k, False: 42]
  ------------------
  882|  11.9k|		x = tx[3] >> 4;
  883|  59.7k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (883:15): [True: 47.8k, False: 11.9k]
  |  Branch (883:24): [True: 47.7k, False: 31]
  ------------------
  884|  47.7k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (884:22): [True: 18.1k, False: 29.6k]
  ------------------
  885|  18.1k|	                        tx[i] = *p;
  886|  18.1k|	                        p++;
  887|  18.1k|	                        atr_len--;
  888|  18.1k|	                } else
  889|  29.6k|	                        tx[i] = -1;
  890|  47.7k|		}
  891|  11.9k|	}
  892|  10.3k|	if (atr_len <= 0)
  ------------------
  |  Branch (892:6): [True: 56, False: 10.2k]
  ------------------
  893|     56|		return SC_SUCCESS;
  ------------------
  |  |   28|     56|#define SC_SUCCESS				0
  ------------------
  894|  10.2k|	if (n_hist > atr_len)
  ------------------
  |  Branch (894:6): [True: 1.25k, False: 9.00k]
  ------------------
  895|  1.25k|		n_hist = atr_len;
  896|  10.2k|	reader->atr_info.hist_bytes_len = n_hist;
  897|  10.2k|	reader->atr_info.hist_bytes = p;
  898|  10.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  10.2k|#define SC_SUCCESS				0
  ------------------
  899|  10.3k|}
sc_mem_secure_alloc:
  902|    677|{
  903|    677|	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|    677|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  912|    677|	if (p != NULL) {
  ------------------
  |  Branch (912:6): [True: 677, False: 0]
  ------------------
  913|    677|		mlock(p, len);
  914|    677|	}
  915|    677|#endif
  916|       |
  917|    677|	return p;
  918|    677|}
sc_mem_secure_free:
  921|  2.01k|{
  922|       |#ifdef _WIN32
  923|       |	VirtualUnlock(ptr, len);
  924|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  925|       |#else
  926|  2.01k|	munlock(ptr, len);
  927|  2.01k|	munmap(ptr, len);
  928|  2.01k|#endif
  929|  2.01k|}
sc_mem_clear:
  932|  74.3k|{
  933|  74.3k|	if (len > 0)   {
  ------------------
  |  Branch (933:6): [True: 73.0k, False: 1.33k]
  ------------------
  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|  73.0k|	}
  946|  74.3k|}
sc_compacttlv_find_tag:
 1060|    943|{
 1061|    943|	if (buf != NULL) {
  ------------------
  |  Branch (1061:6): [True: 943, False: 0]
  ------------------
 1062|    943|		size_t idx;
 1063|    943|		u8 plain_tag = tag & 0xF0;
 1064|    943|		size_t expected_len = tag & 0x0F;
 1065|       |
 1066|  14.3k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1066:17): [True: 13.6k, False: 644]
  ------------------
 1067|  13.6k|			u8 ctag = buf[idx] & 0xF0;
 1068|  13.6k|			size_t ctag_len = buf[idx] & 0x0F;
 1069|  13.6k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1069:8): [True: 731, False: 12.9k]
  |  Branch (1069:29): [True: 714, False: 17]
  ------------------
 1070|    714|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1070:7): [True: 254, False: 460]
  |  Branch (1070:28): [True: 45, False: 415]
  ------------------
 1071|    299|				if (outlen != NULL)
  ------------------
  |  Branch (1071:9): [True: 254, False: 45]
  ------------------
 1072|    254|					*outlen = ctag_len;
 1073|    299|				return buf + (idx + 1);
 1074|    299|			}
 1075|  13.3k|			idx += ctag_len;
 1076|  13.3k|		}
 1077|    943|	}
 1078|    644|	return NULL;
 1079|    943|}
sc_mutex_create:
 1084|  31.5k|{
 1085|  31.5k|	if (ctx == NULL)
  ------------------
  |  Branch (1085:6): [True: 0, False: 31.5k]
  ------------------
 1086|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1087|  31.5k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1087:6): [True: 31.5k, False: 0]
  |  Branch (1087:33): [True: 31.5k, False: 0]
  ------------------
 1088|  31.5k|		return ctx->thread_ctx->create_mutex(mutex);
 1089|      0|	else
 1090|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1091|  31.5k|}
sc_mutex_lock:
 1094|  1.28M|{
 1095|  1.28M|	if (ctx == NULL)
  ------------------
  |  Branch (1095:6): [True: 0, False: 1.28M]
  ------------------
 1096|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1097|  1.28M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1097:6): [True: 1.28M, False: 0]
  |  Branch (1097:33): [True: 1.28M, False: 0]
  ------------------
 1098|  1.28M|		return ctx->thread_ctx->lock_mutex(mutex);
 1099|      0|	else
 1100|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1101|  1.28M|}
sc_mutex_unlock:
 1104|  1.28M|{
 1105|  1.28M|	if (ctx == NULL)
  ------------------
  |  Branch (1105:6): [True: 0, False: 1.28M]
  ------------------
 1106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1107|  1.28M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1107:6): [True: 1.28M, False: 0]
  |  Branch (1107:33): [True: 1.28M, False: 0]
  ------------------
 1108|  1.28M|		return ctx->thread_ctx->unlock_mutex(mutex);
 1109|      0|	else
 1110|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1111|  1.28M|}

sc_decipher:
   37|    154|{
   38|    154|	int r;
   39|       |
   40|    154|	if (card == NULL) {
  ------------------
  |  Branch (40:6): [True: 0, False: 154]
  ------------------
   41|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   42|      0|	}
   43|    154|	if (crgram == NULL || out == NULL) {
  ------------------
  |  Branch (43:6): [True: 0, False: 154]
  |  Branch (43:24): [True: 0, False: 154]
  ------------------
   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|    154|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    154|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    154|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    154|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    154|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 154]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   47|    154|	if (card->ops->decipher == NULL)
  ------------------
  |  Branch (47:6): [True: 0, False: 154]
  ------------------
   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|    154|	r = card->ops->decipher(card, crgram, crgram_len, out, outlen);
   50|    154|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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: 68, False: 86]
  |  |  ------------------
  |  |  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|     62|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 62, False: 6]
  |  |  ------------------
  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     86|	} 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|    154|	return _ret; \
  |  |  163|    154|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   51|    154|}
sc_compute_signature:
   56|    168|{
   57|    168|	int r;
   58|       |
   59|    168|	if (card == NULL) {
  ------------------
  |  Branch (59:6): [True: 0, False: 168]
  ------------------
   60|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   61|      0|	}
   62|    168|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    168|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    168|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    168|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    168|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 168]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|    168|	if (card->ops->compute_signature == NULL)
  ------------------
  |  Branch (63:6): [True: 0, False: 168]
  ------------------
   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|    168|	r = card->ops->compute_signature(card, data, datalen, out, outlen);
   66|    168|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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: 132, False: 36]
  |  |  ------------------
  |  |  156|    132|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    121|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 121, False: 11]
  |  |  ------------------
  |  |  157|    132|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    132|	} 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|    168|	return _ret; \
  |  |  163|    168|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   67|    168|}
sc_set_security_env:
  102|    398|{
  103|    398|	int r;
  104|       |
  105|    398|	if (card == NULL) {
  ------------------
  |  Branch (105:6): [True: 0, False: 398]
  ------------------
  106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  107|      0|	}
  108|    398|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    398|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    398|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    398|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    398|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 398]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|    398|	if (card->ops->set_security_env == NULL)
  ------------------
  |  Branch (109:6): [True: 0, False: 398]
  ------------------
  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|    398|	r = card->ops->set_security_env(card, env, se_num);
  112|    398|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    398|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    398|	int _ret = r; \
  |  |  155|    398|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 398, False: 0]
  |  |  ------------------
  |  |  156|    398|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     76|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 76, False: 322]
  |  |  ------------------
  |  |  157|    398|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    398|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    398|	return _ret; \
  |  |  163|    398|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  113|    398|}
sc_restore_security_env:
  116|      3|{
  117|      3|	int r;
  118|       |
  119|      3|	if (card == NULL) {
  ------------------
  |  Branch (119:6): [True: 0, False: 3]
  ------------------
  120|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  121|      0|	}
  122|      3|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      3|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      3|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      3|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      3|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  123|      3|	if (card->ops->restore_security_env == NULL)
  ------------------
  |  Branch (123:6): [True: 0, False: 3]
  ------------------
  124|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  125|      3|	r = card->ops->restore_security_env(card, se_num);
  126|      3|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  127|      3|}
sc_verify:
  131|    904|{
  132|    904|	struct sc_pin_cmd_data data;
  133|       |
  134|    904|	memset(&data, 0, sizeof(data));
  135|    904|	data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|    904|#define SC_PIN_CMD_VERIFY	0
  ------------------
  136|    904|	data.pin_type = type;
  137|    904|	data.pin_reference = ref;
  138|    904|	data.pin1.data = pin;
  139|    904|	data.pin1.len = pinlen;
  140|       |
  141|    904|	int r = sc_pin_cmd(card, &data);
  142|    904|	if (tries_left)
  ------------------
  |  Branch (142:6): [True: 904, False: 0]
  ------------------
  143|    904|		*tries_left = data.pin1.tries_left;
  144|       |
  145|    904|	return r;
  146|    904|}
sc_pin_cmd:
  204|  3.91k|{
  205|  3.91k|	int r, debug;
  206|       |
  207|  3.91k|	if (card == NULL) {
  ------------------
  |  Branch (207:6): [True: 0, False: 3.91k]
  ------------------
  208|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  209|      0|	}
  210|  3.91k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.91k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.91k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.91k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.91k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.91k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|       |
  212|  3.91k|	debug = card->ctx->debug;
  213|  3.91k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  418|  7.83k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (213:6): [True: 1.31k, False: 2.60k]
  ------------------
  214|  1.31k|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (214:7): [True: 1.31k, False: 0]
  ------------------
  215|  1.31k|		card->ctx->debug = 0;
  216|  1.31k|	}
  217|       |
  218|  3.91k|	if (card->ops->pin_cmd) {
  ------------------
  |  Branch (218:6): [True: 3.91k, False: 0]
  ------------------
  219|  3.91k|		r = card->ops->pin_cmd(card, data);
  220|  3.91k|	} 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|  3.91k|	card->ctx->debug = debug;
  265|       |
  266|  3.91k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  3.91k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.91k|	int _ret = r; \
  |  |  155|  3.91k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.91k, False: 0]
  |  |  ------------------
  |  |  156|  3.91k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  2.19k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.19k, False: 1.72k]
  |  |  ------------------
  |  |  157|  3.91k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.91k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  3.91k|	return _ret; \
  |  |  163|  3.91k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  267|  3.91k|}
sc_build_pin:
  281|    403|{
  282|    403|	size_t i = 0, j, pin_len = pin->len;
  283|       |
  284|    403|	if (pin->max_length && pin_len > pin->max_length)
  ------------------
  |  Branch (284:6): [True: 403, False: 0]
  |  Branch (284:25): [True: 0, False: 403]
  ------------------
  285|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  286|       |
  287|    403|	if (pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|    403|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (287:6): [True: 37, False: 366]
  ------------------
  288|    105|		while (pin_len > 0 && pin->data[pin_len - 1] == 0xFF)
  ------------------
  |  Branch (288:10): [True: 98, False: 7]
  |  Branch (288:25): [True: 68, False: 30]
  ------------------
  289|     68|			pin_len--;
  290|     37|		if (pin_len > 12)
  ------------------
  |  Branch (290:7): [True: 3, False: 34]
  ------------------
  291|      3|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  292|    124|		for (i = 0; i < pin_len; i++) {
  ------------------
  |  Branch (292:15): [True: 105, False: 19]
  ------------------
  293|    105|			if (pin->data[i] < '0' || pin->data[i] > '9')
  ------------------
  |  Branch (293:8): [True: 6, False: 99]
  |  Branch (293:30): [True: 9, False: 90]
  ------------------
  294|     15|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     15|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  295|    105|		}
  296|     19|		buf[0] = 0x20 | (u8) pin_len;
  297|     19|		buf++;
  298|     19|		buflen--;
  299|     19|	}
  300|       |
  301|       |	/* PIN given by application, encode if required */
  302|    385|	if (pin->encoding == SC_PIN_ENCODING_ASCII) {
  ------------------
  |  |  425|    385|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  |  Branch (302:6): [True: 363, False: 22]
  ------------------
  303|    363|		if (pin_len > buflen)
  ------------------
  |  Branch (303:7): [True: 0, False: 363]
  ------------------
  304|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  305|    363|		memcpy(buf, pin->data, pin_len);
  306|    363|		i = pin_len;
  307|    363|	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  426|     44|#define SC_PIN_ENCODING_BCD	1
  ------------------
              	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|     19|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (307:13): [True: 3, False: 19]
  |  Branch (307:53): [True: 19, False: 0]
  ------------------
  308|     22|		if (pin_len > 2 * buflen)
  ------------------
  |  Branch (308:7): [True: 0, False: 22]
  ------------------
  309|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  310|    107|		for (i = j = 0; j < pin_len; j++) {
  ------------------
  |  Branch (310:19): [True: 87, False: 20]
  ------------------
  311|     87|			if (!isdigit(pin->data[j])) {
  ------------------
  |  Branch (311:8): [True: 2, False: 85]
  ------------------
  312|      2|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  313|      2|			}
  314|     85|			buf[i] <<= 4;
  315|     85|			buf[i] |= pin->data[j] & 0xf;
  316|     85|			if (j & 1)
  ------------------
  |  Branch (316:8): [True: 40, False: 45]
  ------------------
  317|     40|				i++;
  318|     85|		}
  319|     20|		if (j & 1) {
  ------------------
  |  Branch (319:7): [True: 4, False: 16]
  ------------------
  320|      4|			buf[i] <<= 4;
  321|      4|			buf[i] |= pin->pad_char & 0xf;
  322|      4|			i++;
  323|      4|		}
  324|     20|	}
  325|       |
  326|       |	/* Pad to maximum PIN length if requested */
  327|    383|	if (pad || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|     63|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (327:6): [True: 320, False: 63]
  |  Branch (327:13): [True: 0, False: 63]
  ------------------
  328|    320|		size_t pad_length = pin->pad_length;
  329|    320|		u8     pad_char   = pin->encoding == SC_PIN_ENCODING_GLP ? 0xFF : pin->pad_char;
  ------------------
  |  |  427|    320|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (329:23): [True: 19, False: 301]
  ------------------
  330|       |
  331|    320|		if (pin->encoding == SC_PIN_ENCODING_BCD)
  ------------------
  |  |  426|    320|#define SC_PIN_ENCODING_BCD	1
  ------------------
  |  Branch (331:7): [True: 1, False: 319]
  ------------------
  332|      1|			pad_length >>= 1;
  333|    320|		if (pin->encoding == SC_PIN_ENCODING_GLP)
  ------------------
  |  |  427|    320|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (333:7): [True: 19, False: 301]
  ------------------
  334|     19|			pad_length = 8;
  335|       |
  336|    320|		if (pad_length > buflen)
  ------------------
  |  Branch (336:7): [True: 0, False: 320]
  ------------------
  337|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  338|       |
  339|    320|		if (pad_length && i < pad_length) {
  ------------------
  |  Branch (339:7): [True: 319, False: 1]
  |  Branch (339:21): [True: 304, False: 15]
  ------------------
  340|    304|			memset(buf + i, pad_char, pad_length - i);
  341|    304|			i = pad_length;
  342|    304|		}
  343|    320|	}
  344|       |
  345|    383|	return (int)i;
  346|    383|}

sc_simpletlv_put_tag:
   43|  7.48k|{
   44|  7.48k|	u8 *p = out;
   45|       |
   46|  7.48k|	if (outlen < 2 || (outlen < 4 && datalen >= 0xff))
  ------------------
  |  Branch (46:6): [True: 0, False: 7.48k]
  |  Branch (46:21): [True: 53, False: 7.43k]
  |  Branch (46:35): [True: 0, False: 53]
  ------------------
   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|  7.48k|	if (tag == 0x00 || tag == 0xff)
  ------------------
  |  Branch (50:6): [True: 2.27k, False: 5.20k]
  |  Branch (50:21): [True: 295, False: 4.91k]
  ------------------
   51|  2.57k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.57k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   52|  4.91k|	if (datalen > 0xffff) {
  ------------------
  |  Branch (52:6): [True: 0, False: 4.91k]
  ------------------
   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|  4.91k|	*p++ = tag; /* tag is single byte */
   58|  4.91k|	if (datalen < 0xff) {
  ------------------
  |  Branch (58:6): [True: 4.75k, False: 163]
  ------------------
   59|       |		/* short value up to 255 */
   60|  4.75k|		*p++ = (u8)datalen; /* is in the second byte */
   61|  4.75k|	} else {
   62|       |		/* longer values up to 65535 */
   63|    163|		*p++ = (u8)0xff; /* first byte is 0xff */
   64|    163|		*p++ = (u8)datalen & 0xff;
   65|    163|		*p++ = (u8)(datalen >> 8) & 0xff; /* LE */
   66|    163|	}
   67|  4.91k|	if (ptr != NULL)
  ------------------
  |  Branch (67:6): [True: 4.91k, False: 0]
  ------------------
   68|  4.91k|		*ptr = p;
   69|  4.91k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.91k|#define SC_SUCCESS				0
  ------------------
   70|  4.91k|}
sc_simpletlv_read_tag:
   77|  62.3k|{
   78|  62.3k|	u8 tag;
   79|  62.3k|	size_t left = buflen, len;
   80|  62.3k|	const u8 *p = *buf;
   81|       |
   82|  62.3k|	*buf = NULL;
   83|       |
   84|  62.3k|	if (left < 2) {
  ------------------
  |  Branch (84:6): [True: 629, False: 61.7k]
  ------------------
   85|    629|		return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    629|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   86|    629|	}
   87|  61.7k|	tag = *p;
   88|  61.7k|	p++;
   89|  61.7k|	len = *p;
   90|  61.7k|	p++;
   91|  61.7k|	left -= 2;
   92|       |
   93|  61.7k|	if (len == 0xff) {
  ------------------
  |  Branch (93:6): [True: 1.93k, False: 59.7k]
  ------------------
   94|       |		/* don't crash on bad data */
   95|  1.93k|		if (left < 2) {
  ------------------
  |  Branch (95:7): [True: 439, False: 1.49k]
  ------------------
   96|    439|			return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    439|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   97|    439|		}
   98|       |		/* skip two bytes (the size) */
   99|  1.49k|		len = lebytes2ushort(p);
  100|  1.49k|		p += 2;
  101|  1.49k|		left -= 2;
  102|  1.49k|	}
  103|       |
  104|  61.2k|	*tag_out = tag;
  105|  61.2k|	*taglen = len;
  106|  61.2k|	*buf = p;
  107|       |
  108|  61.2k|	if (len > left)
  ------------------
  |  Branch (108:6): [True: 4.48k, False: 56.8k]
  ------------------
  109|  4.48k|		return SC_ERROR_TLV_END_OF_CONTENTS;
  ------------------
  |  |   99|  4.48k|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  110|       |
  111|  56.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  56.8k|#define SC_SUCCESS				0
  ------------------
  112|  61.2k|}

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

sc_pkcs11_print_attrs:
  180|  2.37k|{
  181|  2.37k|	if (ulCount == 0) {
  ------------------
  |  Branch (181:6): [True: 0, False: 2.37k]
  ------------------
  182|      0|		sc_do_log(context, level,
  183|      0|			file, line, function,
  184|      0|			"%s: empty template\n",
  185|      0|			info);
  186|      0|		return;
  187|      0|	}
  188|       |
  189|  8.17k|	while (ulCount--)
  ------------------
  |  Branch (189:9): [True: 5.79k, False: 2.37k]
  ------------------
  190|  5.79k|		sc_pkcs11_print_attr(level, file, line, function,
  191|  5.79k|				info, pTemplate++);
  192|       |
  193|  2.37k|}
debug.c:sc_pkcs11_print_attr:
  198|  5.79k|{
  199|  5.79k|	struct fmap	*fm;
  200|  5.79k|	const char *	value;
  201|       |
  202|  5.79k|	fm = sc_pkcs11_map_ulong(level, p11_attr_names, attr->type);
  203|       |
  204|  5.79k|	if (attr->pValue == NULL) {
  ------------------
  |  Branch (204:6): [True: 0, False: 5.79k]
  ------------------
  205|      0|		value = "<size inquiry>";
  206|  5.79k|	} else {
  207|  5.79k|		value = sc_pkcs11_print_value(level, fm,
  208|  5.79k|			attr->pValue, attr->ulValueLen);
  209|  5.79k|	}
  210|       |
  211|  5.79k|	if (fm == NULL) {
  ------------------
  |  Branch (211:6): [True: 15, False: 5.77k]
  ------------------
  212|     15|		sc_do_log(context, level,
  213|     15|			  file, line, function,
  214|     15|			  "%s: Attribute 0x%lx = %s\n",
  215|     15|			  info, attr->type, value);
  216|  5.77k|	} else {
  217|  5.77k|		sc_do_log(context, level,
  218|  5.77k|			  file, line, function,
  219|  5.77k|			  "%s: %s = %s\n",
  220|  5.77k|			  info, fm->name, value);
  221|  5.77k|	}
  222|  5.79k|}
debug.c:sc_pkcs11_map_ulong:
  292|  8.34k|{
  293|  69.6k|	for (; fm && fm->name; fm++) {
  ------------------
  |  Branch (293:9): [True: 69.6k, False: 0]
  |  Branch (293:15): [True: 69.5k, False: 135]
  ------------------
  294|  69.5k|		if (fm->value == value)
  ------------------
  |  Branch (294:7): [True: 8.21k, False: 61.3k]
  ------------------
  295|  8.21k|			return fm;
  296|  69.5k|	}
  297|    135|	return NULL;
  298|  8.34k|}
debug.c:sc_pkcs11_print_ulong:
  249|  2.70k|{
  250|  2.70k|	static char	buffer[64];
  251|  2.70k|	CK_ULONG	value;
  252|       |
  253|  2.70k|	if (count == sizeof(CK_ULONG)) {
  ------------------
  |  Branch (253:6): [True: 2.55k, False: 148]
  ------------------
  254|  2.55k|		memcpy(&value, ptr, count);
  255|  2.55k|		if ((fm = sc_pkcs11_map_ulong(level, fm->map, value)) != NULL)
  ------------------
  |  Branch (255:7): [True: 2.43k, False: 120]
  ------------------
  256|  2.43k|			return fm->name;
  257|    120|		sprintf(buffer, "0x%lx", (unsigned long) value);
  258|    120|		return buffer;
  259|  2.55k|	}
  260|       |
  261|    148|	return sc_pkcs11_print_value(level, NULL, ptr, count);
  262|  2.70k|}
debug.c:sc_pkcs11_print_bool:
  266|  2.42k|{
  267|  2.42k|	CK_BBOOL	value;
  268|       |
  269|  2.42k|	if (count == sizeof(CK_BBOOL)) {
  ------------------
  |  Branch (269:6): [True: 2.42k, False: 0]
  ------------------
  270|  2.42k|		memcpy(&value, ptr, count);
  271|  2.42k|		if (value)
  ------------------
  |  Branch (271:7): [True: 1.68k, False: 740]
  ------------------
  272|  1.68k|			return "TRUE";
  273|    740|		return "FALSE";
  274|  2.42k|	}
  275|       |
  276|      0|	return sc_pkcs11_print_value(level, NULL, ptr, count);
  277|  2.42k|}
debug.c:sc_pkcs11_print_string:
  281|     32|{
  282|     32|	static char	buffer[128];
  283|       |
  284|     32|	if (count >= sizeof(buffer))
  ------------------
  |  Branch (284:6): [True: 0, False: 32]
  ------------------
  285|      0|		count = sizeof(buffer)-1;
  286|     32|	memcpy(buffer, ptr, count);
  287|     32|	buffer[count] = 0;
  288|     32|	return buffer;
  289|     32|}
debug.c:sc_pkcs11_print_value:
  226|  5.94k|{
  227|  5.94k|	static char buffer[4 * DUMP_TEMPLATE_MAX + 1] = "";
  228|       |
  229|  5.94k|	if (count == (CK_ULONG)-1)
  ------------------
  |  Branch (229:6): [True: 0, False: 5.94k]
  ------------------
  230|      0|		return "<error>";
  231|       |
  232|  5.94k|	if (!fm || !fm->print) {
  ------------------
  |  Branch (232:6): [True: 163, False: 5.77k]
  |  Branch (232:13): [True: 615, False: 5.16k]
  ------------------
  233|    778|		unsigned char *value = (unsigned char*) ptr;
  234|    778|		char	*p;
  235|       |
  236|    778|		if (count > DUMP_TEMPLATE_MAX)
  ------------------
  |  |   28|    778|#define DUMP_TEMPLATE_MAX	32
  ------------------
  |  Branch (236:7): [True: 55, False: 723]
  ------------------
  237|     55|			count = DUMP_TEMPLATE_MAX;
  ------------------
  |  |   28|     55|#define DUMP_TEMPLATE_MAX	32
  ------------------
  238|       |
  239|  4.19k|		for (p = buffer; count--; value++)
  ------------------
  |  Branch (239:20): [True: 3.41k, False: 778]
  ------------------
  240|  3.41k|			p += sprintf(p, "%02X", *value);
  241|    778|		return buffer;
  242|    778|	}
  243|       |
  244|  5.16k|	return fm->print(level, fm, ptr, count);
  245|  5.94k|}

C_GetTokenInfo:
  542|  1.55k|{
  543|  1.55k|	struct sc_pkcs11_slot *slot;
  544|  1.55k|	struct pkcs15_fw_data *fw_data = NULL;
  545|  1.55k|	struct sc_pkcs15_object *auth;
  546|  1.55k|	const char *name;
  547|  1.55k|	CK_RV rv;
  548|       |
  549|  1.55k|	if (pInfo == NULL_PTR)
  ------------------
  |  |   27|  1.55k|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (549:6): [True: 0, False: 1.55k]
  ------------------
  550|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  551|       |
  552|  1.55k|	rv = sc_pkcs11_lock();
  553|  1.55k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.55k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (553:6): [True: 0, False: 1.55k]
  ------------------
  554|      0|		return rv;
  555|  1.55k|	sc_log(context, "C_GetTokenInfo(%lx)", slotID);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  556|       |
  557|  1.55k|	rv = slot_get_token(slotID, &slot);
  558|  1.55k|	if (rv != CKR_OK)   {
  ------------------
  |  | 1086|  1.55k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (558:6): [True: 0, False: 1.55k]
  ------------------
  559|      0|		sc_log(context, "C_GetTokenInfo() get token: rv 0x%lX", 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__
  |  |  ------------------
  ------------------
  560|      0|		goto out;
  561|      0|	}
  562|       |
  563|  1.55k|	if (slot->p11card == NULL) {
  ------------------
  |  Branch (563:6): [True: 0, False: 1.55k]
  ------------------
  564|      0|		if (slot->slot_info.flags & CKF_TOKEN_PRESENT) {
  ------------------
  |  |  407|      0|#define CKF_TOKEN_PRESENT 0x00000001UL
  ------------------
  |  Branch (564:7): [True: 0, False: 0]
  ------------------
  565|      0|			rv = CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  566|      0|		} else {
  567|      0|			rv = CKR_TOKEN_NOT_PRESENT;
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
  568|      0|		}
  569|      0|		goto out;
  570|      0|	}
  571|       |
  572|  1.55k|	fw_data = (struct pkcs15_fw_data *) slot->p11card->fws_data[slot->fw_data_idx];
  573|  1.55k|	if (!fw_data) {
  ------------------
  |  Branch (573:6): [True: 0, False: 1.55k]
  ------------------
  574|      0|		rv = sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetTokenInfo");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  575|      0|		goto out;
  576|      0|	}
  577|       |	/* User PIN flags are cleared before re-calculation */
  578|  1.55k|	slot->token_info.flags &= ~(CKF_USER_PIN_COUNT_LOW | CKF_USER_PIN_FINAL_TRY | CKF_USER_PIN_LOCKED | CKF_USER_PIN_TO_BE_CHANGED);
  ------------------
  |  |  422|  1.55k|#define CKF_USER_PIN_COUNT_LOW 0x00010000UL
  ------------------
              	slot->token_info.flags &= ~(CKF_USER_PIN_COUNT_LOW | CKF_USER_PIN_FINAL_TRY | CKF_USER_PIN_LOCKED | CKF_USER_PIN_TO_BE_CHANGED);
  ------------------
  |  |  423|  1.55k|#define CKF_USER_PIN_FINAL_TRY 0x00020000UL
  ------------------
              	slot->token_info.flags &= ~(CKF_USER_PIN_COUNT_LOW | CKF_USER_PIN_FINAL_TRY | CKF_USER_PIN_LOCKED | CKF_USER_PIN_TO_BE_CHANGED);
  ------------------
  |  |  424|  1.55k|#define CKF_USER_PIN_LOCKED 0x00040000UL
  ------------------
              	slot->token_info.flags &= ~(CKF_USER_PIN_COUNT_LOW | CKF_USER_PIN_FINAL_TRY | CKF_USER_PIN_LOCKED | CKF_USER_PIN_TO_BE_CHANGED);
  ------------------
  |  |  425|  1.55k|#define CKF_USER_PIN_TO_BE_CHANGED 0x00080000UL
  ------------------
  579|  1.55k|	auth = slot_data_auth(slot->fw_data);
  ------------------
  |  |   51|  1.55k|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|  1.16k|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (50:23): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|  1.16k|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  ------------------
  |  |  |  Branch (51:29): [True: 1.16k, False: 391]
  |  |  ------------------
  ------------------
  580|  1.55k|	sc_log(context,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  581|  1.55k|		"C_GetTokenInfo() auth. object %p, token-info flags 0x%lX", auth,
  582|  1.55k|		slot->token_info.flags);
  583|  1.55k|	if (auth) {
  ------------------
  |  Branch (583:6): [True: 930, False: 624]
  ------------------
  584|    930|		struct sc_pkcs15_card *p15card = NULL;
  585|    930|		struct sc_pkcs15_auth_info *pin_info = NULL;
  586|       |
  587|    930|		pin_info = (struct sc_pkcs15_auth_info*) auth->data;
  588|       |
  589|    930|		p15card = fw_data->p15_card;
  590|    930|		if (!p15card) {
  ------------------
  |  Branch (590:7): [True: 0, False: 930]
  ------------------
  591|      0|			rv = sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetTokenInfo");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  592|      0|			goto out;
  593|      0|		}
  594|       |
  595|    930|		sc_pkcs15_get_pin_info(p15card, auth);
  596|       |
  597|    930|		if (pin_info->tries_left >= 0) {
  ------------------
  |  Branch (597:7): [True: 244, False: 686]
  ------------------
  598|    244|			if (pin_info->tries_left == 1 || pin_info->max_tries == 1)
  ------------------
  |  Branch (598:8): [True: 6, False: 238]
  |  Branch (598:37): [True: 0, False: 238]
  ------------------
  599|      6|				slot->token_info.flags |= CKF_USER_PIN_FINAL_TRY;
  ------------------
  |  |  423|      6|#define CKF_USER_PIN_FINAL_TRY 0x00020000UL
  ------------------
  600|    238|			else if (pin_info->tries_left == 0)
  ------------------
  |  Branch (600:13): [True: 22, False: 216]
  ------------------
  601|     22|				slot->token_info.flags |= CKF_USER_PIN_LOCKED;
  ------------------
  |  |  424|     22|#define CKF_USER_PIN_LOCKED 0x00040000UL
  ------------------
  602|    216|			else if (pin_info->max_tries > 1 && pin_info->tries_left < pin_info->max_tries)
  ------------------
  |  Branch (602:13): [True: 29, False: 187]
  |  Branch (602:40): [True: 6, False: 23]
  ------------------
  603|      6|				slot->token_info.flags |= CKF_USER_PIN_COUNT_LOW;
  ------------------
  |  |  422|      6|#define CKF_USER_PIN_COUNT_LOW 0x00010000UL
  ------------------
  604|    244|		}
  605|    930|		if (pin_info->logged_in & SC_PIN_STATE_NEEDS_CHANGE) {
  ------------------
  |  |  433|    930|#define SC_PIN_STATE_NEEDS_CHANGE 4
  ------------------
  |  Branch (605:7): [True: 0, False: 930]
  ------------------
  606|      0|			slot->token_info.flags |= CKF_USER_PIN_TO_BE_CHANGED;
  ------------------
  |  |  425|      0|#define CKF_USER_PIN_TO_BE_CHANGED 0x00080000UL
  ------------------
  607|      0|		}
  608|    930|	}
  609|  1.55k|	memcpy(pInfo, &slot->token_info, sizeof(CK_TOKEN_INFO));
  610|       |
  611|  1.55k|out:
  612|  1.55k|	name = lookup_enum(RV_T, rv);
  613|  1.55k|	if (name)
  ------------------
  |  Branch (613:6): [True: 1.55k, False: 0]
  ------------------
  614|  1.55k|		sc_log(context, "C_GetTokenInfo(%lx) returns %s", slotID, name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  615|      0|	else
  616|      0|		sc_log(context, "C_GetTokenInfo(%lx) returns 0x%08lX", slotID, 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__
  |  |  ------------------
  ------------------
  617|  1.55k|	sc_pkcs11_unlock();
  618|       |
  619|  1.55k|	return rv;
  620|  1.55k|}
_is_slot_auth_object:
 1357|  11.0k|{
 1358|       |
 1359|       |	/* Ignore all but PIN authentication objects */
 1360|  11.0k|	if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  11.0k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1360:6): [True: 0, False: 11.0k]
  ------------------
 1361|      0|		return 0;
 1362|       |
 1363|       |	/* Ignore any non-authentication PINs */
 1364|  11.0k|	if ((pin_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) != 0)
  ------------------
  |  |   61|  11.0k|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (1364:6): [True: 2.15k, False: 8.90k]
  ------------------
 1365|  2.15k|		return 0;
 1366|       |
 1367|       |	/* Ignore unblocking pins */
 1368|  8.90k|	if (!sc_pkcs11_conf.create_puk_slot)
  ------------------
  |  Branch (1368:6): [True: 8.90k, False: 0]
  ------------------
 1369|  8.90k|		if (pin_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN)
  ------------------
  |  |   60|  8.90k|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  |  Branch (1369:7): [True: 1.06k, False: 7.84k]
  ------------------
 1370|  1.06k|			return 0;
 1371|       |
 1372|  7.84k|	return 1;
 1373|  8.90k|}
_get_auth_object_by_name:
 1437|  5.52k|{
 1438|  5.52k|	struct sc_pkcs15_object *out = NULL;
 1439|  5.52k|	int rv = SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  5.52k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1440|       |
 1441|       |	/* please keep me in sync with md_get_pin_by_role() in minidriver */
 1442|       |
 1443|       |	/* If 'label' is set, then search for PIN with that label */
 1444|  5.52k|	if (label) {
  ------------------
  |  Branch (1444:6): [True: 0, False: 5.52k]
  ------------------
 1445|      0|		struct sc_pkcs15_id id;
 1446|      0|		strncpy((char*)id.value, label, sizeof(id.value) - 1);
 1447|      0|		id.len = strlen(label);
 1448|      0|		if (id.len > sizeof(id.value))
  ------------------
  |  Branch (1448:7): [True: 0, False: 0]
  ------------------
 1449|      0|			id.len = sizeof(id.value);
 1450|      0|		rv = sc_pkcs15_find_pin_by_auth_id(p15card, &id, &out);
 1451|      0|	}
 1452|  5.52k|	else if (!strcmp(name, "UserPIN"))   {
  ------------------
  |  Branch (1452:11): [True: 5.52k, False: 0]
  ------------------
 1453|       |		/* Try to get 'global' PIN; if no, get the 'local' one */
 1454|  5.52k|		rv = sc_pkcs15_find_pin_by_flags(p15card, SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL,
  ------------------
  |  |   75|  5.52k|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|  5.52k|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
 1455|  5.52k|				SC_PKCS15_PIN_TYPE_FLAGS_MASK, NULL, &out);
  ------------------
  |  |   68|  5.52k|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|  5.52k|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|  5.52k|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|  5.52k|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|  5.52k|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|  5.52k|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1456|  5.52k|		if (rv)
  ------------------
  |  Branch (1456:7): [True: 2.83k, False: 2.69k]
  ------------------
 1457|  2.83k|			rv = sc_pkcs15_find_pin_by_flags(p15card, SC_PKCS15_PIN_TYPE_FLAGS_PIN_LOCAL,
  ------------------
  |  |   78|  2.83k|	( SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL)
  |  |  ------------------
  |  |  |  |   58|  2.83k|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL)
  |  |  ------------------
  |  |  |  |   55|  2.83k|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  ------------------
 1458|  2.83k|					SC_PKCS15_PIN_TYPE_FLAGS_MASK, NULL, &out);
  ------------------
  |  |   68|  2.83k|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|  2.83k|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|  2.83k|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|  2.83k|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|  2.83k|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|  2.83k|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1459|  5.52k|	}
 1460|      0|	else if (!strcmp(name, "SignPIN"))   {
  ------------------
  |  Branch (1460:11): [True: 0, False: 0]
  ------------------
 1461|      0|		int idx = 0;
 1462|       |
 1463|       |		/* Get the 'global' user PIN */
 1464|      0|		rv = sc_pkcs15_find_pin_by_flags(p15card, SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL,
  ------------------
  |  |   75|      0|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
 1465|      0|				SC_PKCS15_PIN_TYPE_FLAGS_MASK, NULL, &out);
  ------------------
  |  |   68|      0|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|      0|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1466|      0|		if (!rv)   {
  ------------------
  |  Branch (1466:7): [True: 0, False: 0]
  ------------------
 1467|       |			/* Global (user) PIN exists, get the local one -- sign PIN */
 1468|      0|			rv = sc_pkcs15_find_pin_by_flags(p15card, 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
  |  |  ------------------
  ------------------
 1469|      0|					SC_PKCS15_PIN_TYPE_FLAGS_MASK, NULL, &out);
  ------------------
  |  |   68|      0|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|      0|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1470|      0|		}
 1471|      0|		else   {
 1472|       |			/* No global PIN, try to get first local one -- user PIN */
 1473|      0|			rv = sc_pkcs15_find_pin_by_flags(p15card, 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
  |  |  ------------------
  ------------------
 1474|      0|					SC_PKCS15_PIN_TYPE_FLAGS_MASK, &idx, &out);
  ------------------
  |  |   68|      0|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|      0|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1475|      0|			if (!rv)   {
  ------------------
  |  Branch (1475:8): [True: 0, False: 0]
  ------------------
 1476|       |				/* User PIN is local, try to get the second local -- sign PIN */
 1477|      0|				idx++;
 1478|      0|				rv = sc_pkcs15_find_pin_by_flags(p15card, 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
  |  |  ------------------
  ------------------
 1479|      0|						SC_PKCS15_PIN_TYPE_FLAGS_MASK, &idx, &out);
  ------------------
  |  |   68|      0|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|      0|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1480|      0|			}
 1481|      0|		}
 1482|      0|	}
 1483|      0|	else if (!strcmp(name, "UserPUK"))   {
  ------------------
  |  Branch (1483:11): [True: 0, False: 0]
  ------------------
 1484|       |		/* Get the 'global' PUK; if no, get the 'local' one */
 1485|      0|		rv = sc_pkcs15_find_pin_by_flags(p15card, 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
  |  |  ------------------
  ------------------
 1486|      0|				SC_PKCS15_PIN_TYPE_FLAGS_MASK, NULL, &out);
  ------------------
  |  |   68|      0|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|      0|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1487|      0|		if (rv)
  ------------------
  |  Branch (1487:7): [True: 0, False: 0]
  ------------------
 1488|      0|			rv = sc_pkcs15_find_pin_by_flags(p15card, SC_PKCS15_PIN_TYPE_FLAGS_PUK_LOCAL,
  ------------------
  |  |   85|      0|	( SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN				\
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |   86|      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
  |  |  ------------------
  ------------------
 1489|      0|					SC_PKCS15_PIN_TYPE_FLAGS_MASK, NULL, &out);
  ------------------
  |  |   68|      0|	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED 	\
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   69|      0|	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |               	| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  ------------------
 1490|      0|	}
 1491|      0|	else if (!strcmp(name, "SignPUK"))   {
  ------------------
  |  Branch (1491:11): [True: 0, False: 0]
  ------------------
 1492|       |		/* TODO: Sign PUK to be defined */
 1493|      0|	}
 1494|      0|	else if (!strcmp(name, "SoPIN"))   {
  ------------------
  |  Branch (1494:11): [True: 0, False: 0]
  ------------------
 1495|      0|		rv = sc_pkcs15_find_pin_by_flags(p15card, SC_PKCS15_PIN_TYPE_FLAGS_SOPIN,
  ------------------
  |  |   72|      0|	( SC_PKCS15_PIN_FLAG_SO_PIN | SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_SO_PIN | SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
 1496|      0|				SC_PKCS15_PIN_TYPE_FLAGS_SOPIN, NULL, &out);
  ------------------
  |  |   72|      0|	( SC_PKCS15_PIN_FLAG_SO_PIN | SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_SO_PIN | SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
 1497|      0|	}
 1498|       |
 1499|  5.52k|	return rv ? NULL : out;
  ------------------
  |  Branch (1499:9): [True: 1.69k, False: 3.83k]
  ------------------
 1500|  5.52k|}
framework-pkcs15.c:pkcs15_bind:
  325|  15.1k|{
  326|  15.1k|	struct pkcs15_fw_data *fw_data = NULL;
  327|  15.1k|	struct sc_aid *aid = app_info ? &app_info->aid : NULL;
  ------------------
  |  Branch (327:23): [True: 3.81k, False: 11.3k]
  ------------------
  328|  15.1k|	int rc, idx;
  329|  15.1k|	CK_RV ck_rv;
  330|       |
  331|  15.1k|	sc_log(context, "Bind PKCS#15 '%s' application", app_info ? app_info->label : "<anonymous>");
  ------------------
  |  |   71|  30.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.81k, False: 11.3k]
  |  |  ------------------
  ------------------
  332|  15.1k|	if (!p11card)
  ------------------
  |  Branch (332:6): [True: 0, False: 15.1k]
  ------------------
  333|      0|		return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  334|  19.5k|	for (idx=0; idx<SC_PKCS11_FRAMEWORK_DATA_MAX_NUM; idx++)
  ------------------
  |  |  194|  19.5k|#define SC_PKCS11_FRAMEWORK_DATA_MAX_NUM	4
  ------------------
  |  Branch (334:14): [True: 19.3k, False: 140]
  ------------------
  335|  19.3k|		if (!p11card->fws_data[idx])
  ------------------
  |  Branch (335:7): [True: 14.9k, False: 4.38k]
  ------------------
  336|  14.9k|			break;
  337|  15.1k|	if (idx == SC_PKCS11_FRAMEWORK_DATA_MAX_NUM)
  ------------------
  |  |  194|  15.1k|#define SC_PKCS11_FRAMEWORK_DATA_MAX_NUM	4
  ------------------
  |  Branch (337:6): [True: 140, False: 14.9k]
  ------------------
  338|    140|		return CKR_USER_TOO_MANY_TYPES;
  ------------------
  |  | 1155|    140|#define CKR_USER_TOO_MANY_TYPES 0x00000105UL
  ------------------
  339|       |
  340|  14.9k|	if (!(fw_data = calloc(1, sizeof(*fw_data))))
  ------------------
  |  Branch (340:6): [True: 0, False: 14.9k]
  ------------------
  341|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  342|  14.9k|	p11card->fws_data[idx] = fw_data;
  343|       |
  344|  14.9k|	rc = sc_pkcs15_bind(p11card->card, aid, &fw_data->p15_card);
  345|  14.9k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  14.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:6): [True: 9.40k, False: 5.57k]
  ------------------
  346|  9.40k|		sc_log(context, "sc_pkcs15_bind failed: %d", rc);
  ------------------
  |  |   71|  9.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__
  |  |  ------------------
  ------------------
  347|  9.40k|		return sc_to_cryptoki_error(rc, NULL);
  348|  9.40k|	}
  349|       |
  350|       |	/* Mechanisms are registered globally per card. Checking
  351|       |	 * p11card->nmechanisms avoids registering the same mechanisms twice for a
  352|       |	 * card with multiple slots. */
  353|  5.57k|	if (!p11card->nmechanisms) {
  ------------------
  |  Branch (353:6): [True: 5.21k, False: 361]
  ------------------
  354|  5.21k|		ck_rv = register_mechanisms(p11card);
  355|  5.21k|		if (ck_rv != CKR_OK) {
  ------------------
  |  | 1086|  5.21k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (355:7): [True: 0, False: 5.21k]
  ------------------
  356|      0|			sc_log(context, "cannot register mechanisms; CKR 0x%lX",
  ------------------
  |  |   71|      0|#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|      0|			       ck_rv);
  358|      0|			return ck_rv;
  359|      0|		}
  360|  5.21k|	}
  361|       |
  362|  5.57k|	return CKR_OK;
  ------------------
  |  | 1086|  5.57k|#define CKR_OK 0x00000000UL
  ------------------
  363|  5.57k|}
framework-pkcs15.c:register_mechanisms:
 6556|  5.21k|{
 6557|  5.21k|	sc_card_t *card = p11card->card;
 6558|  5.21k|	sc_algorithm_info_t *alg_info;
 6559|  5.21k|	CK_MECHANISM_INFO mech_info;
 6560|  5.21k|	CK_ULONG ec_min_key_size, ec_max_key_size,
 6561|  5.21k|		aes_min_key_size, aes_max_key_size;
 6562|  5.21k|	unsigned long ec_ext_flags;
 6563|  5.21k|	sc_pkcs11_mechanism_type_t *mt = NULL, *registered_mt = NULL;
 6564|  5.21k|	unsigned int num;
 6565|  5.21k|	int rsa_flags = 0, ec_flags = 0, eddsa_flags = 0, xeddsa_flags = 0;
 6566|  5.21k|	int ec_found = 0, gostr_flags = 0, aes_flags = 0;
 6567|  5.21k|	CK_RV rc;
 6568|       |
 6569|       |	/* Register generic mechanisms */
 6570|  5.21k|	sc_pkcs11_register_generic_mechanisms(p11card);
 6571|       |
 6572|  5.21k|	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DECRYPT;
  ------------------
  |  |  352|  5.21k|#define CKF_HW 0x00000001UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DECRYPT;
  ------------------
  |  |  363|  5.21k|#define CKF_SIGN 0x00000800UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DECRYPT;
  ------------------
  |  |  361|  5.21k|#define CKF_DECRYPT 0x00000200UL
  ------------------
 6573|  5.21k|#ifdef ENABLE_OPENSSL
 6574|       |	/* That practise definitely conflicts with CKF_HW -- andre 2010-11-28 */
 6575|  5.21k|	mech_info.flags |= CKF_VERIFY;
  ------------------
  |  |  365|  5.21k|#define CKF_VERIFY 0x00002000UL
  ------------------
 6576|  5.21k|#endif
 6577|  5.21k|	if ((card->caps & SC_CARD_CAP_UNWRAP_KEY) == SC_CARD_CAP_UNWRAP_KEY)
  ------------------
  |  |  574|  5.21k|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
              	if ((card->caps & SC_CARD_CAP_UNWRAP_KEY) == SC_CARD_CAP_UNWRAP_KEY)
  ------------------
  |  |  574|  5.21k|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
  |  Branch (6577:6): [True: 23, False: 5.19k]
  ------------------
 6578|     23|		mech_info.flags |= CKF_UNWRAP;
  ------------------
  |  |  370|     23|#define CKF_UNWRAP 0x00040000UL
  ------------------
 6579|  5.21k|	if ((card->caps & SC_CARD_CAP_WRAP_KEY) == SC_CARD_CAP_WRAP_KEY)
  ------------------
  |  |  572|  5.21k|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
              	if ((card->caps & SC_CARD_CAP_WRAP_KEY) == SC_CARD_CAP_WRAP_KEY)
  ------------------
  |  |  572|  5.21k|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
  |  Branch (6579:6): [True: 23, False: 5.19k]
  ------------------
 6580|     23|		mech_info.flags |= CKF_WRAP;
  ------------------
  |  |  369|     23|#define CKF_WRAP 0x00020000UL
  ------------------
 6581|       |
 6582|  5.21k|	mech_info.ulMinKeySize = ~0;
 6583|  5.21k|	mech_info.ulMaxKeySize = 0;
 6584|  5.21k|	ec_min_key_size = ~0;
 6585|  5.21k|	ec_max_key_size = 0;
 6586|  5.21k|	aes_min_key_size = ~0;
 6587|  5.21k|	aes_max_key_size = 0;
 6588|       |
 6589|  5.21k|	ec_ext_flags = 0;
 6590|       |
 6591|       |	/* For now, we just OR all the algorithm specific
 6592|       |	 * flags, based on the assumption that cards don't
 6593|       |	 * support different modes for different key *sizes*. */
 6594|  5.21k|	num = card->algorithm_count;
 6595|  5.21k|	alg_info = card->algorithms;
 6596|  26.1k|	while (num--) {
  ------------------
  |  Branch (6596:9): [True: 20.8k, False: 5.21k]
  ------------------
 6597|  20.8k|		switch (alg_info->algorithm) {
  ------------------
  |  Branch (6597:11): [True: 20.8k, False: 12]
  ------------------
 6598|  15.4k|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|  15.4k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (6598:4): [True: 15.4k, False: 5.48k]
  ------------------
 6599|  15.4k|				if (alg_info->key_length < mech_info.ulMinKeySize)
  ------------------
  |  Branch (6599:9): [True: 4.98k, False: 10.4k]
  ------------------
 6600|  4.98k|					mech_info.ulMinKeySize = alg_info->key_length;
 6601|  15.4k|				if (alg_info->key_length > mech_info.ulMaxKeySize)
  ------------------
  |  Branch (6601:9): [True: 15.0k, False: 391]
  ------------------
 6602|  15.0k|					mech_info.ulMaxKeySize = alg_info->key_length;
 6603|  15.4k|				rsa_flags |= alg_info->flags;
 6604|  15.4k|				break;
 6605|  5.24k|			case SC_ALGORITHM_EC:
  ------------------
  |  |   70|  5.24k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6605:4): [True: 5.24k, False: 15.6k]
  ------------------
 6606|  5.24k|				if (alg_info->key_length < ec_min_key_size)
  ------------------
  |  Branch (6606:9): [True: 1.96k, False: 3.27k]
  ------------------
 6607|  1.96k|					ec_min_key_size = alg_info->key_length;
 6608|  5.24k|				if (alg_info->key_length > ec_max_key_size)
  ------------------
  |  Branch (6608:9): [True: 5.12k, False: 116]
  ------------------
 6609|  5.12k|					ec_max_key_size = alg_info->key_length;
 6610|  5.24k|				ec_flags |= alg_info->flags;
 6611|  5.24k|				ec_ext_flags |= alg_info->u._ec.ext_flags;
 6612|  5.24k|				ec_found = 1;
 6613|  5.24k|				break;
 6614|    106|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|    106|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6614:4): [True: 106, False: 20.7k]
  ------------------
 6615|    106|				eddsa_flags |= alg_info->flags;
 6616|    106|				break;
 6617|    106|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|    106|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6617:4): [True: 106, False: 20.7k]
  ------------------
 6618|    106|				xeddsa_flags |= alg_info->flags;
 6619|    106|				break;
 6620|      8|			case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      8|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (6620:4): [True: 8, False: 20.8k]
  ------------------
 6621|      8|				gostr_flags |= alg_info->flags;
 6622|      8|				break;
 6623|      7|			case SC_ALGORITHM_AES:
  ------------------
  |  |   79|      7|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (6623:4): [True: 7, False: 20.8k]
  ------------------
 6624|      7|				aes_flags |= alg_info->flags;
 6625|      7|				if (alg_info->key_length < aes_min_key_size)
  ------------------
  |  Branch (6625:9): [True: 5, False: 2]
  ------------------
 6626|      5|					aes_min_key_size = alg_info->key_length;
 6627|      7|				if (alg_info->key_length > aes_max_key_size)
  ------------------
  |  Branch (6627:9): [True: 7, False: 0]
  ------------------
 6628|      7|					aes_max_key_size = alg_info->key_length;
 6629|      7|				break;
 6630|  20.8k|		}
 6631|  20.8k|		alg_info++;
 6632|  20.8k|	}
 6633|       |
 6634|       |	/*
 6635|       |	 * TODO this looked like a bug:
 6636|       |	 * if (ec_flags & SC_ALGORITHM_ECDSA_RAW)
 6637|       |	 * Card driver driver should not have to specify SC_ALGORITHM_ECDSA_RAW
 6638|       |	 */
 6639|  5.21k|	if (ec_found) {
  ------------------
  |  Branch (6639:6): [True: 1.96k, False: 3.25k]
  ------------------
 6640|  1.96k|		rc = register_ec_mechanisms(p11card, ec_flags, ec_ext_flags, ec_min_key_size, ec_max_key_size);
 6641|  1.96k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  1.96k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6641:7): [True: 0, False: 1.96k]
  ------------------
 6642|      0|			return rc;
 6643|  1.96k|	}
 6644|       |
 6645|  5.21k|	if (eddsa_flags & SC_ALGORITHM_EDDSA_RAW) {
  ------------------
  |  |  188|  5.21k|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  |  Branch (6645:6): [True: 104, False: 5.11k]
  ------------------
 6646|    104|		rc = register_eddsa_mechanisms(p11card, eddsa_flags, 255, 255);
 6647|    104|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6647:7): [True: 0, False: 104]
  ------------------
 6648|      0|			return rc;
 6649|    104|	}
 6650|       |
 6651|  5.21k|	if (xeddsa_flags & (SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW)) {
  ------------------
  |  |  189|  5.21k|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              	if (xeddsa_flags & (SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW)) {
  ------------------
  |  |  173|  5.21k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  |  Branch (6651:6): [True: 104, False: 5.11k]
  ------------------
 6652|    104|		rc = register_xeddsa_mechanisms(p11card, xeddsa_flags, 255, 255);
 6653|    104|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6653:7): [True: 0, False: 104]
  ------------------
 6654|      0|			return rc;
 6655|    104|	}
 6656|       |
 6657|  5.21k|	if (gostr_flags & (SC_ALGORITHM_GOSTR3410_RAW
  ------------------
  |  |  156|  5.21k|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  ------------------
  |  Branch (6657:6): [True: 8, False: 5.21k]
  ------------------
 6658|  5.21k|				| SC_ALGORITHM_GOSTR3410_HASH_NONE
  ------------------
  |  |  157|  5.21k|#define SC_ALGORITHM_GOSTR3410_HASH_NONE	SC_ALGORITHM_GOSTR3410_RAW /*XXX*/
  |  |  ------------------
  |  |  |  |  156|  5.21k|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  |  |  ------------------
  ------------------
 6659|  5.21k|				| SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411)) {
  ------------------
  |  |  158|  5.21k|#define SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411	0x00080000
  ------------------
 6660|      8|		if (gostr_flags & SC_ALGORITHM_GOSTR3410_RAW)
  ------------------
  |  |  156|      8|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  ------------------
  |  Branch (6660:7): [True: 8, False: 0]
  ------------------
 6661|      8|			gostr_flags |= SC_ALGORITHM_GOSTR3410_HASH_NONE;
  ------------------
  |  |  157|      8|#define SC_ALGORITHM_GOSTR3410_HASH_NONE	SC_ALGORITHM_GOSTR3410_RAW /*XXX*/
  |  |  ------------------
  |  |  |  |  156|      8|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  |  |  ------------------
  ------------------
 6662|      8|		rc = register_gost_mechanisms(p11card, gostr_flags);
 6663|      8|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6663:7): [True: 0, False: 8]
  ------------------
 6664|      0|			return rc;
 6665|      8|	}
 6666|       |
 6667|       |	/* Check if we support raw RSA */
 6668|  5.21k|	if (rsa_flags & SC_ALGORITHM_RSA_RAW) {
  ------------------
  |  |  102|  5.21k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (6668:6): [True: 3.58k, False: 1.63k]
  ------------------
 6669|  3.58k|		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_X_509, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  541|  3.58k|#define CKM_RSA_X_509 0x00000003UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_X_509, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  464|  3.58k|#define CKK_RSA 0x00000000UL
  ------------------
 6670|  3.58k|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6671|  3.58k|		sc_pkcs11_free_mechanism(&mt);
 6672|  3.58k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.58k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6672:7): [True: 0, False: 3.58k]
  ------------------
 6673|      0|			return rc;
 6674|       |
 6675|       |		/* We support PKCS1 padding in software */
 6676|       |		/* either the card supports it or OpenSC does */
 6677|  3.58k|		rsa_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|  3.58k|#define SC_ALGORITHM_RSA_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|  3.58k|#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|  3.58k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
 6678|  3.58k|#ifdef ENABLE_OPENSSL
 6679|  3.58k|		rsa_flags |= SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|  3.58k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
 6680|  3.58k|		rsa_flags |= SC_ALGORITHM_RSA_PAD_OAEP;
  ------------------
  |  |  108|  3.58k|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
 6681|  3.58k|#endif
 6682|  3.58k|	}
 6683|       |
 6684|  5.21k|	if (rsa_flags & SC_ALGORITHM_RSA_PAD_ISO9796) {
  ------------------
  |  |  106|  5.21k|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  |  Branch (6684:6): [True: 832, False: 4.38k]
  ------------------
 6685|       |		/* Supported in hardware only, if the card driver declares it. */
 6686|    832|		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_9796, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  540|    832|#define CKM_RSA_9796 0x00000002UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_9796, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  464|    832|#define CKK_RSA 0x00000000UL
  ------------------
 6687|    832|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6688|    832|		sc_pkcs11_free_mechanism(&mt);
 6689|    832|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    832|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6689:7): [True: 0, False: 832]
  ------------------
 6690|      0|			return rc;
 6691|    832|	}
 6692|       |
 6693|  5.21k|#ifdef ENABLE_OPENSSL
 6694|       |	/* all our software hashes are in OpenSSL */
 6695|       |	/* Only if card did not list the hashes, will we
 6696|       |	 * help it a little, by adding all the OpenSSL hashes
 6697|       |	 * that have PKCS#11 mechanisms.
 6698|       |	 */
 6699|  5.21k|	if (!(rsa_flags & (SC_ALGORITHM_RSA_HASHES & ~SC_ALGORITHM_RSA_HASH_NONE))) {
  ------------------
  |  |  142|  5.21k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
              	if (!(rsa_flags & (SC_ALGORITHM_RSA_HASHES & ~SC_ALGORITHM_RSA_HASH_NONE))) {
  ------------------
  |  |  133|  5.21k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (6699:6): [True: 4.00k, False: 1.21k]
  ------------------
 6700|  4.00k|		rsa_flags |= SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|  4.00k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
 6701|  4.00k|	}
 6702|  5.21k|#endif
 6703|       |
 6704|       |	/* No need to Check for PKCS1  We support it in software and turned it on above so always added it */
 6705|  5.21k|	if (rsa_flags & SC_ALGORITHM_RSA_PAD_PKCS1) {
  ------------------
  |  |  111|  5.21k|#define SC_ALGORITHM_RSA_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.21k|#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.21k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (6705:6): [True: 4.96k, False: 257]
  ------------------
 6706|  4.96k|		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  539|  4.96k|#define CKM_RSA_PKCS 0x00000001UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  464|  4.96k|#define CKK_RSA 0x00000000UL
  ------------------
 6707|  4.96k|		rc = sc_pkcs11_register_mechanism(p11card, mt, &registered_mt);
 6708|  4.96k|		sc_pkcs11_free_mechanism(&mt);
 6709|  4.96k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.96k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6709:7): [True: 0, False: 4.96k]
  ------------------
 6710|      0|			return rc;
 6711|       |
 6712|  4.96k|#ifdef ENABLE_OPENSSL
 6713|       |		/* sc_pkcs11_register_sign_and_hash_mechanism expects software hash */
 6714|       |		/* All hashes are in OpenSSL
 6715|       |		 * Either the card set the hashes or we helped it above */
 6716|       |
 6717|  4.96k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA1) {
  ------------------
  |  |  134|  4.96k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (6717:7): [True: 4.64k, False: 314]
  ------------------
 6718|  4.64k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6719|  4.64k|				CKM_SHA1_RSA_PKCS, CKM_SHA_1, registered_mt);
  ------------------
  |  |  544|  4.64k|#define CKM_SHA1_RSA_PKCS 0x00000006UL
  ------------------
              				CKM_SHA1_RSA_PKCS, CKM_SHA_1, registered_mt);
  ------------------
  |  |  667|  4.64k|#define CKM_SHA_1 0x00000220UL
  ------------------
 6720|  4.64k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.64k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6720:8): [True: 0, False: 4.64k]
  ------------------
 6721|      0|				return rc;
 6722|  4.64k|		}
 6723|  4.96k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA224) {
  ------------------
  |  |  141|  4.96k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  |  Branch (6723:7): [True: 3.87k, False: 1.08k]
  ------------------
 6724|  3.87k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6725|  3.87k|				CKM_SHA224_RSA_PKCS, CKM_SHA224, registered_mt);
  ------------------
  |  |  604|  3.87k|#define CKM_SHA224_RSA_PKCS 0x00000046UL
  ------------------
              				CKM_SHA224_RSA_PKCS, CKM_SHA224, registered_mt);
  ------------------
  |  |  679|  3.87k|#define CKM_SHA224 0x00000255UL
  ------------------
 6726|  3.87k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.87k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6726:8): [True: 0, False: 3.87k]
  ------------------
 6727|      0|				return rc;
 6728|  3.87k|		}
 6729|  4.96k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA256) {
  ------------------
  |  |  138|  4.96k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (6729:7): [True: 4.82k, False: 141]
  ------------------
 6730|  4.82k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6731|  4.82k|				CKM_SHA256_RSA_PKCS, CKM_SHA256, registered_mt);
  ------------------
  |  |  598|  4.82k|#define CKM_SHA256_RSA_PKCS 0x00000040UL
  ------------------
              				CKM_SHA256_RSA_PKCS, CKM_SHA256, registered_mt);
  ------------------
  |  |  676|  4.82k|#define CKM_SHA256 0x00000250UL
  ------------------
 6732|  4.82k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.82k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6732:8): [True: 0, False: 4.82k]
  ------------------
 6733|      0|				return rc;
 6734|  4.82k|		}
 6735|  4.96k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA384) {
  ------------------
  |  |  139|  4.96k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  |  Branch (6735:7): [True: 4.24k, False: 721]
  ------------------
 6736|  4.24k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6737|  4.24k|				CKM_SHA384_RSA_PKCS, CKM_SHA384, registered_mt);
  ------------------
  |  |  599|  4.24k|#define CKM_SHA384_RSA_PKCS 0x00000041UL
  ------------------
              				CKM_SHA384_RSA_PKCS, CKM_SHA384, registered_mt);
  ------------------
  |  |  682|  4.24k|#define CKM_SHA384 0x00000260UL
  ------------------
 6738|  4.24k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.24k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6738:8): [True: 0, False: 4.24k]
  ------------------
 6739|      0|				return rc;
 6740|  4.24k|		}
 6741|  4.96k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA512) {
  ------------------
  |  |  140|  4.96k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  |  Branch (6741:7): [True: 4.24k, False: 721]
  ------------------
 6742|  4.24k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6743|  4.24k|				CKM_SHA512_RSA_PKCS, CKM_SHA512, registered_mt);
  ------------------
  |  |  600|  4.24k|#define CKM_SHA512_RSA_PKCS 0x00000042UL
  ------------------
              				CKM_SHA512_RSA_PKCS, CKM_SHA512, registered_mt);
  ------------------
  |  |  685|  4.24k|#define CKM_SHA512 0x00000270UL
  ------------------
 6744|  4.24k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.24k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6744:8): [True: 0, False: 4.24k]
  ------------------
 6745|      0|				return rc;
 6746|  4.24k|		}
 6747|  4.96k|		if (!FIPS_mode() && rsa_flags & SC_ALGORITHM_RSA_HASH_MD5) {
  ------------------
  |  |  135|  4.96k|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  |  Branch (6747:7): [True: 4.96k, False: 0]
  |  Branch (6747:23): [True: 4.19k, False: 768]
  ------------------
 6748|  4.19k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6749|  4.19k|				CKM_MD5_RSA_PKCS, CKM_MD5, registered_mt);
  ------------------
  |  |  543|  4.19k|#define CKM_MD5_RSA_PKCS 0x00000005UL
  ------------------
              				CKM_MD5_RSA_PKCS, CKM_MD5, registered_mt);
  ------------------
  |  |  664|  4.19k|#define CKM_MD5 0x00000210UL
  ------------------
 6750|  4.19k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.19k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6750:8): [True: 0, False: 4.19k]
  ------------------
 6751|      0|				return rc;
 6752|  4.19k|		}
 6753|  4.96k|		if (!FIPS_mode() && rsa_flags & SC_ALGORITHM_RSA_HASH_RIPEMD160) {
  ------------------
  |  |  137|  4.96k|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  |  Branch (6753:7): [True: 4.96k, False: 0]
  |  Branch (6753:23): [True: 4.19k, False: 768]
  ------------------
 6754|  4.19k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6755|  4.19k|				CKM_RIPEMD160_RSA_PKCS, CKM_RIPEMD160, registered_mt);
  ------------------
  |  |  546|  4.19k|#define CKM_RIPEMD160_RSA_PKCS 0x00000008UL
  ------------------
              				CKM_RIPEMD160_RSA_PKCS, CKM_RIPEMD160, registered_mt);
  ------------------
  |  |  673|  4.19k|#define CKM_RIPEMD160 0x00000240UL
  ------------------
 6756|  4.19k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  4.19k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6756:8): [True: 0, False: 4.19k]
  ------------------
 6757|      0|				return rc;
 6758|  4.19k|		}
 6759|  4.96k|#endif /* ENABLE_OPENSSL */
 6760|  4.96k|	}
 6761|       |
 6762|  5.21k|	if (rsa_flags & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  107|  5.21k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (6762:6): [True: 3.93k, False: 1.28k]
  ------------------
 6763|  3.93k|		CK_FLAGS old_flags = mech_info.flags;
 6764|  3.93k|		mech_info.flags &= ~(CKF_DECRYPT|CKF_ENCRYPT|CKF_WRAP|CKF_UNWRAP);
  ------------------
  |  |  361|  3.93k|#define CKF_DECRYPT 0x00000200UL
  ------------------
              		mech_info.flags &= ~(CKF_DECRYPT|CKF_ENCRYPT|CKF_WRAP|CKF_UNWRAP);
  ------------------
  |  |  360|  3.93k|#define CKF_ENCRYPT 0x00000100UL
  ------------------
              		mech_info.flags &= ~(CKF_DECRYPT|CKF_ENCRYPT|CKF_WRAP|CKF_UNWRAP);
  ------------------
  |  |  369|  3.93k|#define CKF_WRAP 0x00020000UL
  ------------------
              		mech_info.flags &= ~(CKF_DECRYPT|CKF_ENCRYPT|CKF_WRAP|CKF_UNWRAP);
  ------------------
  |  |  370|  3.93k|#define CKF_UNWRAP 0x00040000UL
  ------------------
 6765|  3.93k|		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS_PSS, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  551|  3.93k|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS_PSS, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  464|  3.93k|#define CKK_RSA 0x00000000UL
  ------------------
 6766|  3.93k|		rc = sc_pkcs11_register_mechanism(p11card, mt, &registered_mt);
 6767|  3.93k|		sc_pkcs11_free_mechanism(&mt);
 6768|  3.93k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.93k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6768:7): [True: 0, False: 3.93k]
  ------------------
 6769|      0|			return rc;
 6770|       |
 6771|  3.93k|#ifdef ENABLE_OPENSSL
 6772|       |		/* sc_pkcs11_register_sign_and_hash_mechanism expects software hash */
 6773|       |		/* All hashes are in OpenSSL
 6774|       |		 * Either the card set the hashes or we helped it above */
 6775|       |
 6776|  3.93k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA1) {
  ------------------
  |  |  134|  3.93k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (6776:7): [True: 3.67k, False: 260]
  ------------------
 6777|  3.67k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6778|  3.67k|				CKM_SHA1_RSA_PKCS_PSS, CKM_SHA_1, registered_mt);
  ------------------
  |  |  552|  3.67k|#define CKM_SHA1_RSA_PKCS_PSS 0x0000000EUL
  ------------------
              				CKM_SHA1_RSA_PKCS_PSS, CKM_SHA_1, registered_mt);
  ------------------
  |  |  667|  3.67k|#define CKM_SHA_1 0x00000220UL
  ------------------
 6779|  3.67k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.67k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6779:8): [True: 0, False: 3.67k]
  ------------------
 6780|      0|				return rc;
 6781|  3.67k|		}
 6782|  3.93k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA224) {
  ------------------
  |  |  141|  3.93k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  |  Branch (6782:7): [True: 3.54k, False: 388]
  ------------------
 6783|  3.54k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6784|  3.54k|				CKM_SHA224_RSA_PKCS_PSS, CKM_SHA224, registered_mt);
  ------------------
  |  |  605|  3.54k|#define CKM_SHA224_RSA_PKCS_PSS 0x00000047UL
  ------------------
              				CKM_SHA224_RSA_PKCS_PSS, CKM_SHA224, registered_mt);
  ------------------
  |  |  679|  3.54k|#define CKM_SHA224 0x00000255UL
  ------------------
 6785|  3.54k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.54k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6785:8): [True: 0, False: 3.54k]
  ------------------
 6786|      0|				return rc;
 6787|  3.54k|		}
 6788|  3.93k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA256) {
  ------------------
  |  |  138|  3.93k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (6788:7): [True: 3.90k, False: 25]
  ------------------
 6789|  3.90k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6790|  3.90k|				CKM_SHA256_RSA_PKCS_PSS, CKM_SHA256, registered_mt);
  ------------------
  |  |  601|  3.90k|#define CKM_SHA256_RSA_PKCS_PSS 0x00000043UL
  ------------------
              				CKM_SHA256_RSA_PKCS_PSS, CKM_SHA256, registered_mt);
  ------------------
  |  |  676|  3.90k|#define CKM_SHA256 0x00000250UL
  ------------------
 6791|  3.90k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.90k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6791:8): [True: 0, False: 3.90k]
  ------------------
 6792|      0|				return rc;
 6793|  3.90k|		}
 6794|  3.93k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA384) {
  ------------------
  |  |  139|  3.93k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  |  Branch (6794:7): [True: 3.90k, False: 25]
  ------------------
 6795|  3.90k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6796|  3.90k|				CKM_SHA384_RSA_PKCS_PSS, CKM_SHA384, registered_mt);
  ------------------
  |  |  602|  3.90k|#define CKM_SHA384_RSA_PKCS_PSS 0x00000044UL
  ------------------
              				CKM_SHA384_RSA_PKCS_PSS, CKM_SHA384, registered_mt);
  ------------------
  |  |  682|  3.90k|#define CKM_SHA384 0x00000260UL
  ------------------
 6797|  3.90k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.90k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6797:8): [True: 0, False: 3.90k]
  ------------------
 6798|      0|				return rc;
 6799|  3.90k|		}
 6800|  3.93k|		if (rsa_flags & SC_ALGORITHM_RSA_HASH_SHA512) {
  ------------------
  |  |  140|  3.93k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  |  Branch (6800:7): [True: 3.90k, False: 25]
  ------------------
 6801|  3.90k|			rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6802|  3.90k|				CKM_SHA512_RSA_PKCS_PSS, CKM_SHA512, registered_mt);
  ------------------
  |  |  603|  3.90k|#define CKM_SHA512_RSA_PKCS_PSS 0x00000045UL
  ------------------
              				CKM_SHA512_RSA_PKCS_PSS, CKM_SHA512, registered_mt);
  ------------------
  |  |  685|  3.90k|#define CKM_SHA512 0x00000270UL
  ------------------
 6803|  3.90k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  3.90k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6803:8): [True: 0, False: 3.90k]
  ------------------
 6804|      0|				return rc;
 6805|  3.90k|		}
 6806|  3.93k|#endif /* ENABLE_OPENSSL */
 6807|  3.93k|		mech_info.flags = old_flags;
 6808|  3.93k|	}
 6809|       |
 6810|  5.21k|	if (rsa_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  108|  5.21k|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (6810:6): [True: 3.84k, False: 1.37k]
  ------------------
 6811|  3.84k|		CK_FLAGS old_flags = mech_info.flags;
 6812|  3.84k|		mech_info.flags &= ~(CKF_SIGN|CKF_VERIFY|CKF_SIGN_RECOVER|CKF_VERIFY_RECOVER);
  ------------------
  |  |  363|  3.84k|#define CKF_SIGN 0x00000800UL
  ------------------
              		mech_info.flags &= ~(CKF_SIGN|CKF_VERIFY|CKF_SIGN_RECOVER|CKF_VERIFY_RECOVER);
  ------------------
  |  |  365|  3.84k|#define CKF_VERIFY 0x00002000UL
  ------------------
              		mech_info.flags &= ~(CKF_SIGN|CKF_VERIFY|CKF_SIGN_RECOVER|CKF_VERIFY_RECOVER);
  ------------------
  |  |  364|  3.84k|#define CKF_SIGN_RECOVER 0x00001000UL
  ------------------
              		mech_info.flags &= ~(CKF_SIGN|CKF_VERIFY|CKF_SIGN_RECOVER|CKF_VERIFY_RECOVER);
  ------------------
  |  |  366|  3.84k|#define CKF_VERIFY_RECOVER 0x00004000UL
  ------------------
 6813|  3.84k|		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS_OAEP, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  547|  3.84k|#define CKM_RSA_PKCS_OAEP 0x00000009UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS_OAEP, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  464|  3.84k|#define CKK_RSA 0x00000000UL
  ------------------
 6814|  3.84k|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6815|  3.84k|		sc_pkcs11_free_mechanism(&mt);
 6816|  3.84k|		if (rc != CKR_OK) {
  ------------------
  |  | 1086|  3.84k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6816:7): [True: 0, False: 3.84k]
  ------------------
 6817|      0|			return rc;
 6818|      0|		}
 6819|  3.84k|		mech_info.flags = old_flags;
 6820|  3.84k|	}
 6821|       |
 6822|  5.21k|	if (rsa_flags & SC_ALGORITHM_ONBOARD_KEY_GEN) {
  ------------------
  |  |   93|  5.21k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  |  Branch (6822:6): [True: 1.24k, False: 3.96k]
  ------------------
 6823|  1.24k|		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  352|  1.24k|#define CKF_HW 0x00000001UL
  ------------------
              		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  368|  1.24k|#define CKF_GENERATE_KEY_PAIR 0x00010000UL
  ------------------
 6824|  1.24k|		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS_KEY_PAIR_GEN, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  538|  1.24k|#define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_RSA_PKCS_KEY_PAIR_GEN, &mech_info, CKK_RSA, NULL, NULL, NULL);
  ------------------
  |  |  464|  1.24k|#define CKK_RSA 0x00000000UL
  ------------------
 6825|  1.24k|		if (!mt)
  ------------------
  |  Branch (6825:7): [True: 0, False: 1.24k]
  ------------------
 6826|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6827|  1.24k|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6828|  1.24k|		sc_pkcs11_free_mechanism(&mt);
 6829|  1.24k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  1.24k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6829:7): [True: 0, False: 1.24k]
  ------------------
 6830|      0|			return rc;
 6831|  1.24k|	}
 6832|       |
 6833|  5.21k|	if (aes_max_key_size > 0) {
  ------------------
  |  Branch (6833:6): [True: 5, False: 5.21k]
  ------------------
 6834|      5|		rc = sc_pkcs11_register_aes_mechanisms(p11card, aes_flags, aes_min_key_size, aes_max_key_size);
 6835|      5|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      5|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6835:7): [True: 0, False: 5]
  ------------------
 6836|      0|			return rc;
 6837|      5|	}
 6838|       |
 6839|       |
 6840|  5.21k|	return CKR_OK;
  ------------------
  |  | 1086|  5.21k|#define CKR_OK 0x00000000UL
  ------------------
 6841|  5.21k|}
framework-pkcs15.c:register_ec_mechanisms:
 6237|  1.96k|{
 6238|  1.96k|	CK_MECHANISM_INFO mech_info;
 6239|  1.96k|	sc_pkcs11_mechanism_type_t *mt = NULL, *registered_mt = NULL;
 6240|  1.96k|	CK_FLAGS ec_flags = 0;
 6241|  1.96k|	CK_RV rc;
 6242|       |
 6243|  1.96k|	if (ext_flags & SC_ALGORITHM_EXT_EC_F_P)
  ------------------
  |  |  198|  1.96k|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
  |  Branch (6243:6): [True: 169, False: 1.79k]
  ------------------
 6244|    169|		ec_flags |= CKF_EC_F_P;
  ------------------
  |  |  372|    169|#define CKF_EC_F_P 0x00100000UL
  ------------------
 6245|  1.96k|	if (ext_flags & SC_ALGORITHM_EXT_EC_F_2M)
  ------------------
  |  |  199|  1.96k|#define SC_ALGORITHM_EXT_EC_F_2M         0x00000002
  ------------------
  |  Branch (6245:6): [True: 0, False: 1.96k]
  ------------------
 6246|      0|		ec_flags |= CKF_EC_F_2M;
  ------------------
  |  |  373|      0|#define CKF_EC_F_2M 0x00200000UL
  ------------------
 6247|  1.96k|	if (ext_flags & SC_ALGORITHM_EXT_EC_ECPARAMETERS)
  ------------------
  |  |  200|  1.96k|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
  |  Branch (6247:6): [True: 144, False: 1.81k]
  ------------------
 6248|    144|		ec_flags |= CKF_EC_ECPARAMETERS;
  ------------------
  |  |  374|    144|#define CKF_EC_ECPARAMETERS 0x00400000UL
  ------------------
 6249|  1.96k|	if (ext_flags & SC_ALGORITHM_EXT_EC_NAMEDCURVE)
  ------------------
  |  |  201|  1.96k|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  |  Branch (6249:6): [True: 1.90k, False: 54]
  ------------------
 6250|  1.90k|		ec_flags |= CKF_EC_NAMEDCURVE;
  ------------------
  |  |  384|  1.90k|#define CKF_EC_NAMEDCURVE 0x00800000U
  ------------------
 6251|  1.96k|	if (ext_flags & SC_ALGORITHM_EXT_EC_UNCOMPRESES)
  ------------------
  |  |  202|  1.96k|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  |  Branch (6251:6): [True: 1.90k, False: 56]
  ------------------
 6252|  1.90k|		ec_flags |= CKF_EC_UNCOMPRESS;
  ------------------
  |  |  376|  1.90k|#define CKF_EC_UNCOMPRESS 0x01000000UL
  ------------------
 6253|  1.96k|	if (ext_flags & SC_ALGORITHM_EXT_EC_COMPRESS)
  ------------------
  |  |  203|  1.96k|#define SC_ALGORITHM_EXT_EC_COMPRESS     0x00000020
  ------------------
  |  Branch (6253:6): [True: 0, False: 1.96k]
  ------------------
 6254|      0|		ec_flags |= CKF_EC_COMPRESS;
  ------------------
  |  |  377|      0|#define CKF_EC_COMPRESS 0x02000000UL
  ------------------
 6255|       |
 6256|  1.96k|	mech_info.flags = CKF_HW | CKF_SIGN | CKF_VERIFY;
  ------------------
  |  |  352|  1.96k|#define CKF_HW 0x00000001UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_VERIFY;
  ------------------
  |  |  363|  1.96k|#define CKF_SIGN 0x00000800UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_VERIFY;
  ------------------
  |  |  365|  1.96k|#define CKF_VERIFY 0x00002000UL
  ------------------
 6257|  1.96k|	mech_info.flags |= ec_flags;
 6258|  1.96k|	mech_info.ulMinKeySize = min_key_size;
 6259|  1.96k|	mech_info.ulMaxKeySize = max_key_size;
 6260|       |
 6261|       |	/* add mechs card or driver support */
 6262|  1.96k|	if (flags & SC_ALGORITHM_ECDSA_RAW) {
  ------------------
  |  |  174|  1.96k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (6262:6): [True: 1.93k, False: 25]
  ------------------
 6263|  1.93k|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  860|  1.93k|#define CKM_ECDSA 0x00001041UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|  1.93k|#define CKK_EC 0x00000003UL
  ------------------
 6264|  1.93k|		if (!mt)
  ------------------
  |  Branch (6264:7): [True: 0, False: 1.93k]
  ------------------
 6265|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6266|  1.93k|		if (flags & SC_ALGORITHM_ECDSA_HASH_NONE) {
  ------------------
  |  |  175|  1.93k|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|  1.93k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  |  Branch (6266:7): [True: 1.93k, False: 0]
  ------------------
 6267|  1.93k|			rc = sc_pkcs11_register_mechanism(p11card, mt, &registered_mt);
 6268|  1.93k|			sc_pkcs11_free_mechanism(&mt);
 6269|  1.93k|			if (rc != CKR_OK)
  ------------------
  |  | 1086|  1.93k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6269:8): [True: 0, False: 1.93k]
  ------------------
 6270|      0|				return rc;
 6271|  1.93k|		}
 6272|       |
 6273|  1.93k|#ifdef ENABLE_OPENSSL
 6274|       |		/* if card supports RAW add sign_and_hash using RAW for mechs  card does not support */
 6275|  1.93k|		sc_pkcs11_mechanism_type_t *sign_type = mt ? mt : registered_mt;
  ------------------
  |  Branch (6275:43): [True: 0, False: 1.93k]
  ------------------
 6276|  1.93k|		if (flags & SC_ALGORITHM_ECDSA_RAW) {
  ------------------
  |  |  174|  1.93k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (6276:7): [True: 1.93k, False: 0]
  ------------------
 6277|  1.93k|			if (!(flags & SC_ALGORITHM_ECDSA_HASH_SHA1)) {
  ------------------
  |  |  176|  1.93k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|  1.93k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  |  Branch (6277:8): [True: 1.78k, False: 150]
  ------------------
 6278|  1.78k|				rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6279|  1.78k|					CKM_ECDSA_SHA1, CKM_SHA_1, sign_type);
  ------------------
  |  |  861|  1.78k|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
              					CKM_ECDSA_SHA1, CKM_SHA_1, sign_type);
  ------------------
  |  |  667|  1.78k|#define CKM_SHA_1 0x00000220UL
  ------------------
 6280|  1.78k|				if (rc != CKR_OK) {
  ------------------
  |  | 1086|  1.78k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6280:9): [True: 0, False: 1.78k]
  ------------------
 6281|      0|					sc_pkcs11_free_mechanism(&mt);
 6282|      0|					return rc;
 6283|      0|				}
 6284|  1.78k|			}
 6285|       |
 6286|  1.93k|			if (!(flags & SC_ALGORITHM_ECDSA_HASH_SHA224)) {
  ------------------
  |  |  177|  1.93k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|  1.93k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
  |  Branch (6286:8): [True: 1.83k, False: 103]
  ------------------
 6287|  1.83k|				rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6288|  1.83k|					CKM_ECDSA_SHA224, CKM_SHA224, sign_type);
  ------------------
  |  |  862|  1.83k|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
              					CKM_ECDSA_SHA224, CKM_SHA224, sign_type);
  ------------------
  |  |  679|  1.83k|#define CKM_SHA224 0x00000255UL
  ------------------
 6289|  1.83k|				if (rc != CKR_OK) {
  ------------------
  |  | 1086|  1.83k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6289:9): [True: 0, False: 1.83k]
  ------------------
 6290|      0|					sc_pkcs11_free_mechanism(&mt);
 6291|      0|					return rc;
 6292|      0|				}
 6293|  1.83k|			}
 6294|       |
 6295|  1.93k|			if (!(flags & SC_ALGORITHM_ECDSA_HASH_SHA256)) {
  ------------------
  |  |  178|  1.93k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|  1.93k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  |  Branch (6295:8): [True: 1.78k, False: 150]
  ------------------
 6296|  1.78k|				rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6297|  1.78k|					CKM_ECDSA_SHA256, CKM_SHA256, sign_type);
  ------------------
  |  |  863|  1.78k|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
              					CKM_ECDSA_SHA256, CKM_SHA256, sign_type);
  ------------------
  |  |  676|  1.78k|#define CKM_SHA256 0x00000250UL
  ------------------
 6298|  1.78k|				if (rc != CKR_OK) {
  ------------------
  |  | 1086|  1.78k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6298:9): [True: 0, False: 1.78k]
  ------------------
 6299|      0|					sc_pkcs11_free_mechanism(&mt);
 6300|      0|					return rc;
 6301|      0|				}
 6302|  1.78k|			}
 6303|       |
 6304|  1.93k|			if (!(flags & SC_ALGORITHM_ECDSA_HASH_SHA384)) {
  ------------------
  |  |  179|  1.93k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|  1.93k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
  |  Branch (6304:8): [True: 1.83k, False: 103]
  ------------------
 6305|  1.83k|				rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6306|  1.83k|					CKM_ECDSA_SHA384, CKM_SHA384, sign_type);
  ------------------
  |  |  864|  1.83k|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
              					CKM_ECDSA_SHA384, CKM_SHA384, sign_type);
  ------------------
  |  |  682|  1.83k|#define CKM_SHA384 0x00000260UL
  ------------------
 6307|  1.83k|				if (rc != CKR_OK) {
  ------------------
  |  | 1086|  1.83k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6307:9): [True: 0, False: 1.83k]
  ------------------
 6308|      0|					sc_pkcs11_free_mechanism(&mt);
 6309|      0|					return rc;
 6310|      0|				}
 6311|  1.83k|			}
 6312|       |
 6313|  1.93k|			if (!(flags & SC_ALGORITHM_ECDSA_HASH_SHA512)) {
  ------------------
  |  |  180|  1.93k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|  1.93k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
  |  Branch (6313:8): [True: 1.83k, False: 103]
  ------------------
 6314|  1.83k|				rc = sc_pkcs11_register_sign_and_hash_mechanism(p11card,
 6315|  1.83k|					CKM_ECDSA_SHA512, CKM_SHA512, sign_type);
  ------------------
  |  |  865|  1.83k|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
              					CKM_ECDSA_SHA512, CKM_SHA512, sign_type);
  ------------------
  |  |  685|  1.83k|#define CKM_SHA512 0x00000270UL
  ------------------
 6316|  1.83k|				if (rc != CKR_OK) {
  ------------------
  |  | 1086|  1.83k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6316:9): [True: 0, False: 1.83k]
  ------------------
 6317|      0|					sc_pkcs11_free_mechanism(&mt);
 6318|      0|					return rc;
 6319|      0|				}
 6320|  1.83k|			}
 6321|  1.93k|		}
 6322|  1.93k|		sc_pkcs11_free_mechanism(&mt);
 6323|  1.93k|#endif
 6324|  1.93k|	}
 6325|       |
 6326|  1.96k|	if (flags & SC_ALGORITHM_ECDSA_HASH_SHA1) {
  ------------------
  |  |  176|  1.96k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|  1.96k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  |  Branch (6326:6): [True: 175, False: 1.78k]
  ------------------
 6327|    175|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA1, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  861|    175|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA1, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|    175|#define CKK_EC 0x00000003UL
  ------------------
 6328|    175|		if (!mt)
  ------------------
  |  Branch (6328:7): [True: 0, False: 175]
  ------------------
 6329|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6330|    175|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6331|    175|		sc_pkcs11_free_mechanism(&mt);
 6332|    175|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    175|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6332:7): [True: 0, False: 175]
  ------------------
 6333|      0|			return rc;
 6334|    175|	}
 6335|       |
 6336|  1.96k|	if (flags & SC_ALGORITHM_ECDSA_HASH_SHA224) {
  ------------------
  |  |  177|  1.96k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|  1.96k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
  |  Branch (6336:6): [True: 103, False: 1.86k]
  ------------------
 6337|    103|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA224, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  862|    103|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA224, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|    103|#define CKK_EC 0x00000003UL
  ------------------
 6338|    103|		if (!mt)
  ------------------
  |  Branch (6338:7): [True: 0, False: 103]
  ------------------
 6339|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6340|    103|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6341|    103|		sc_pkcs11_free_mechanism(&mt);
 6342|    103|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    103|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6342:7): [True: 0, False: 103]
  ------------------
 6343|      0|			return rc;
 6344|    103|	}
 6345|       |
 6346|  1.96k|	if (flags & SC_ALGORITHM_ECDSA_HASH_SHA256) {
  ------------------
  |  |  178|  1.96k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|  1.96k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  |  Branch (6346:6): [True: 150, False: 1.81k]
  ------------------
 6347|    150|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA256, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  863|    150|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA256, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|    150|#define CKK_EC 0x00000003UL
  ------------------
 6348|    150|		if (!mt)
  ------------------
  |  Branch (6348:7): [True: 0, False: 150]
  ------------------
 6349|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6350|    150|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6351|    150|		sc_pkcs11_free_mechanism(&mt);
 6352|    150|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    150|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6352:7): [True: 0, False: 150]
  ------------------
 6353|      0|			return rc;
 6354|    150|	}
 6355|       |
 6356|  1.96k|	if (flags & SC_ALGORITHM_ECDSA_HASH_SHA384) {
  ------------------
  |  |  179|  1.96k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|  1.96k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
  |  Branch (6356:6): [True: 103, False: 1.86k]
  ------------------
 6357|    103|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA384, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  864|    103|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA384, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|    103|#define CKK_EC 0x00000003UL
  ------------------
 6358|    103|		if (!mt)
  ------------------
  |  Branch (6358:7): [True: 0, False: 103]
  ------------------
 6359|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6360|    103|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6361|    103|		sc_pkcs11_free_mechanism(&mt);
 6362|    103|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    103|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6362:7): [True: 0, False: 103]
  ------------------
 6363|      0|			return rc;
 6364|    103|	}
 6365|       |
 6366|  1.96k|	if (flags & SC_ALGORITHM_ECDSA_HASH_SHA512) {
  ------------------
  |  |  180|  1.96k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|  1.96k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
  |  Branch (6366:6): [True: 103, False: 1.86k]
  ------------------
 6367|    103|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA512, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  865|    103|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDSA_SHA512, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|    103|#define CKK_EC 0x00000003UL
  ------------------
 6368|    103|		if (!mt)
  ------------------
  |  Branch (6368:7): [True: 0, False: 103]
  ------------------
 6369|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6370|    103|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6371|    103|		sc_pkcs11_free_mechanism(&mt);
 6372|    103|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    103|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6372:7): [True: 0, False: 103]
  ------------------
 6373|      0|			return rc;
 6374|    103|	}
 6375|       |
 6376|       |	/* ADD ECDH mechanisms */
 6377|       |	/* The PIV uses curves where CKM_ECDH1_DERIVE and CKM_ECDH1_COFACTOR_DERIVE produce the same results */
 6378|  1.96k|	if (flags & SC_ALGORITHM_ECDH_CDH_RAW) {
  ------------------
  |  |  173|  1.96k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  |  Branch (6378:6): [True: 1.84k, False: 115]
  ------------------
 6379|  1.84k|		mech_info.flags &= ~(CKF_SIGN | CKF_VERIFY);
  ------------------
  |  |  363|  1.84k|#define CKF_SIGN 0x00000800UL
  ------------------
              		mech_info.flags &= ~(CKF_SIGN | CKF_VERIFY);
  ------------------
  |  |  365|  1.84k|#define CKF_VERIFY 0x00002000UL
  ------------------
 6380|  1.84k|		mech_info.flags |= CKF_DERIVE;
  ------------------
  |  |  371|  1.84k|#define CKF_DERIVE 0x00080000UL
  ------------------
 6381|       |
 6382|  1.84k|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDH1_COFACTOR_DERIVE, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  868|  1.84k|#define CKM_ECDH1_COFACTOR_DERIVE 0x00001051UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDH1_COFACTOR_DERIVE, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|  1.84k|#define CKK_EC 0x00000003UL
  ------------------
 6383|  1.84k|		if (!mt)
  ------------------
  |  Branch (6383:7): [True: 0, False: 1.84k]
  ------------------
 6384|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6385|  1.84k|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6386|  1.84k|		sc_pkcs11_free_mechanism(&mt);
 6387|  1.84k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  1.84k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6387:7): [True: 0, False: 1.84k]
  ------------------
 6388|      0|			return rc;
 6389|       |
 6390|  1.84k|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDH1_DERIVE, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  867|  1.84k|#define CKM_ECDH1_DERIVE 0x00001050UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDH1_DERIVE, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|  1.84k|#define CKK_EC 0x00000003UL
  ------------------
 6391|  1.84k|		if (!mt)
  ------------------
  |  Branch (6391:7): [True: 0, False: 1.84k]
  ------------------
 6392|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6393|  1.84k|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6394|  1.84k|		sc_pkcs11_free_mechanism(&mt);
 6395|  1.84k|		if (rc != CKR_OK)
  ------------------
  |  | 1086|  1.84k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6395:7): [True: 0, False: 1.84k]
  ------------------
 6396|      0|			return rc;
 6397|  1.84k|	}
 6398|       |
 6399|  1.96k|	if (flags & SC_ALGORITHM_ONBOARD_KEY_GEN) {
  ------------------
  |  |   93|  1.96k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  |  Branch (6399:6): [True: 201, False: 1.76k]
  ------------------
 6400|    201|		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  352|    201|#define CKF_HW 0x00000001UL
  ------------------
              		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  368|    201|#define CKF_GENERATE_KEY_PAIR 0x00010000UL
  ------------------
 6401|    201|		mech_info.flags |= ec_flags;
 6402|    201|		mt = sc_pkcs11_new_fw_mechanism(CKM_EC_KEY_PAIR_GEN, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  859|    201|#define CKM_EC_KEY_PAIR_GEN 0x00001040UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_EC_KEY_PAIR_GEN, &mech_info, CKK_EC, NULL, NULL, NULL);
  ------------------
  |  |  467|    201|#define CKK_EC 0x00000003UL
  ------------------
 6403|    201|		if (!mt)
  ------------------
  |  Branch (6403:7): [True: 0, False: 201]
  ------------------
 6404|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6405|    201|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6406|    201|		sc_pkcs11_free_mechanism(&mt);
 6407|    201|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    201|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6407:7): [True: 0, False: 201]
  ------------------
 6408|      0|			return rc;
 6409|    201|	}
 6410|       |
 6411|  1.96k|	return CKR_OK;
  ------------------
  |  | 1086|  1.96k|#define CKR_OK 0x00000000UL
  ------------------
 6412|  1.96k|}
framework-pkcs15.c:register_eddsa_mechanisms:
 6416|    104|{
 6417|    104|	CK_MECHANISM_INFO mech_info;
 6418|    104|	sc_pkcs11_mechanism_type_t *mt;
 6419|    104|	CK_RV rc;
 6420|       |
 6421|    104|	mech_info.flags = CKF_HW | CKF_SIGN;
  ------------------
  |  |  352|    104|#define CKF_HW 0x00000001UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN;
  ------------------
  |  |  363|    104|#define CKF_SIGN 0x00000800UL
  ------------------
 6422|    104|	mech_info.ulMinKeySize = min_key_size;
 6423|    104|	mech_info.ulMaxKeySize = max_key_size;
 6424|       |
 6425|    104|#ifdef ENABLE_OPENSSL
 6426|       |	/* TODO verification using EDDSA
 6427|       |	mech_info.flags |= CKF_VERIFY;
 6428|       |	*/
 6429|    104|#endif
 6430|    104|	if (flags & SC_ALGORITHM_EDDSA_RAW) {
  ------------------
  |  |  188|    104|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  |  Branch (6430:6): [True: 104, False: 0]
  ------------------
 6431|    104|		mt = sc_pkcs11_new_fw_mechanism(CKM_EDDSA, &mech_info, CKK_EC_EDWARDS, NULL, NULL, NULL);
  ------------------
  |  |  990|    104|#define CKM_EDDSA 0x00001057UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_EDDSA, &mech_info, CKK_EC_EDWARDS, NULL, NULL, NULL);
  ------------------
  |  |  518|    104|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
 6432|    104|		if (!mt)
  ------------------
  |  Branch (6432:7): [True: 0, False: 104]
  ------------------
 6433|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6434|    104|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6435|    104|		sc_pkcs11_free_mechanism(&mt);
 6436|    104|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6436:7): [True: 0, False: 104]
  ------------------
 6437|      0|			return rc;
 6438|    104|	}
 6439|       |
 6440|    104|	if (flags & SC_ALGORITHM_ONBOARD_KEY_GEN) {
  ------------------
  |  |   93|    104|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  |  Branch (6440:6): [True: 2, False: 102]
  ------------------
 6441|      2|		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  352|      2|#define CKF_HW 0x00000001UL
  ------------------
              		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  368|      2|#define CKF_GENERATE_KEY_PAIR 0x00010000UL
  ------------------
 6442|      2|		mt = sc_pkcs11_new_fw_mechanism(CKM_EC_EDWARDS_KEY_PAIR_GEN,
  ------------------
  |  |  988|      2|#define CKM_EC_EDWARDS_KEY_PAIR_GEN 0x00001055UL
  ------------------
 6443|      2|			&mech_info, CKK_EC_EDWARDS, NULL, NULL, NULL);
  ------------------
  |  |  518|      2|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
 6444|      2|		if (!mt)
  ------------------
  |  Branch (6444:7): [True: 0, False: 2]
  ------------------
 6445|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6446|      2|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6447|      2|		sc_pkcs11_free_mechanism(&mt);
 6448|      2|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      2|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6448:7): [True: 0, False: 2]
  ------------------
 6449|      0|			return rc;
 6450|      2|	}
 6451|       |
 6452|    104|	return CKR_OK;
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
 6453|    104|}
framework-pkcs15.c:register_xeddsa_mechanisms:
 6457|    104|{
 6458|    104|	CK_MECHANISM_INFO mech_info;
 6459|    104|	sc_pkcs11_mechanism_type_t *mt;
 6460|    104|	CK_RV rc;
 6461|       |
 6462|    104|	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DERIVE;
  ------------------
  |  |  352|    104|#define CKF_HW 0x00000001UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DERIVE;
  ------------------
  |  |  363|    104|#define CKF_SIGN 0x00000800UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DERIVE;
  ------------------
  |  |  371|    104|#define CKF_DERIVE 0x00080000UL
  ------------------
 6463|    104|	mech_info.ulMinKeySize = min_key_size;
 6464|    104|	mech_info.ulMaxKeySize = max_key_size;
 6465|       |
 6466|    104|	if (flags & SC_ALGORITHM_XEDDSA_RAW) {
  ------------------
  |  |  189|    104|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
  |  Branch (6466:6): [True: 102, False: 2]
  ------------------
 6467|    102|		mt = sc_pkcs11_new_fw_mechanism(CKM_XEDDSA, &mech_info, CKK_EC_MONTGOMERY, NULL, NULL, NULL);
  ------------------
  |  |  979|    102|#define CKM_XEDDSA 0x00004029UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_XEDDSA, &mech_info, CKK_EC_MONTGOMERY, NULL, NULL, NULL);
  ------------------
  |  |  519|    102|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
 6468|    102|		if (!mt)
  ------------------
  |  Branch (6468:7): [True: 0, False: 102]
  ------------------
 6469|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6470|    102|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6471|    102|		sc_pkcs11_free_mechanism(&mt);
 6472|    102|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    102|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6472:7): [True: 0, False: 102]
  ------------------
 6473|      0|			return rc;
 6474|    102|	}
 6475|       |
 6476|       |	/* ADD ECDH mechanisms */
 6477|    104|	if (flags & SC_ALGORITHM_ECDH_CDH_RAW) {
  ------------------
  |  |  173|    104|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  |  Branch (6477:6): [True: 104, False: 0]
  ------------------
 6478|    104|		mech_info.flags &= ~CKF_SIGN;
  ------------------
  |  |  363|    104|#define CKF_SIGN 0x00000800UL
  ------------------
 6479|    104|		mech_info.flags |= CKF_DERIVE;
  ------------------
  |  |  371|    104|#define CKF_DERIVE 0x00080000UL
  ------------------
 6480|       |
 6481|       |		/* Montgomery curves derive function is defined only for CKM_ECDH1_DERIVE mechanism */
 6482|    104|		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDH1_DERIVE, &mech_info, CKK_EC_MONTGOMERY, NULL, NULL, NULL);
  ------------------
  |  |  867|    104|#define CKM_ECDH1_DERIVE 0x00001050UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_ECDH1_DERIVE, &mech_info, CKK_EC_MONTGOMERY, NULL, NULL, NULL);
  ------------------
  |  |  519|    104|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
 6483|    104|		if (!mt)
  ------------------
  |  Branch (6483:7): [True: 0, False: 104]
  ------------------
 6484|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6485|    104|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6486|    104|		sc_pkcs11_free_mechanism(&mt);
 6487|    104|		if (rc != CKR_OK)
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6487:7): [True: 0, False: 104]
  ------------------
 6488|      0|			return rc;
 6489|    104|	}
 6490|       |
 6491|    104|	if (flags & SC_ALGORITHM_ONBOARD_KEY_GEN) {
  ------------------
  |  |   93|    104|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  |  Branch (6491:6): [True: 2, False: 102]
  ------------------
 6492|      2|		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  352|      2|#define CKF_HW 0x00000001UL
  ------------------
              		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  368|      2|#define CKF_GENERATE_KEY_PAIR 0x00010000UL
  ------------------
 6493|      2|		mt = sc_pkcs11_new_fw_mechanism(CKM_EC_MONTGOMERY_KEY_PAIR_GEN, &mech_info, CKK_EC_MONTGOMERY, NULL, NULL, NULL);
  ------------------
  |  |  989|      2|#define CKM_EC_MONTGOMERY_KEY_PAIR_GEN 0x00001056UL
  ------------------
              		mt = sc_pkcs11_new_fw_mechanism(CKM_EC_MONTGOMERY_KEY_PAIR_GEN, &mech_info, CKK_EC_MONTGOMERY, NULL, NULL, NULL);
  ------------------
  |  |  519|      2|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
 6494|      2|		if (!mt)
  ------------------
  |  Branch (6494:7): [True: 0, False: 2]
  ------------------
 6495|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6496|      2|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6497|      2|		sc_pkcs11_free_mechanism(&mt);
 6498|      2|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      2|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6498:7): [True: 0, False: 2]
  ------------------
 6499|      0|			return rc;
 6500|      2|	}
 6501|       |
 6502|    104|	return CKR_OK;
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
 6503|    104|}
framework-pkcs15.c:register_gost_mechanisms:
 6186|      8|{
 6187|      8|	CK_MECHANISM_INFO mech_info;
 6188|      8|	sc_pkcs11_mechanism_type_t *mt;
 6189|      8|	CK_RV rc;
 6190|       |
 6191|      8|	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DECRYPT;
  ------------------
  |  |  352|      8|#define CKF_HW 0x00000001UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DECRYPT;
  ------------------
  |  |  363|      8|#define CKF_SIGN 0x00000800UL
  ------------------
              	mech_info.flags = CKF_HW | CKF_SIGN | CKF_DECRYPT;
  ------------------
  |  |  361|      8|#define CKF_DECRYPT 0x00000200UL
  ------------------
 6192|      8|#ifdef ENABLE_OPENSSL
 6193|       |	/* That practise definitely conflicts with CKF_HW -- andre 2010-11-28 */
 6194|      8|	mech_info.flags |= CKF_VERIFY;
  ------------------
  |  |  365|      8|#define CKF_VERIFY 0x00002000UL
  ------------------
 6195|      8|#endif
 6196|      8|	mech_info.ulMinKeySize = SC_PKCS15_GOSTR3410_KEYSIZE;
  ------------------
  |  |  326|      8|#define SC_PKCS15_GOSTR3410_KEYSIZE             256
  ------------------
 6197|      8|	mech_info.ulMaxKeySize = SC_PKCS15_GOSTR3410_KEYSIZE;
  ------------------
  |  |  326|      8|#define SC_PKCS15_GOSTR3410_KEYSIZE             256
  ------------------
 6198|       |
 6199|      8|	if (flags & SC_ALGORITHM_GOSTR3410_HASH_NONE) {
  ------------------
  |  |  157|      8|#define SC_ALGORITHM_GOSTR3410_HASH_NONE	SC_ALGORITHM_GOSTR3410_RAW /*XXX*/
  |  |  ------------------
  |  |  |  |  156|      8|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  |  |  ------------------
  ------------------
  |  Branch (6199:6): [True: 8, False: 0]
  ------------------
 6200|      8|		mt = sc_pkcs11_new_fw_mechanism(CKM_GOSTR3410,
  ------------------
  |  |  909|      8|#define CKM_GOSTR3410 0x00001201UL
  ------------------
 6201|      8|				&mech_info, CKK_GOSTR3410, NULL, NULL, NULL);
  ------------------
  |  |  502|      8|#define CKK_GOSTR3410 0x00000030UL
  ------------------
 6202|      8|		if (!mt)
  ------------------
  |  Branch (6202:7): [True: 0, False: 8]
  ------------------
 6203|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6204|      8|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6205|      8|		sc_pkcs11_free_mechanism(&mt);
 6206|      8|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6206:7): [True: 0, False: 8]
  ------------------
 6207|      0|			return rc;
 6208|      8|	}
 6209|      8|	if (flags & SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411) {
  ------------------
  |  |  158|      8|#define SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411	0x00080000
  ------------------
  |  Branch (6209:6): [True: 0, False: 8]
  ------------------
 6210|      0|		mt = sc_pkcs11_new_fw_mechanism(CKM_GOSTR3410_WITH_GOSTR3411,
  ------------------
  |  |  910|      0|#define CKM_GOSTR3410_WITH_GOSTR3411 0x00001202UL
  ------------------
 6211|      0|				&mech_info, CKK_GOSTR3410, NULL, NULL, NULL);
  ------------------
  |  |  502|      0|#define CKK_GOSTR3410 0x00000030UL
  ------------------
 6212|      0|		if (!mt)
  ------------------
  |  Branch (6212:7): [True: 0, False: 0]
  ------------------
 6213|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6214|      0|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6215|      0|		sc_pkcs11_free_mechanism(&mt);
 6216|      0|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6216:7): [True: 0, False: 0]
  ------------------
 6217|      0|			return rc;
 6218|      0|	}
 6219|      8|	if (flags & SC_ALGORITHM_ONBOARD_KEY_GEN) {
  ------------------
  |  |   93|      8|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  |  Branch (6219:6): [True: 8, False: 0]
  ------------------
 6220|      8|		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  352|      8|#define CKF_HW 0x00000001UL
  ------------------
              		mech_info.flags = CKF_HW | CKF_GENERATE_KEY_PAIR;
  ------------------
  |  |  368|      8|#define CKF_GENERATE_KEY_PAIR 0x00010000UL
  ------------------
 6221|      8|		mt = sc_pkcs11_new_fw_mechanism(CKM_GOSTR3410_KEY_PAIR_GEN,
  ------------------
  |  |  908|      8|#define CKM_GOSTR3410_KEY_PAIR_GEN 0x00001200UL
  ------------------
 6222|      8|				&mech_info, CKK_GOSTR3410, NULL, NULL, NULL);
  ------------------
  |  |  502|      8|#define CKK_GOSTR3410 0x00000030UL
  ------------------
 6223|      8|		if (!mt)
  ------------------
  |  Branch (6223:7): [True: 0, False: 8]
  ------------------
 6224|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6225|      8|		rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6226|      8|		sc_pkcs11_free_mechanism(&mt);
 6227|      8|		if (rc != CKR_OK)
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6227:7): [True: 0, False: 8]
  ------------------
 6228|      0|			return rc;
 6229|      8|	}
 6230|       |
 6231|      8|	return CKR_OK;
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
 6232|      8|}
framework-pkcs15.c:sc_pkcs11_register_aes_mechanisms:
 6507|      5|{
 6508|      5|	CK_RV rc;
 6509|      5|	CK_MECHANISM_INFO mech_info;
 6510|      5|	sc_pkcs11_mechanism_type_t *mt;
 6511|      5|	sc_card_t* card = p11card->card;
 6512|      5|	memset(&mech_info, 0, sizeof(mech_info));
 6513|      5|	mech_info.flags = CKF_ENCRYPT | CKF_DECRYPT;
  ------------------
  |  |  360|      5|#define CKF_ENCRYPT 0x00000100UL
  ------------------
              	mech_info.flags = CKF_ENCRYPT | CKF_DECRYPT;
  ------------------
  |  |  361|      5|#define CKF_DECRYPT 0x00000200UL
  ------------------
 6514|      5|	mech_info.ulMinKeySize = min_key_size;
 6515|      5|	mech_info.ulMaxKeySize = max_key_size;
 6516|       |
 6517|      5|	if ((card->caps & SC_CARD_CAP_UNWRAP_KEY) == SC_CARD_CAP_UNWRAP_KEY)
  ------------------
  |  |  574|      5|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
              	if ((card->caps & SC_CARD_CAP_UNWRAP_KEY) == SC_CARD_CAP_UNWRAP_KEY)
  ------------------
  |  |  574|      5|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
  |  Branch (6517:6): [True: 3, False: 2]
  ------------------
 6518|      3|		mech_info.flags |= CKF_UNWRAP;
  ------------------
  |  |  370|      3|#define CKF_UNWRAP 0x00040000UL
  ------------------
 6519|      5|	if ((card->caps & SC_CARD_CAP_WRAP_KEY) == SC_CARD_CAP_WRAP_KEY)
  ------------------
  |  |  572|      5|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
              	if ((card->caps & SC_CARD_CAP_WRAP_KEY) == SC_CARD_CAP_WRAP_KEY)
  ------------------
  |  |  572|      5|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
  |  Branch (6519:6): [True: 3, False: 2]
  ------------------
 6520|      3|		mech_info.flags |= CKF_WRAP;
  ------------------
  |  |  369|      3|#define CKF_WRAP 0x00020000UL
  ------------------
 6521|       |
 6522|      5|	mt = sc_pkcs11_new_fw_mechanism(CKM_AES_ECB, &mech_info, CKK_AES, NULL, NULL, NULL);
  ------------------
  |  |  882|      5|#define CKM_AES_ECB 0x00001081UL
  ------------------
              	mt = sc_pkcs11_new_fw_mechanism(CKM_AES_ECB, &mech_info, CKK_AES, NULL, NULL, NULL);
  ------------------
  |  |  485|      5|#define CKK_AES 0x0000001FUL
  ------------------
 6523|      5|	if (!mt)
  ------------------
  |  Branch (6523:6): [True: 0, False: 5]
  ------------------
 6524|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6525|      5|	rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6526|      5|	sc_pkcs11_free_mechanism(&mt);
 6527|      5|	if (rc != CKR_OK)
  ------------------
  |  | 1086|      5|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6527:6): [True: 0, False: 5]
  ------------------
 6528|      0|			return rc;
 6529|       |
 6530|      5|	mt = sc_pkcs11_new_fw_mechanism(CKM_AES_CBC, &mech_info, CKK_AES, NULL, NULL, NULL);
  ------------------
  |  |  883|      5|#define CKM_AES_CBC 0x00001082UL
  ------------------
              	mt = sc_pkcs11_new_fw_mechanism(CKM_AES_CBC, &mech_info, CKK_AES, NULL, NULL, NULL);
  ------------------
  |  |  485|      5|#define CKK_AES 0x0000001FUL
  ------------------
 6531|      5|	if (!mt)
  ------------------
  |  Branch (6531:6): [True: 0, False: 5]
  ------------------
 6532|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6533|      5|	rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6534|      5|	sc_pkcs11_free_mechanism(&mt);
 6535|      5|	if (rc != CKR_OK)
  ------------------
  |  | 1086|      5|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6535:6): [True: 0, False: 5]
  ------------------
 6536|      0|			return rc;
 6537|       |
 6538|      5|	mt = sc_pkcs11_new_fw_mechanism(CKM_AES_CBC_PAD, &mech_info, CKK_AES, NULL, NULL, NULL);
  ------------------
  |  |  886|      5|#define CKM_AES_CBC_PAD 0x00001085UL
  ------------------
              	mt = sc_pkcs11_new_fw_mechanism(CKM_AES_CBC_PAD, &mech_info, CKK_AES, NULL, NULL, NULL);
  ------------------
  |  |  485|      5|#define CKK_AES 0x0000001FUL
  ------------------
 6539|      5|	if (!mt)
  ------------------
  |  Branch (6539:6): [True: 0, False: 5]
  ------------------
 6540|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 6541|      5|	rc = sc_pkcs11_register_mechanism(p11card, mt, NULL);
 6542|      5|	sc_pkcs11_free_mechanism(&mt);
 6543|      5|	if (rc != CKR_OK)
  ------------------
  |  | 1086|      5|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (6543:6): [True: 0, False: 5]
  ------------------
 6544|      0|			return rc;
 6545|       |
 6546|      5|	return CKR_OK;
  ------------------
  |  | 1086|      5|#define CKR_OK 0x00000000UL
  ------------------
 6547|      5|}
framework-pkcs15.c:pkcs15_unbind:
  368|  12.7k|{
  369|  12.7k|	unsigned int i, idx;
  370|  12.7k|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|  12.7k|#define SC_SUCCESS				0
  ------------------
  371|       |
  372|  12.7k|	if (!p11card)
  ------------------
  |  Branch (372:6): [True: 0, False: 12.7k]
  ------------------
  373|      0|		return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  374|  27.7k|	for (idx=0; p11card && idx<SC_PKCS11_FRAMEWORK_DATA_MAX_NUM; idx++)   {
  ------------------
  |  |  194|  27.7k|#define SC_PKCS11_FRAMEWORK_DATA_MAX_NUM	4
  ------------------
  |  Branch (374:14): [True: 27.7k, False: 0]
  |  Branch (374:25): [True: 27.2k, False: 429]
  ------------------
  375|  27.2k|		struct pkcs15_fw_data *fw_data = (struct pkcs15_fw_data *) p11card->fws_data[idx];
  376|       |
  377|  27.2k|		if (!fw_data)
  ------------------
  |  Branch (377:7): [True: 12.3k, False: 14.9k]
  ------------------
  378|  12.3k|			break;
  379|  44.9k|		for (i = 0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (379:15): [True: 29.9k, False: 14.9k]
  ------------------
  380|  29.9k|			struct pkcs15_any_object *obj = fw_data->objects[i];
  381|       |
  382|       |			/* use object specific release method if existing */
  383|  29.9k|			if (obj->base.ops && obj->base.ops->release)
  ------------------
  |  Branch (383:8): [True: 29.9k, False: 0]
  |  Branch (383:25): [True: 29.9k, False: 0]
  ------------------
  384|  29.9k|				obj->base.ops->release(obj);
  385|      0|			else
  386|      0|				__pkcs15_release_object(obj);
  387|  29.9k|		}
  388|       |
  389|  14.9k|		unlock_card(fw_data);
  390|       |
  391|  14.9k|		if (fw_data->p15_card) {
  ------------------
  |  Branch (391:7): [True: 5.57k, False: 9.40k]
  ------------------
  392|  5.57k|			rv = sc_pkcs15_unbind(fw_data->p15_card);
  393|  5.57k|		}
  394|  14.9k|		fw_data->p15_card = NULL;
  395|       |
  396|  14.9k|		free(fw_data);
  397|  14.9k|		p11card->fws_data[idx] = NULL;
  398|  14.9k|	}
  399|       |
  400|       |	return sc_to_cryptoki_error(rv, NULL);
  401|  12.7k|}
framework-pkcs15.c:__pkcs15_release_object:
  510|  56.8k|{
  511|  56.8k|	if (--(obj->refcount) != 0)
  ------------------
  |  Branch (511:6): [True: 26.8k, False: 29.9k]
  ------------------
  512|  26.8k|		return obj->refcount;
  513|       |
  514|  29.9k|	sc_mem_clear(obj, obj->size);
  515|  29.9k|	free(obj);
  516|       |
  517|  29.9k|	return 0;
  518|  56.8k|}
framework-pkcs15.c:unlock_card:
 6860|  14.9k|{
 6861|  14.9k|	while (fw_data->locked) {
  ------------------
  |  Branch (6861:9): [True: 0, False: 14.9k]
  ------------------
 6862|      0|		sc_unlock(fw_data->p15_card->card);
 6863|      0|		fw_data->locked--;
 6864|      0|	}
 6865|  14.9k|	return 0;
 6866|  14.9k|}
framework-pkcs15.c:pkcs15_create_tokens:
 1637|  10.7k|{
 1638|  10.7k|	struct pkcs15_fw_data *fw_data = NULL;
 1639|  10.7k|	struct sc_pkcs15_object *auth_user_pin = NULL, *auth_sign_pin = NULL;
 1640|  10.7k|	struct sc_pkcs11_slot *slot = NULL, *sign_slot = NULL;
 1641|  10.7k|	unsigned int cs_flags = sc_pkcs11_conf.create_slots_flags;
 1642|  10.7k|	CK_RV rv;
 1643|  10.7k|	int rc, i, idx;
 1644|  10.7k|	scconf_block *conf_block = NULL;
 1645|  10.7k|	char *user_pin = NULL, *sign_pin = NULL;
 1646|       |
 1647|  10.7k|	if (p11card) {
  ------------------
  |  Branch (1647:6): [True: 10.7k, False: 0]
  ------------------
 1648|  10.7k|		sc_log(context, "create PKCS#15 tokens; fws:%p,%p,%p", p11card->fws_data[0], p11card->fws_data[1], p11card->fws_data[2]);
  ------------------
  |  |   71|  10.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1649|  10.7k|	}
 1650|  10.7k|	sc_log(context, "create slots flags 0x%X", cs_flags);
  ------------------
  |  |   71|  10.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1651|       |
 1652|  10.7k|	if (p11card) {
  ------------------
  |  Branch (1652:6): [True: 10.7k, False: 0]
  ------------------
 1653|  10.7k|		p11card->num_slots = 0;
 1654|  10.7k|	}
 1655|       |
 1656|       |	/* Find out framework data corresponding to the given application */
 1657|  10.7k|	fw_data = get_fw_data(p11card, app_info, &idx);
 1658|  10.7k|	if (!fw_data)   {
  ------------------
  |  Branch (1658:6): [True: 5.19k, False: 5.52k]
  ------------------
 1659|  5.19k|		if (p11card) {
  ------------------
  |  Branch (1659:7): [True: 5.19k, False: 0]
  ------------------
 1660|  5.19k|			sc_log(context, "Create slot for the non-binded card");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1661|  5.19k|			pkcs15_create_slot(p11card, NULL, NULL, app_info, &slot);
 1662|  5.19k|		}
 1663|  5.19k|		return CKR_OK;
  ------------------
  |  | 1086|  5.19k|#define CKR_OK 0x00000000UL
  ------------------
 1664|  5.19k|	}
 1665|  5.52k|	sc_log(context, "Use FW data with index %i; fw_data->p15_card %p", idx, fw_data->p15_card);
  ------------------
  |  |   71|  5.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1666|       |
 1667|  5.52k|	conf_block = sc_get_conf_block(p11card->card->ctx, "framework", "pkcs15", 1);
 1668|  5.52k|	if (conf_block && app_info)   {
  ------------------
  |  Branch (1668:6): [True: 0, False: 5.52k]
  |  Branch (1668:20): [True: 0, False: 0]
  ------------------
 1669|      0|		scconf_block **blocks = NULL;
 1670|      0|		char str_path[SC_MAX_AID_STRING_SIZE];
 1671|       |
 1672|      0|		memset(str_path, 0, sizeof(str_path));
 1673|      0|		sc_bin_to_hex(app_info->path.value, app_info->path.len, str_path, sizeof(str_path), 0);
 1674|      0|		blocks = scconf_find_blocks(p11card->card->ctx->conf, conf_block, "application", str_path);
 1675|      0|		if (blocks)   {
  ------------------
  |  Branch (1675:7): [True: 0, False: 0]
  ------------------
 1676|      0|			if (blocks[0]) {
  ------------------
  |  Branch (1676:8): [True: 0, False: 0]
  ------------------
 1677|      0|				user_pin = (char *)scconf_get_str(blocks[0], "user_pin", NULL);
 1678|      0|				sign_pin = (char *)scconf_get_str(blocks[0], "sign_pin", NULL);
 1679|      0|			}
 1680|      0|			free(blocks);
 1681|      0|		}
 1682|      0|	}
 1683|       |
 1684|       |	/* Try to identify UserPIN and SignPIN by their symbolic name */
 1685|  5.52k|	auth_user_pin = _get_auth_object_by_name(fw_data->p15_card, "UserPIN", user_pin);
 1686|  5.52k|	if (cs_flags & SC_PKCS11_SLOT_FOR_PIN_SIGN)
  ------------------
  |  |   45|  5.52k|#define SC_PKCS11_SLOT_FOR_PIN_SIGN	2
  ------------------
  |  Branch (1686:6): [True: 0, False: 5.52k]
  ------------------
 1687|      0|		auth_sign_pin = _get_auth_object_by_name(fw_data->p15_card, "SignPIN", sign_pin);
 1688|  5.52k|	sc_log(context, "Flags:0x%X; Auth User/Sign PINs %p/%p", cs_flags, auth_user_pin, auth_sign_pin);
  ------------------
  |  |   71|  5.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1689|       |
 1690|       |	/* Add PKCS#15 objects of the known types to the framework data */
 1691|  5.52k|	rc = _pkcs15_create_typed_objects(fw_data);
 1692|  5.52k|	if (rc < 0)
  ------------------
  |  Branch (1692:6): [True: 0, False: 5.52k]
  ------------------
 1693|      0|		return sc_to_cryptoki_error(rc, NULL);
 1694|  5.52k|	sc_log(context, "Found %d FW objects objects", fw_data->num_objects);
  ------------------
  |  |   71|  5.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1695|       |
 1696|       |	/* Create slots for all non-unblock, non-so PINs if:
 1697|       |	 *  - 'UserPIN' cannot be identified (VT: for some cards with incomplete PIN flags);
 1698|       |	 *  - configuration impose to create slot for all PINs.
 1699|       |	 */
 1700|  5.52k|	if (!auth_user_pin || cs_flags & SC_PKCS11_SLOT_CREATE_ALL)   {
  ------------------
  |  |   46|  3.83k|#define SC_PKCS11_SLOT_CREATE_ALL	8
  ------------------
  |  Branch (1700:6): [True: 1.69k, False: 3.83k]
  |  Branch (1700:24): [True: 3.83k, False: 0]
  ------------------
 1701|  5.52k|		struct sc_pkcs15_object *auths[MAX_OBJECTS];
 1702|  5.52k|		int auth_count;
 1703|       |
 1704|  5.52k|		memset(auths, 0, sizeof(auths));
 1705|       |		/* Get authentication PKCS#15 objects present in the associated on-card application */
 1706|  5.52k|		rc = sc_pkcs15_get_objects(fw_data->p15_card, SC_PKCS15_TYPE_AUTH_PIN, auths, SC_PKCS15_MAX_PINS);
  ------------------
  |  |  445|  5.52k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
              		rc = sc_pkcs15_get_objects(fw_data->p15_card, SC_PKCS15_TYPE_AUTH_PIN, auths, SC_PKCS15_MAX_PINS);
  ------------------
  |  |   34|  5.52k|#define SC_PKCS15_MAX_PINS		8
  ------------------
 1707|  5.52k|		if (rc < 0)
  ------------------
  |  Branch (1707:7): [True: 0, False: 5.52k]
  ------------------
 1708|      0|			return sc_to_cryptoki_error(rc, NULL);
 1709|  5.52k|		auth_count = rc;
 1710|  5.52k|		sc_log(context, "Found %d authentication objects", auth_count);
  ------------------
  |  |   71|  5.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1711|       |
 1712|  11.0k|		for (i = 0; i < auth_count; i++) {
  ------------------
  |  Branch (1712:15): [True: 5.54k, False: 5.52k]
  ------------------
 1713|  5.54k|			struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *)auths[i]->data;
 1714|  5.54k|			if (!_is_slot_auth_object(pin_info))
  ------------------
  |  Branch (1714:8): [True: 1.62k, False: 3.92k]
  ------------------
 1715|  1.62k|				continue;
 1716|  3.92k|			p11card->num_slots++;
 1717|  3.92k|		}
 1718|       |
 1719|  10.9k|		for (i = 0; i < auth_count; i++) {
  ------------------
  |  Branch (1719:15): [True: 5.51k, False: 5.41k]
  ------------------
 1720|  5.51k|			struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info*)auths[i]->data;
 1721|  5.51k|			struct sc_pkcs11_slot *islot = NULL;
 1722|       |
 1723|       |			/* Check if a slot could be created with this PIN */
 1724|  5.51k|			if (!_is_slot_auth_object(pin_info))
  ------------------
  |  Branch (1724:8): [True: 1.59k, False: 3.92k]
  ------------------
 1725|  1.59k|				continue;
 1726|  3.92k|			sc_log(context, "Found authentication object '%.*s'", (int) sizeof auths[i]->label, auths[i]->label);
  ------------------
  |  |   71|  3.92k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1727|       |
 1728|  3.92k|			rv = pkcs15_create_slot(p11card, fw_data, auths[i], app_info, &islot);
 1729|  3.92k|			if (rv != CKR_OK)
  ------------------
  |  | 1086|  3.92k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1729:8): [True: 109, False: 3.81k]
  ------------------
 1730|    109|				return CKR_OK; /* no more slots available for this card */
  ------------------
  |  | 1086|    109|#define CKR_OK 0x00000000UL
  ------------------
 1731|  3.81k|			islot->fw_data_idx = idx;
 1732|  3.81k|			_add_pin_related_objects(islot, auths[i], fw_data, NULL);
 1733|       |
 1734|       |			/* Get slot to which the public objects will be associated */
 1735|  3.81k|			if (!slot && !auth_user_pin)
  ------------------
  |  Branch (1735:8): [True: 3.81k, False: 0]
  |  Branch (1735:17): [True: 44, False: 3.76k]
  ------------------
 1736|     44|				slot = islot;
 1737|  3.76k|			else if (!slot && auth_user_pin && auth_user_pin == auths[i])
  ------------------
  |  Branch (1737:13): [True: 3.76k, False: 0]
  |  Branch (1737:22): [True: 3.76k, False: 0]
  |  Branch (1737:39): [True: 3.76k, False: 3]
  ------------------
 1738|  3.76k|				slot = islot;
 1739|  3.81k|		}
 1740|  5.52k|	}
 1741|      0|	else   {
 1742|      0|		if (auth_user_pin && (cs_flags & SC_PKCS11_SLOT_FOR_PIN_USER))
  ------------------
  |  |   44|      0|#define SC_PKCS11_SLOT_FOR_PIN_USER	1
  ------------------
  |  Branch (1742:7): [True: 0, False: 0]
  |  Branch (1742:24): [True: 0, False: 0]
  ------------------
 1743|      0|			p11card->num_slots++;
 1744|      0|		if (auth_sign_pin && (cs_flags & SC_PKCS11_SLOT_FOR_PIN_SIGN))
  ------------------
  |  |   45|      0|#define SC_PKCS11_SLOT_FOR_PIN_SIGN	2
  ------------------
  |  Branch (1744:7): [True: 0, False: 0]
  |  Branch (1744:24): [True: 0, False: 0]
  ------------------
 1745|      0|			p11card->num_slots++;
 1746|      0|		sc_log(context, "User/Sign PINs %p/%p", auth_user_pin, auth_sign_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__
  |  |  ------------------
  ------------------
 1747|      0|		if (auth_user_pin && (cs_flags & SC_PKCS11_SLOT_FOR_PIN_USER)) {
  ------------------
  |  |   44|      0|#define SC_PKCS11_SLOT_FOR_PIN_USER	1
  ------------------
  |  Branch (1747:7): [True: 0, False: 0]
  |  Branch (1747:24): [True: 0, False: 0]
  ------------------
 1748|       |			/* For the UserPIN of the first slot create slot */
 1749|      0|			sc_log(context, "Create slot for User PIN '%.*s'", (int) sizeof auth_user_pin->label, auth_user_pin->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__
  |  |  ------------------
  ------------------
 1750|      0|			rv = pkcs15_create_slot(p11card, fw_data, auth_user_pin, app_info, &slot);
 1751|      0|			if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1751:8): [True: 0, False: 0]
  ------------------
 1752|      0|				return CKR_OK; /* no more slots available for this card */
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 1753|      0|			slot->fw_data_idx = idx;
 1754|      0|			_add_pin_related_objects(slot, auth_user_pin, fw_data, NULL);
 1755|      0|		}
 1756|       |
 1757|      0|		if (auth_sign_pin && (cs_flags & SC_PKCS11_SLOT_FOR_PIN_SIGN))   {
  ------------------
  |  |   45|      0|#define SC_PKCS11_SLOT_FOR_PIN_SIGN	2
  ------------------
  |  Branch (1757:7): [True: 0, False: 0]
  |  Branch (1757:24): [True: 0, False: 0]
  ------------------
 1758|       |			/* Only Sign PIN slot needs to be exposed */
 1759|      0|			sc_log(context, "Create slot for Sign PIN '%.*s'", (int) sizeof auth_sign_pin->label, auth_sign_pin->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__
  |  |  ------------------
  ------------------
 1760|      0|			rv = pkcs15_create_slot(p11card, fw_data, auth_sign_pin, app_info, &sign_slot);
 1761|      0|			if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1761:8): [True: 0, False: 0]
  ------------------
 1762|      0|				return CKR_OK; /* no more slots available for this card */
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 1763|      0|			sign_slot->fw_data_idx = idx;
 1764|      0|			_add_pin_related_objects(sign_slot, auth_sign_pin, fw_data, NULL);
 1765|      0|		}
 1766|       |
 1767|      0|		if (!slot && sign_slot)
  ------------------
  |  Branch (1767:7): [True: 0, False: 0]
  |  Branch (1767:16): [True: 0, False: 0]
  ------------------
 1768|      0|			slot = sign_slot;
 1769|      0|	}
 1770|       |
 1771|  5.41k|	if (!slot && (cs_flags == SC_PKCS11_SLOT_CREATE_ALL))   {
  ------------------
  |  |   46|  1.65k|#define SC_PKCS11_SLOT_CREATE_ALL	8
  ------------------
  |  Branch (1771:6): [True: 1.65k, False: 3.76k]
  |  Branch (1771:15): [True: 1.65k, False: 0]
  ------------------
 1772|  1.65k|		sc_log(context, "Now create slot without AUTH object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1773|  1.65k|		pkcs15_create_slot(p11card, fw_data, NULL, app_info, &slot);
 1774|  1.65k|		sc_log(context, "Created slot without AUTH object: %p", slot);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1775|  1.65k|	}
 1776|       |
 1777|  5.41k|	if (slot)   {
  ------------------
  |  Branch (1777:6): [True: 5.13k, False: 278]
  ------------------
 1778|  5.13k|		sc_log(context, "Add public objects to slot %p", slot);
  ------------------
  |  |   71|  5.13k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1779|  5.13k|		_add_public_objects(slot, fw_data);
 1780|  5.13k|	}
 1781|       |
 1782|  5.41k|	sc_log(context, "All tokens created");
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1783|  5.41k|	return CKR_OK;
  ------------------
  |  | 1086|  5.41k|#define CKR_OK 0x00000000UL
  ------------------
 1784|  5.52k|}
framework-pkcs15.c:get_fw_data:
  288|  10.7k|{
  289|  10.7k|	struct pkcs15_fw_data *out = NULL;
  290|  10.7k|	int idx;
  291|       |
  292|  10.7k|	if (!p11card)
  ------------------
  |  Branch (292:6): [True: 0, False: 10.7k]
  ------------------
  293|      0|		return NULL;
  294|  31.6k|	for (idx=0; p11card && idx < SC_PKCS11_FRAMEWORK_DATA_MAX_NUM; idx++)   {
  ------------------
  |  |  194|  31.6k|#define SC_PKCS11_FRAMEWORK_DATA_MAX_NUM	4
  ------------------
  |  Branch (294:14): [True: 31.6k, False: 0]
  |  Branch (294:25): [True: 26.4k, False: 5.19k]
  ------------------
  295|  26.4k|		struct pkcs15_fw_data *fw_data = (struct pkcs15_fw_data *) p11card->fws_data[idx];
  296|  26.4k|		struct sc_file *file_app = NULL;
  297|       |
  298|  26.4k|		if (!fw_data || !fw_data->p15_card)
  ------------------
  |  Branch (298:7): [True: 15.5k, False: 10.8k]
  |  Branch (298:19): [True: 5.23k, False: 5.64k]
  ------------------
  299|  20.7k|			continue;
  300|       |
  301|  5.64k|		file_app = fw_data->p15_card->file_app;
  302|  5.64k|		if (app_info && file_app)   {
  ------------------
  |  Branch (302:7): [True: 695, False: 4.94k]
  |  Branch (302:19): [True: 167, False: 528]
  ------------------
  303|    167|			if (file_app->path.len != app_info->path.len)
  ------------------
  |  Branch (303:8): [True: 83, False: 84]
  ------------------
  304|     83|				continue;
  305|     84|			if (file_app->path.aid.len != app_info->path.aid.len)
  ------------------
  |  Branch (305:8): [True: 0, False: 84]
  ------------------
  306|      0|				continue;
  307|     84|			if (memcmp(file_app->path.aid.value, app_info->path.aid.value, app_info->path.aid.len))
  ------------------
  |  Branch (307:8): [True: 0, False: 84]
  ------------------
  308|      0|				continue;
  309|     84|			if (memcmp(file_app->path.value, app_info->path.value, app_info->path.len))
  ------------------
  |  Branch (309:8): [True: 32, False: 52]
  ------------------
  310|     32|				continue;
  311|     84|		}
  312|       |
  313|  5.52k|		out = fw_data;
  314|  5.52k|		if (out_idx)
  ------------------
  |  Branch (314:7): [True: 5.52k, False: 0]
  ------------------
  315|  5.52k|			*out_idx = idx;
  316|  5.52k|		break;
  317|  5.64k|	}
  318|       |
  319|  10.7k|	return out;
  320|  10.7k|}
framework-pkcs15.c:pkcs15_create_slot:
 1252|  10.7k|{
 1253|  10.7k|	struct sc_pkcs11_slot *slot = NULL;
 1254|  10.7k|	CK_RV rv;
 1255|       |
 1256|  10.7k|	rv = slot_allocate(&slot, p11card);
 1257|  10.7k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  10.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1257:6): [True: 407, False: 10.3k]
  ------------------
 1258|    407|		return rv;
 1259|       |
 1260|       |	/* There's a token in this slot */
 1261|  10.3k|	slot->slot_info.flags |= CKF_TOKEN_PRESENT;
  ------------------
  |  |  407|  10.3k|#define CKF_TOKEN_PRESENT 0x00000001UL
  ------------------
 1262|       |
 1263|       |	/* Fill in the slot/token info from pkcs15 data */
 1264|  10.3k|	if (fw_data)
  ------------------
  |  Branch (1264:6): [True: 5.18k, False: 5.17k]
  ------------------
 1265|  5.18k|		pkcs15_init_slot(fw_data->p15_card, slot, auth, app_info);
 1266|  5.17k|	else {
 1267|       |		/* Token is not initialized, announce pinpad capability nevertheless */
 1268|  5.17k|		if (slot->reader->capabilities & SC_READER_CAP_PIN_PAD)
  ------------------
  |  |  376|  5.17k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1268:7): [True: 0, False: 5.17k]
  ------------------
 1269|      0|			slot->token_info.flags |= CKF_PROTECTED_AUTHENTICATION_PATH;
  ------------------
  |  |  418|      0|#define CKF_PROTECTED_AUTHENTICATION_PATH 0x00000100UL
  ------------------
 1270|  5.17k|	}
 1271|       |
 1272|  10.3k|	*out = slot;
 1273|  10.3k|	return CKR_OK;
  ------------------
  |  | 1086|  10.3k|#define CKR_OK 0x00000000UL
  ------------------
 1274|  10.7k|}
framework-pkcs15.c:pkcs15_init_slot:
 1140|  5.18k|{
 1141|  5.18k|	struct pkcs15_slot_data *fw_data;
 1142|  5.18k|	struct sc_pkcs15_auth_info *pin_info = NULL;
 1143|  5.18k|	int write_protected;
 1144|  5.18k|	scconf_block *atrblock;
 1145|       |
 1146|  5.18k|	sc_log(context, "Called");
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1147|  5.18k|	pkcs15_init_token_info(p15card, &slot->token_info);
 1148|  5.18k|	slot->token_info.flags |= CKF_TOKEN_INITIALIZED;
  ------------------
  |  |  420|  5.18k|#define CKF_TOKEN_INITIALIZED 0x00000400UL
  ------------------
 1149|  5.18k|	if (auth != NULL)
  ------------------
  |  Branch (1149:6): [True: 3.81k, False: 1.37k]
  ------------------
 1150|  3.81k|		slot->token_info.flags |= CKF_USER_PIN_INITIALIZED;
  ------------------
  |  |  415|  3.81k|#define CKF_USER_PIN_INITIALIZED 0x00000008UL
  ------------------
 1151|       |
 1152|  5.18k|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD) || (p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  376|  5.18k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
              	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD) || (p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  560|  5.18k|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (1152:6): [True: 0, False: 5.18k]
  |  Branch (1152:71): [True: 0, False: 5.18k]
  ------------------
 1153|      0|		slot->token_info.flags |= CKF_PROTECTED_AUTHENTICATION_PATH;
  ------------------
  |  |  418|      0|#define CKF_PROTECTED_AUTHENTICATION_PATH 0x00000100UL
  ------------------
 1154|       |
 1155|  5.18k|	if (p15card->card->caps & SC_CARD_CAP_RNG && p15card->card->ops->get_challenge != NULL)
  ------------------
  |  |  550|  10.3k|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  |  Branch (1155:6): [True: 3.55k, False: 1.63k]
  |  Branch (1155:47): [True: 3.55k, False: 0]
  ------------------
 1156|  3.55k|		slot->token_info.flags |= CKF_RNG;
  ------------------
  |  |  412|  3.55k|#define CKF_RNG 0x00000001UL
  ------------------
 1157|       |
 1158|  5.18k|	if (p15card->tokeninfo && p15card->tokeninfo->flags & SC_PKCS15_TOKEN_READONLY) {
  ------------------
  |  |  595|  5.18k|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  |  Branch (1158:6): [True: 5.18k, False: 0]
  |  Branch (1158:28): [True: 177, False: 5.00k]
  ------------------
 1159|    177|		write_protected = 1;
 1160|  5.00k|	} else {
 1161|  5.00k|		write_protected = 0;
 1162|  5.00k|	}
 1163|  5.18k|	atrblock = _sc_match_atr_block(p15card->card->ctx, NULL, &p15card->card->atr);
 1164|  5.18k|	if (atrblock) {
  ------------------
  |  Branch (1164:6): [True: 0, False: 5.18k]
  ------------------
 1165|      0|		write_protected = scconf_get_bool(atrblock, "read_only", write_protected);
 1166|      0|	}
 1167|  5.18k|	if (write_protected) {
  ------------------
  |  Branch (1167:6): [True: 177, False: 5.00k]
  ------------------
 1168|    177|		slot->token_info.flags |= CKF_WRITE_PROTECTED;
  ------------------
  |  |  413|    177|#define CKF_WRITE_PROTECTED 0x00000002UL
  ------------------
 1169|    177|	}
 1170|       |
 1171|  5.18k|	slot->fw_data = fw_data = calloc(1, sizeof(*fw_data));
 1172|  5.18k|	if (!fw_data) {
  ------------------
  |  Branch (1172:6): [True: 0, False: 5.18k]
  ------------------
 1173|      0|		return;
 1174|      0|	}
 1175|  5.18k|	fw_data->auth_obj = auth;
 1176|       |
 1177|  5.18k|	if (auth != NULL) {
  ------------------
  |  Branch (1177:6): [True: 3.81k, False: 1.37k]
  ------------------
 1178|  3.81k|		pin_info = (struct sc_pkcs15_auth_info*) auth->data;
 1179|       |
 1180|  3.81k|		if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|  3.81k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1180:7): [True: 0, False: 3.81k]
  ------------------
 1181|      0|			pin_info = NULL;
 1182|      0|		}
 1183|  3.81k|		else   {
 1184|  3.81k|			size_t pin_len = 0;
 1185|  3.81k|			if (auth->label[0] && strncmp(auth->label, "PIN", 4) != 0)
  ------------------
  |  Branch (1185:8): [True: 3.81k, False: 0]
  |  Branch (1185:26): [True: 973, False: 2.83k]
  ------------------
 1186|    973|				pin_len = strlen(auth->label);
 1187|  3.81k|			if (pin_len && get_num_slots(p15card->card) > 1) {
  ------------------
  |  Branch (1187:8): [True: 973, False: 2.83k]
  |  Branch (1187:19): [True: 39, False: 934]
  ------------------
 1188|     39|				size_t tokeninfo_len = 0;
 1189|     39|				if (p15card->tokeninfo && p15card->tokeninfo->label)
  ------------------
  |  Branch (1189:9): [True: 39, False: 0]
  |  Branch (1189:31): [True: 36, False: 3]
  ------------------
 1190|     36|					tokeninfo_len = strlen(p15card->tokeninfo->label);
 1191|       |				/* Print the possibly truncated token label with at least 4
 1192|       |				 * characters followed by the PIN label in parenthesis */
 1193|     39|				if (tokeninfo_len == 0
  ------------------
  |  Branch (1193:9): [True: 3, False: 36]
  ------------------
 1194|     36|						|| pin_len + strlen("L... ()") > 32) {
  ------------------
  |  Branch (1194:10): [True: 0, False: 36]
  ------------------
 1195|       |					/* There is no token label or it doesn't fit,
 1196|       |					 * print only PIN label */
 1197|      3|					strcpy_bp(slot->token_info.label, auth->label, 32);
 1198|     36|				} else {
 1199|     36|					size_t max_tokeninfo_len = MIN(tokeninfo_len,
  ------------------
  |  |   70|     36|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 36, False: 0]
  |  |  ------------------
  ------------------
 1200|     36|							32 - pin_len - strlen(" ()"));
 1201|     36|					strcpy_bp(slot->token_info.label,
 1202|     36|							p15card->tokeninfo->label,
 1203|     36|							max_tokeninfo_len);
 1204|     36|					slot->token_info.label[max_tokeninfo_len]           = ' ';
 1205|     36|					slot->token_info.label[max_tokeninfo_len+1]         = '(';
 1206|     36|					strcpy_bp(slot->token_info.label+max_tokeninfo_len+2,
 1207|     36|							auth->label, pin_len);
 1208|     36|					strcpy_bp(slot->token_info.label+max_tokeninfo_len+2+pin_len,
 1209|     36|							")", 32 - max_tokeninfo_len-2-pin_len);
 1210|     36|				}
 1211|  3.77k|			} else {
 1212|       |				/* PIN label is empty or just says useless "PIN",
 1213|       |				 * print only token label */
 1214|  3.77k|				strcpy_bp(slot->token_info.label,
 1215|  3.77k|						p15card->tokeninfo ? p15card->tokeninfo->label : "",
  ------------------
  |  Branch (1215:7): [True: 3.77k, False: 0]
  ------------------
 1216|  3.77k|						32);
 1217|  3.77k|			}
 1218|       |			/* Some applications (NSS) do not like the colons in the
 1219|       |			 * TOKEN_INFO label so replace them here */
 1220|   125k|			for (int i = 0; i < 32; i++) {
  ------------------
  |  Branch (1220:20): [True: 121k, False: 3.81k]
  ------------------
 1221|   121k|				if (slot->token_info.label[i] == ':') {
  ------------------
  |  Branch (1221:9): [True: 10, False: 121k]
  ------------------
 1222|     10|					slot->token_info.label[i] = '.';
 1223|     10|				}
 1224|   121k|			}
 1225|  3.81k|			slot->token_info.flags |= CKF_LOGIN_REQUIRED;
  ------------------
  |  |  414|  3.81k|#define CKF_LOGIN_REQUIRED 0x00000004UL
  ------------------
 1226|  3.81k|		}
 1227|  3.81k|	}
 1228|       |
 1229|  5.18k|	if (pin_info) {
  ------------------
  |  Branch (1229:6): [True: 3.81k, False: 1.37k]
  ------------------
 1230|  3.81k|		slot->token_info.ulMaxPinLen = pin_info->attrs.pin.max_length;
 1231|  3.81k|		slot->token_info.ulMinPinLen = pin_info->attrs.pin.min_length;
 1232|  3.81k|	}
 1233|  1.37k|	else {
 1234|       |		/* choose reasonable defaults */
 1235|  1.37k|		slot->token_info.ulMaxPinLen = 8;
 1236|  1.37k|		slot->token_info.ulMinPinLen = 4;
 1237|  1.37k|		strcpy_bp(slot->token_info.label,
 1238|  1.37k|				p15card->tokeninfo ? p15card->tokeninfo->label : "",
  ------------------
  |  Branch (1238:5): [True: 1.37k, False: 0]
  ------------------
 1239|  1.37k|				32);
 1240|  1.37k|	}
 1241|       |
 1242|  5.18k|	slot->app_info = app_info;
 1243|  5.18k|	sc_log(context, "Initialized slot 0x%lx with token %*s", slot->id,
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1244|  5.18k|			(int)sizeof(slot->token_info.label), slot->token_info.label);
 1245|  5.18k|}
framework-pkcs15.c:pkcs15_init_token_info:
  406|  5.18k|{
  407|  5.18k|	scconf_block *conf_block = NULL;
  408|  5.18k|	char *model = NULL;
  409|       |
  410|  5.18k|	conf_block = sc_get_conf_block(p15card->card->ctx, "framework", "pkcs15", 1);
  411|  5.18k|	if (conf_block && p15card->file_app)   {
  ------------------
  |  Branch (411:6): [True: 0, False: 5.18k]
  |  Branch (411:20): [True: 0, False: 0]
  ------------------
  412|      0|		scconf_block **blocks = NULL;
  413|      0|		char str_path[SC_MAX_AID_STRING_SIZE];
  414|       |
  415|      0|		memset(str_path, 0, sizeof(str_path));
  416|      0|		sc_bin_to_hex(p15card->file_app->path.value, p15card->file_app->path.len, str_path, sizeof(str_path), 0);
  417|      0|		blocks = scconf_find_blocks(p15card->card->ctx->conf, conf_block, "application", str_path);
  418|      0|		if (blocks)   {
  ------------------
  |  Branch (418:7): [True: 0, False: 0]
  ------------------
  419|      0|			if (blocks[0])
  ------------------
  |  Branch (419:8): [True: 0, False: 0]
  ------------------
  420|      0|				model = (char *)scconf_get_str(blocks[0], "model", NULL);
  421|      0|			free(blocks);
  422|      0|		}
  423|      0|	}
  424|       |
  425|  5.18k|	if (model)
  ------------------
  |  Branch (425:6): [True: 0, False: 5.18k]
  ------------------
  426|      0|		strcpy_bp(pToken->model, model, sizeof(pToken->model));
  427|  5.18k|	else if (sc_card_ctl(p15card->card, SC_CARDCTL_GET_MODEL, &model) == SC_SUCCESS)
  ------------------
  |  |   28|  5.18k|#define SC_SUCCESS				0
  ------------------
  |  Branch (427:11): [True: 4, False: 5.18k]
  ------------------
  428|      4|		strcpy_bp(pToken->model, model, sizeof(pToken->model));
  429|  5.18k|	else if (p15card->flags & SC_PKCS15_CARD_FLAG_EMULATED)
  ------------------
  |  |  601|  5.18k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  |  Branch (429:11): [True: 5.02k, False: 152]
  ------------------
  430|  5.02k|		strcpy_bp(pToken->model, "PKCS#15 emulated", sizeof(pToken->model));
  431|    152|	else
  432|    152|		strcpy_bp(pToken->model, "PKCS#15", sizeof(pToken->model));
  433|       |
  434|  5.18k|	if (p15card->tokeninfo) {
  ------------------
  |  Branch (434:6): [True: 5.18k, False: 0]
  ------------------
  435|  5.18k|		strcpy_bp(pToken->manufacturerID, p15card->tokeninfo->manufacturer_id, 32);
  436|       |
  437|       |		/* Take the last 16 chars of the serial number (if the are more than 16).
  438|       |		 * _Assuming_ that the serial number is a Big Endian counter, this
  439|       |		 * will assure that the serial within each type of card will be
  440|       |		 * unique in pkcs11 (at least for the first 8^16 cards :-) */
  441|  5.18k|		if (p15card->tokeninfo->serial_number != NULL) {
  ------------------
  |  Branch (441:7): [True: 3.67k, False: 1.50k]
  ------------------
  442|  3.67k|			size_t sn_start = strlen(p15card->tokeninfo->serial_number);
  443|       |
  444|  3.67k|			if (sn_start <= 16)
  ------------------
  |  Branch (444:8): [True: 2.72k, False: 956]
  ------------------
  445|  2.72k|				sn_start = 0;
  446|    956|			else
  447|    956|				sn_start -= 16;
  448|       |
  449|  3.67k|			strcpy_bp(pToken->serialNumber, p15card->tokeninfo->serial_number + sn_start, 16);
  450|  3.67k|		}
  451|  5.18k|	}
  452|       |
  453|  5.18k|	pToken->ulMaxSessionCount = CK_EFFECTIVELY_INFINITE;
  ------------------
  |  |   31|  5.18k|#define CK_EFFECTIVELY_INFINITE 0UL
  ------------------
  454|  5.18k|	pToken->ulSessionCount = 0; /* FIXME */
  455|  5.18k|	pToken->ulMaxRwSessionCount = CK_EFFECTIVELY_INFINITE;
  ------------------
  |  |   31|  5.18k|#define CK_EFFECTIVELY_INFINITE 0UL
  ------------------
  456|  5.18k|	pToken->ulRwSessionCount = 0; /* FIXME */
  457|  5.18k|	pToken->ulTotalPublicMemory = CK_UNAVAILABLE_INFORMATION;
  ------------------
  |  |   32|  5.18k|#define CK_UNAVAILABLE_INFORMATION ~0UL
  ------------------
  458|  5.18k|	pToken->ulFreePublicMemory = CK_UNAVAILABLE_INFORMATION;
  ------------------
  |  |   32|  5.18k|#define CK_UNAVAILABLE_INFORMATION ~0UL
  ------------------
  459|  5.18k|	pToken->ulTotalPrivateMemory = CK_UNAVAILABLE_INFORMATION;
  ------------------
  |  |   32|  5.18k|#define CK_UNAVAILABLE_INFORMATION ~0UL
  ------------------
  460|  5.18k|	pToken->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION;
  ------------------
  |  |   32|  5.18k|#define CK_UNAVAILABLE_INFORMATION ~0UL
  ------------------
  461|  5.18k|	pToken->hardwareVersion.major = p15card->card->version.hw_major;
  462|  5.18k|	pToken->hardwareVersion.minor = p15card->card->version.hw_minor;
  463|  5.18k|	pToken->firmwareVersion.major = p15card->card->version.fw_major;
  464|  5.18k|	pToken->firmwareVersion.minor = p15card->card->version.fw_minor;
  465|  5.18k|}
framework-pkcs15.c:get_num_slots:
 1127|    973|{
 1128|    973|	unsigned int i;
 1129|    973|	for (i = 0; i < list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (1129:14): [True: 973, False: 0]
  ------------------
 1130|    973|		sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *)list_get_at(&virtual_slots, i);
 1131|    973|		if (slot && slot->p11card && slot->p11card->card == card)
  ------------------
  |  Branch (1131:7): [True: 973, False: 0]
  |  Branch (1131:15): [True: 973, False: 0]
  |  Branch (1131:32): [True: 973, False: 0]
  ------------------
 1132|    973|			return slot->p11card->num_slots;
 1133|    973|	}
 1134|      0|	return 0;
 1135|    973|}
framework-pkcs15.c:_pkcs15_create_typed_objects:
 1279|  5.52k|{
 1280|  5.52k|	int rv;
 1281|       |
 1282|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PRKEY_RSA, "RSA private key",
  ------------------
  |  |  419|  5.52k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
 1283|  5.52k|			__pkcs15_create_prkey_object);
 1284|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1284:6): [True: 0, False: 5.52k]
  ------------------
 1285|      0|		return rv;
 1286|       |
 1287|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PUBKEY_RSA, "RSA public key",
  ------------------
  |  |  426|  5.52k|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
 1288|  5.52k|			__pkcs15_create_pubkey_object);
 1289|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1289:6): [True: 0, False: 5.52k]
  ------------------
 1290|      0|		return rv;
 1291|       |
 1292|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PRKEY_EC, "EC private key",
  ------------------
  |  |  421|  5.52k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
 1293|  5.52k|			__pkcs15_create_prkey_object);
 1294|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1294:6): [True: 0, False: 5.52k]
  ------------------
 1295|      0|		return rv;
 1296|       |
 1297|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PUBKEY_EC, "EC public key",
  ------------------
  |  |  428|  5.52k|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
 1298|  5.52k|			__pkcs15_create_pubkey_object);
 1299|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1299:6): [True: 0, False: 5.52k]
  ------------------
 1300|      0|		return rv;
 1301|       |
 1302|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PRKEY_EDDSA, "EdDSA private key",
  ------------------
  |  |  422|  5.52k|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
 1303|  5.52k|			__pkcs15_create_prkey_object);
 1304|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1304:6): [True: 0, False: 5.52k]
  ------------------
 1305|      0|		return rv;
 1306|       |
 1307|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PUBKEY_EDDSA, "EdDSA public key",
  ------------------
  |  |  429|  5.52k|#define SC_PKCS15_TYPE_PUBKEY_EDDSA		0x205
  ------------------
 1308|  5.52k|			__pkcs15_create_pubkey_object);
 1309|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1309:6): [True: 0, False: 5.52k]
  ------------------
 1310|      0|		return rv;
 1311|       |
 1312|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PRKEY_XEDDSA, "XEdDSA private key",
  ------------------
  |  |  423|  5.52k|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
 1313|  5.52k|			__pkcs15_create_prkey_object);
 1314|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1314:6): [True: 0, False: 5.52k]
  ------------------
 1315|      0|		return rv;
 1316|       |
 1317|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PUBKEY_XEDDSA, "XEdDSA public key",
  ------------------
  |  |  430|  5.52k|#define SC_PKCS15_TYPE_PUBKEY_XEDDSA		0x206
  ------------------
 1318|  5.52k|			__pkcs15_create_pubkey_object);
 1319|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1319:6): [True: 0, False: 5.52k]
  ------------------
 1320|      0|		return rv;
 1321|       |
 1322|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PRKEY_GOSTR3410, "GOSTR3410 private key",
  ------------------
  |  |  420|  5.52k|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
 1323|  5.52k|			__pkcs15_create_prkey_object);
 1324|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1324:6): [True: 0, False: 5.52k]
  ------------------
 1325|      0|		return rv;
 1326|       |
 1327|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_PUBKEY_GOSTR3410, "GOSTR3410 public key",
  ------------------
  |  |  427|  5.52k|#define SC_PKCS15_TYPE_PUBKEY_GOSTR3410		0x203
  ------------------
 1328|  5.52k|			__pkcs15_create_pubkey_object);
 1329|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1329:6): [True: 0, False: 5.52k]
  ------------------
 1330|      0|		return rv;
 1331|       |
 1332|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_CERT_X509, "certificate",
  ------------------
  |  |  439|  5.52k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
 1333|  5.52k|			__pkcs15_create_cert_object);
 1334|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1334:6): [True: 0, False: 5.52k]
  ------------------
 1335|      0|		return rv;
 1336|       |
 1337|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_DATA_OBJECT, "data object",
  ------------------
  |  |  442|  5.52k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
 1338|  5.52k|			__pkcs15_create_data_object);
 1339|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1339:6): [True: 0, False: 5.52k]
  ------------------
 1340|      0|		return rv;
 1341|       |
 1342|  5.52k|	rv = pkcs15_create_pkcs11_objects(fw_data, SC_PKCS15_TYPE_SKEY_GENERIC, "Generic secret key",
  ------------------
  |  |  433|  5.52k|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
 1343|  5.52k|			__pkcs15_create_secret_key_object);
 1344|  5.52k|	if (rv < 0)
  ------------------
  |  Branch (1344:6): [True: 0, False: 5.52k]
  ------------------
 1345|      0|		return rv;
 1346|       |
 1347|       |	/* Match up related keys and certificates */
 1348|  5.52k|	pkcs15_bind_related_objects(fw_data);
 1349|  5.52k|	sc_log(context, "found %i FW objects", fw_data->num_objects);
  ------------------
  |  |   71|  5.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1350|       |
 1351|  5.52k|	return rv;
 1352|  5.52k|}
framework-pkcs15.c:pkcs15_create_pkcs11_objects:
  897|  71.8k|{
  898|  71.8k|	struct sc_pkcs15_object *p15_object[MAX_OBJECTS];
  899|  71.8k|	int i, count, rv;
  900|       |
  901|  71.8k|	rv = count = sc_pkcs15_get_objects(fw_data->p15_card, p15_type, p15_object, MAX_OBJECTS);
  ------------------
  |  |   66|  71.8k|#define MAX_OBJECTS	128
  ------------------
  902|  71.8k|	if (rv >= 0)
  ------------------
  |  Branch (902:6): [True: 71.8k, False: 0]
  ------------------
  903|  71.8k|		sc_log(context, "Found %d %s%s", count, name, (count == 1)? "" : "s");
  ------------------
  |  |   71|   143k|#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: 1.75k, False: 70.0k]
  |  |  ------------------
  ------------------
  904|       |
  905|  97.1k|	for (i = 0; rv >= 0 && i < count; i++)
  ------------------
  |  Branch (905:14): [True: 96.3k, False: 785]
  |  Branch (905:25): [True: 25.2k, False: 71.0k]
  ------------------
  906|  25.2k|		rv = create(fw_data, p15_object[i], NULL);
  907|       |
  908|  71.8k|	return count;
  909|  71.8k|}
framework-pkcs15.c:__pkcs15_create_prkey_object:
  800|  3.40k|{
  801|  3.40k|	struct pkcs15_any_object *any_object = NULL;
  802|  3.40k|	struct pkcs15_prkey_object *object = NULL;
  803|  3.40k|	int rv;
  804|       |
  805|  3.40k|	rv = __pkcs15_create_object(fw_data, &any_object,
  806|  3.40k|			prkey, &pkcs15_prkey_ops, sizeof(struct pkcs15_prkey_object));
  807|  3.40k|	object = (struct pkcs15_prkey_object *) any_object;
  808|  3.40k|	if (rv >= 0)
  ------------------
  |  Branch (808:6): [True: 3.40k, False: 0]
  ------------------
  809|  3.40k|		object->prv_info = (struct sc_pkcs15_prkey_info *) prkey->data;
  810|       |
  811|  3.40k|	if (prkey_object != NULL)
  ------------------
  |  Branch (811:6): [True: 0, False: 3.40k]
  ------------------
  812|      0|		*prkey_object = any_object;
  813|       |
  814|  3.40k|	return rv;
  815|  3.40k|}
framework-pkcs15.c:__pkcs15_create_object:
  488|  29.9k|{
  489|  29.9k|	struct pkcs15_any_object *obj;
  490|       |
  491|  29.9k|	if (fw_data->num_objects >= MAX_OBJECTS)
  ------------------
  |  |   66|  29.9k|#define MAX_OBJECTS	128
  ------------------
  |  Branch (491:6): [True: 0, False: 29.9k]
  ------------------
  492|      0|		return SC_ERROR_TOO_MANY_OBJECTS;
  ------------------
  |  |   86|      0|#define SC_ERROR_TOO_MANY_OBJECTS		-1405
  ------------------
  493|       |
  494|  29.9k|	if (!(obj = calloc(1, size)))
  ------------------
  |  Branch (494:6): [True: 0, False: 29.9k]
  ------------------
  495|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  496|       |
  497|  29.9k|	fw_data->objects[fw_data->num_objects++] = obj;
  498|       |
  499|  29.9k|	obj->base.ops = ops;
  500|  29.9k|	obj->p15_object = p15_object;
  501|  29.9k|	obj->refcount = 1;
  502|  29.9k|	obj->size = size;
  503|       |
  504|  29.9k|	*result = obj;
  505|  29.9k|	return SC_SUCCESS;
  ------------------
  |  |   28|  29.9k|#define SC_SUCCESS				0
  ------------------
  506|  29.9k|}
framework-pkcs15.c:__pkcs15_create_pubkey_object:
  745|  1.10k|{
  746|  1.10k|	struct pkcs15_any_object *any_object = NULL;
  747|  1.10k|	struct pkcs15_pubkey_object *object = NULL;
  748|  1.10k|	struct sc_pkcs15_pubkey *p15_key = NULL;
  749|  1.10k|	int rv;
  750|       |
  751|       |	/* Read public key from card */
  752|       |	/* Attempt to read pubkey from card or file.
  753|       |	 * During initialization process, the key may have been created
  754|       |	 * and saved as a file before the certificate has been created.
  755|       |	 */
  756|  1.10k|	if (pubkey->flags & SC_PKCS15_CO_FLAG_PRIVATE)   {	/* is the key private? */
  ------------------
  |  |   50|  1.10k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (756:6): [True: 32, False: 1.07k]
  ------------------
  757|     32|		sc_log(context, "No pubkey");
  ------------------
  |  |   71|     32|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  758|     32|		p15_key = NULL;					/* will read key when needed */
  759|     32|	}
  760|  1.07k|	else {
  761|       |		/* if emulation already created pubkey use it */
  762|  1.07k|		if (pubkey->emulated && (fw_data->p15_card->flags & SC_PKCS15_CARD_FLAG_EMULATED)) {
  ------------------
  |  |  601|  1.01k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  |  Branch (762:7): [True: 1.01k, False: 56]
  |  Branch (762:27): [True: 1.01k, False: 0]
  ------------------
  763|  1.01k|			sc_log(context, "Use emulated pubkey");
  ------------------
  |  |   71|  1.01k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  764|  1.01k|			sc_pkcs15_dup_pubkey(context, (struct sc_pkcs15_pubkey *) pubkey->emulated, &p15_key);
  765|  1.01k|		}
  766|     56|		else {
  767|     56|			sc_log(context, "Get pubkey from PKCS#15 object");
  ------------------
  |  |   71|     56|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  768|     56|			rv = sc_pkcs15_read_pubkey(fw_data->p15_card, pubkey, &p15_key);
  769|     56|			if (rv < 0)
  ------------------
  |  Branch (769:8): [True: 55, False: 1]
  ------------------
  770|     55|				 p15_key = NULL;
  771|     56|		}
  772|  1.07k|	}
  773|       |
  774|       |	/* Public key object */
  775|  1.10k|	rv = __pkcs15_create_object(fw_data, &any_object,
  776|  1.10k|			pubkey, &pkcs15_pubkey_ops, sizeof(struct pkcs15_pubkey_object));
  777|  1.10k|	object = (struct pkcs15_pubkey_object *) any_object;
  778|  1.10k|	if (rv >= 0) {
  ------------------
  |  Branch (778:6): [True: 1.10k, False: 0]
  ------------------
  779|  1.10k|		object->pub_info = (struct sc_pkcs15_pubkey_info *) pubkey->data;
  780|  1.10k|		object->pub_data = p15_key;
  781|  1.10k|		if (p15_key && object->pub_info->modulus_length == 0 && p15_key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    956|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (781:7): [True: 1.01k, False: 89]
  |  Branch (781:18): [True: 956, False: 60]
  |  Branch (781:59): [True: 1, False: 955]
  ------------------
  782|      1|			object->pub_info->modulus_length = 8 * p15_key->u.rsa.modulus.len;
  783|  1.10k|	} else {
  784|      0|		sc_pkcs15_free_pubkey(p15_key);
  785|      0|	}
  786|  1.10k|	if (object && object->pub_data) {
  ------------------
  |  Branch (786:6): [True: 1.10k, False: 0]
  |  Branch (786:16): [True: 1.01k, False: 89]
  ------------------
  787|  1.01k|		if ((object->pub_data->alg_id)&&(object->pub_data->algorithm == SC_ALGORITHM_GOSTR3410))
  ------------------
  |  |   71|  1.01k|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (787:7): [True: 1.01k, False: 1]
  |  Branch (787:35): [True: 0, False: 1.01k]
  ------------------
  788|      0|			object->pub_data->alg_id->params = &((object->pub_data->u).gostr3410.params);
  789|  1.01k|	}
  790|  1.10k|	if (pubkey_object != NULL)
  ------------------
  |  Branch (790:6): [True: 0, False: 1.10k]
  ------------------
  791|      0|		*pubkey_object = any_object;
  792|       |
  793|  1.10k|	return rv;
  794|  1.10k|}
framework-pkcs15.c:__pkcs15_create_cert_object:
  679|  2.04k|{
  680|  2.04k|	struct sc_pkcs15_cert_info *p15_info = NULL;
  681|  2.04k|	struct sc_pkcs15_cert *p15_cert = NULL;
  682|  2.04k|	struct pkcs15_any_object *any_object = NULL;
  683|  2.04k|	struct pkcs15_cert_object *object = NULL;
  684|  2.04k|	struct pkcs15_pubkey_object *obj2 = NULL;
  685|  2.04k|	struct pkcs15_any_object *any_object2 = NULL;
  686|  2.04k|	int rv;
  687|       |
  688|  2.04k|	p15_info = (struct sc_pkcs15_cert_info *) cert->data;
  689|       |
  690|  2.04k|	if (cert->flags & SC_PKCS15_CO_FLAG_PRIVATE)  {	/* is the cert private? */
  ------------------
  |  |   50|  2.04k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (690:6): [True: 205, False: 1.83k]
  ------------------
  691|    205|		p15_cert = NULL;			/* will read cert when needed */
  692|    205|	}
  693|  1.83k|	else    {
  694|  1.83k|		rv = sc_pkcs15_read_certificate(fw_data->p15_card, p15_info, 0, &p15_cert);
  695|  1.83k|		if (rv < 0)
  ------------------
  |  Branch (695:7): [True: 785, False: 1.05k]
  ------------------
  696|    785|			return rv;
  697|  1.83k|	}
  698|       |
  699|       |	/* Certificate object */
  700|  1.25k|	rv = __pkcs15_create_object(fw_data, &any_object,
  701|  1.25k|			cert, &pkcs15_cert_ops, sizeof(struct pkcs15_cert_object));
  702|  1.25k|	object = (struct pkcs15_cert_object *) any_object;
  703|  1.25k|	if (rv < 0) {
  ------------------
  |  Branch (703:6): [True: 0, False: 1.25k]
  ------------------
  704|      0|		if (p15_cert != NULL)
  ------------------
  |  Branch (704:7): [True: 0, False: 0]
  ------------------
  705|      0|			sc_pkcs15_free_certificate(p15_cert);
  706|      0|		return rv;
  707|      0|	}
  708|       |
  709|  1.25k|	object->cert_info = p15_info;
  710|  1.25k|	object->cert_data = p15_cert;
  711|       |
  712|       |	/* Corresponding public key */
  713|  1.25k|	rv = public_key_created(fw_data, &p15_info->id, &any_object2);
  714|  1.25k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  1.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (714:6): [True: 239, False: 1.01k]
  ------------------
  715|    239|		rv = __pkcs15_create_object(fw_data, &any_object2,
  716|    239|				NULL, &pkcs15_pubkey_ops, sizeof(struct pkcs15_pubkey_object));
  717|  1.25k|	obj2 = (struct pkcs15_pubkey_object *) any_object2;
  718|  1.25k|	if (rv < 0)
  ------------------
  |  Branch (718:6): [True: 0, False: 1.25k]
  ------------------
  719|      0|		return rv;
  720|       |
  721|  1.25k|	if (p15_cert) {
  ------------------
  |  Branch (721:6): [True: 1.05k, False: 205]
  ------------------
  722|       |		 /* make a copy of public key from the cert */
  723|  1.05k|		if (!obj2->pub_data)
  ------------------
  |  Branch (723:7): [True: 36, False: 1.01k]
  ------------------
  724|     36|			rv = sc_pkcs15_pubkey_from_cert(context, &p15_cert->data, &obj2->pub_data);
  725|  1.05k|		if (rv < 0)
  ------------------
  |  Branch (725:7): [True: 0, False: 1.05k]
  ------------------
  726|      0|			return rv;
  727|  1.05k|	}
  728|       |
  729|  1.25k|	obj2->pub_genfrom = object;
  ------------------
  |  |  117|  1.25k|#define pub_genfrom		base.related_cert
  ------------------
  730|  1.25k|	object->cert_pubkey = obj2;
  ------------------
  |  |   94|  1.25k|#define cert_pubkey		base.related_pubkey
  ------------------
  731|       |
  732|       |	/* Find missing labels for certificate */
  733|  1.25k|	pkcs15_cert_extract_label(object);
  734|       |
  735|  1.25k|	if (cert_object != NULL)
  ------------------
  |  Branch (735:6): [True: 0, False: 1.25k]
  ------------------
  736|      0|		*cert_object = any_object;
  737|       |
  738|  1.25k|	return 0;
  739|  1.25k|}
framework-pkcs15.c:public_key_created:
  626|  1.25k|{
  627|  1.25k|	size_t ii;
  628|       |
  629|  20.1k|	for(ii=0; ii<fw_data->num_objects; ii++) {
  ------------------
  |  Branch (629:12): [True: 19.8k, False: 239]
  ------------------
  630|  19.8k|		struct pkcs15_any_object *any_object = fw_data->objects[ii];
  631|  19.8k|		struct sc_pkcs15_object *p15_object = any_object->p15_object;
  632|       |
  633|  19.8k|		if (!p15_object)
  ------------------
  |  Branch (633:7): [True: 378, False: 19.5k]
  ------------------
  634|    378|			continue;
  635|       |
  636|  19.5k|		if ((p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) != SC_PKCS15_TYPE_PUBKEY)
  ------------------
  |  |  416|  19.5k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              		if ((p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) != SC_PKCS15_TYPE_PUBKEY)
  ------------------
  |  |  425|  19.5k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (636:7): [True: 13.1k, False: 6.34k]
  ------------------
  637|  13.1k|			continue;
  638|       |
  639|  6.34k|		if (sc_pkcs15_compare_id(id, &((struct sc_pkcs15_pubkey_info *)p15_object->data)->id))   {
  ------------------
  |  Branch (639:7): [True: 1.01k, False: 5.33k]
  ------------------
  640|  1.01k|			if (obj2)
  ------------------
  |  Branch (640:8): [True: 1.01k, False: 0]
  ------------------
  641|  1.01k|				*obj2 = any_object;
  642|  1.01k|			return SC_SUCCESS;
  ------------------
  |  |   28|  1.01k|#define SC_SUCCESS				0
  ------------------
  643|  1.01k|		}
  644|  6.34k|	}
  645|       |
  646|    239|	return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    239|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  647|  1.25k|}
framework-pkcs15.c:pkcs15_cert_extract_label:
  651|  1.25k|{
  652|  1.25k|	if (!cert || !cert->cert_p15obj || !cert->cert_data)
  ------------------
  |  |   93|  2.51k|#define cert_p15obj		base.p15_object
  ------------------
  |  Branch (652:6): [True: 0, False: 1.25k]
  |  Branch (652:15): [True: 0, False: 1.25k]
  |  Branch (652:37): [True: 205, False: 1.05k]
  ------------------
  653|    205|		return;
  654|       |
  655|  1.05k|	sc_log(context, "pkcs15_cert_extract_label() called. Current label: %s", cert->cert_p15obj->label);
  ------------------
  |  |   71|  1.05k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  655|  1.05k|	sc_log(context, "pkcs15_cert_extract_label() called. Current label: %s", cert->cert_p15obj->label);
  |  |  |  |  ------------------
  |  |  |  |  |  |   93|  1.05k|#define cert_p15obj		base.p15_object
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  656|       |
  657|       |	/* if we didn't get a label, set one based on the CN */
  658|  1.05k|	if (*cert->cert_p15obj->label == '\0') { /* can't be NULL -- static array */
  ------------------
  |  |   93|  1.05k|#define cert_p15obj		base.p15_object
  ------------------
  |  Branch (658:6): [True: 0, False: 1.05k]
  ------------------
  659|      0|		static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  660|      0|		u8 *cn_name = NULL;
  661|      0|		size_t cn_len = 0;
  662|      0|		int rv = sc_pkcs15_get_name_from_dn(context,
  663|      0|			cert->cert_data->subject, cert->cert_data->subject_len,
  664|      0|			&cn_oid, &cn_name, &cn_len);
  665|      0|		if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (665:7): [True: 0, False: 0]
  ------------------
  666|      0|			sc_log(context, "pkcs15_cert_extract_label(): Name from DN is %.*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__
  |  |  ------------------
  ------------------
  667|      0|					(unsigned int) cn_len, cn_name);
  668|      0|			cn_len = MIN(cn_len, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  669|      0|			memcpy(cert->cert_p15obj->label, cn_name, cn_len);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
  670|      0|			cert->cert_p15obj->label[cn_len] = '\0';
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
  671|      0|		}
  672|      0|		free(cn_name);
  673|      0|	}
  674|  1.05k|}
framework-pkcs15.c:__pkcs15_create_data_object:
  821|  18.7k|{
  822|  18.7k|	struct pkcs15_any_object *any_object = NULL;
  823|  18.7k|	struct pkcs15_data_object *dobj = NULL;
  824|  18.7k|	int rv;
  825|       |
  826|  18.7k|	rv = __pkcs15_create_object(fw_data, &any_object,
  827|  18.7k|			object, &pkcs15_dobj_ops, sizeof(struct pkcs15_data_object));
  828|  18.7k|        dobj = (struct pkcs15_data_object *) any_object;
  829|  18.7k|	if (rv >= 0)   {
  ------------------
  |  Branch (829:6): [True: 18.7k, False: 0]
  ------------------
  830|  18.7k|		dobj->info = (struct sc_pkcs15_data_info *) object->data;
  831|  18.7k|		dobj->value = NULL;
  832|  18.7k|	}
  833|       |
  834|  18.7k|	if (data_object != NULL)
  ------------------
  |  Branch (834:6): [True: 0, False: 18.7k]
  ------------------
  835|      0|		*data_object = any_object;
  836|       |
  837|  18.7k|	return rv;
  838|  18.7k|}
framework-pkcs15.c:__pkcs15_create_secret_key_object:
  875|     14|{
  876|     14|	struct pkcs15_any_object *any_object = NULL;
  877|     14|	struct pkcs15_skey_object *skey = NULL;
  878|     14|	int rv;
  879|       |
  880|     14|	rv = __pkcs15_create_object(fw_data, &any_object,
  881|     14|			object, &pkcs15_skey_ops, sizeof(struct pkcs15_skey_object));
  882|     14|	skey = (struct pkcs15_skey_object *)any_object;
  883|     14|	if (rv >= 0)
  ------------------
  |  Branch (883:6): [True: 14, False: 0]
  ------------------
  884|     14|		skey->info = (struct sc_pkcs15_skey_info *)object->data;
  885|       |
  886|     14|	if (skey_object != NULL)
  ------------------
  |  Branch (886:6): [True: 14, False: 0]
  ------------------
  887|     14|		*skey_object = any_object;
  888|       |
  889|     14|	return rv;
  890|     14|}
framework-pkcs15.c:pkcs15_bind_related_objects:
 1001|  5.52k|{
 1002|  5.52k|	unsigned int i;
 1003|       |
 1004|       |	/* Loop over all private keys and attached related certificate
 1005|       |	 * and/or public key
 1006|       |	 */
 1007|  30.8k|	for (i = 0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (1007:14): [True: 25.2k, False: 5.52k]
  ------------------
 1008|  25.2k|		struct pkcs15_any_object *obj = fw_data->objects[i];
 1009|       |
 1010|  25.2k|		if (obj->base.flags & SC_PKCS11_OBJECT_HIDDEN)
  ------------------
  |  |  138|  25.2k|#define SC_PKCS11_OBJECT_HIDDEN	0x0002
  ------------------
  |  Branch (1010:7): [True: 625, False: 24.6k]
  ------------------
 1011|    625|			continue;
 1012|       |
 1013|  24.6k|		sc_log(context, "Looking for objects related to object %d", i);
  ------------------
  |  |   71|  24.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__
  |  |  ------------------
  ------------------
 1014|  24.6k|		if (is_privkey(obj))
  ------------------
  |  |  120|  24.6k|#define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  119|  24.6k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 24.6k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 24.4k, False: 239]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  416|  24.6k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  418|  24.6k|#define SC_PKCS15_TYPE_PRKEY			0x100
  |  |  ------------------
  |  |  |  Branch (120:26): [True: 2.83k, False: 21.8k]
  |  |  ------------------
  ------------------
 1015|  2.83k|			__pkcs15_prkey_bind_related(fw_data, (struct pkcs15_prkey_object *) obj);
 1016|  21.8k|		else if (is_cert(obj))
  ------------------
  |  |  122|  21.8k|#define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  119|  21.8k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 21.8k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 21.5k, False: 239]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  439|  21.8k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  |  |  ------------------
  |  |  |  Branch (122:23): [True: 1.25k, False: 20.5k]
  |  |  ------------------
  ------------------
 1017|  1.25k|			__pkcs15_cert_bind_related(fw_data, (struct pkcs15_cert_object *) obj);
 1018|  24.6k|	}
 1019|  5.52k|}
framework-pkcs15.c:__pkcs15_prkey_bind_related:
  914|  2.83k|{
  915|  2.83k|	struct sc_pkcs15_id *id = &pk->prv_info->id;
  916|  2.83k|	unsigned int i;
  917|       |
  918|  2.83k|	sc_log(context, "Object is a private key and has id %s", sc_pkcs15_print_id(id));
  ------------------
  |  |   71|  2.83k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  919|       |
  920|  76.5k|	for (i = 0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (920:14): [True: 73.7k, False: 2.83k]
  ------------------
  921|  73.7k|		struct pkcs15_any_object *obj = fw_data->objects[i];
  922|       |
  923|  73.7k|		if (obj->base.flags & SC_PKCS11_OBJECT_HIDDEN)
  ------------------
  |  |  138|  73.7k|#define SC_PKCS11_OBJECT_HIDDEN	0x0002
  ------------------
  |  Branch (923:7): [True: 990, False: 72.7k]
  ------------------
  924|    990|			continue;
  925|  72.7k|		if (is_privkey(obj) && obj != (struct pkcs15_any_object *) pk) {
  ------------------
  |  |  120|   145k|#define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  119|  72.7k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 72.7k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 72.1k, False: 644]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  416|  72.7k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  418|  72.7k|#define SC_PKCS15_TYPE_PRKEY			0x100
  |  |  ------------------
  |  |  |  Branch (120:26): [True: 17.5k, False: 55.1k]
  |  |  ------------------
  ------------------
  |  Branch (925:26): [True: 14.7k, False: 2.83k]
  ------------------
  926|       |			/* merge private keys with the same ID and
  927|       |			 * different usage bits */
  928|  14.7k|			struct pkcs15_prkey_object *other, **pp;
  929|       |
  930|  14.7k|			other = (struct pkcs15_prkey_object *) obj;
  931|  14.7k|			if (sc_pkcs15_compare_id(&other->prv_info->id, id)) {
  ------------------
  |  Branch (931:8): [True: 607, False: 14.1k]
  ------------------
  932|    607|				obj->base.flags |= SC_PKCS11_OBJECT_HIDDEN;
  ------------------
  |  |  138|    607|#define SC_PKCS11_OBJECT_HIDDEN	0x0002
  ------------------
  933|  1.34k|				for (pp = &pk->prv_next; *pp; pp = &(*pp)->prv_next)
  ------------------
  |  |  107|    607|#define prv_next		base.related_privkey
  ------------------
              				for (pp = &pk->prv_next; *pp; pp = &(*pp)->prv_next)
  ------------------
  |  |  107|    733|#define prv_next		base.related_privkey
  ------------------
  |  Branch (933:30): [True: 733, False: 607]
  ------------------
  934|    733|					;
  935|    607|				*pp = (struct pkcs15_prkey_object *) obj;
  936|    607|			}
  937|  14.7k|		}
  938|  58.0k|		else if (is_pubkey(obj) && !pk->prv_pubkey) {
  ------------------
  |  |  121|   116k|#define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  119|  58.0k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 58.0k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 57.3k, False: 644]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  416|  58.0k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  425|  58.0k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  |  |  ------------------
  |  |  |  Branch (121:25): [True: 11.5k, False: 46.4k]
  |  |  ------------------
  ------------------
              		else if (is_pubkey(obj) && !pk->prv_pubkey) {
  ------------------
  |  |  106|  11.5k|#define prv_pubkey		base.related_pubkey
  ------------------
  |  Branch (938:30): [True: 6.33k, False: 5.25k]
  ------------------
  939|  6.33k|			struct pkcs15_pubkey_object *pubkey;
  940|       |
  941|  6.33k|			pubkey = (struct pkcs15_pubkey_object *) obj;
  942|  6.33k|			if (sc_pkcs15_compare_id(&pubkey->pub_info->id, id)) {
  ------------------
  |  Branch (942:8): [True: 1.08k, False: 5.25k]
  ------------------
  943|  1.08k|				sc_log(context, "Associating object %d as public key", i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  944|  1.08k|				pk->prv_pubkey = pubkey;
  ------------------
  |  |  106|  1.08k|#define prv_pubkey		base.related_pubkey
  ------------------
  945|  1.08k|				if (pubkey->pub_data) {
  ------------------
  |  Branch (945:9): [True: 1.01k, False: 64]
  ------------------
  946|  1.01k|					sc_pkcs15_dup_pubkey(context, pubkey->pub_data, &pk->pub_data);
  947|  1.01k|					if (pk->prv_info->modulus_length == 0)
  ------------------
  |  Branch (947:10): [True: 957, False: 60]
  ------------------
  948|    957|						pk->prv_info->modulus_length = pubkey->pub_info->modulus_length;
  949|  1.01k|				}
  950|  1.08k|			}
  951|  6.33k|		}
  952|  72.7k|	}
  953|  2.83k|}
framework-pkcs15.c:__pkcs15_cert_bind_related:
  958|  1.25k|{
  959|  1.25k|	struct sc_pkcs15_cert *c1 = cert->cert_data;
  960|  1.25k|	struct sc_pkcs15_id *id = &cert->cert_info->id;
  961|  1.25k|	unsigned int i;
  962|       |
  963|  1.25k|	sc_log(context, "Object is a certificate and has id %s", sc_pkcs15_print_id(id));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  964|       |
  965|       |	/* Loop over all objects to see if we find the certificate of
  966|       |	 * the issuer and the associated private key */
  967|  64.0k|	for (i = 0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (967:14): [True: 62.9k, False: 1.11k]
  ------------------
  968|  62.9k|		struct pkcs15_any_object *obj = fw_data->objects[i];
  969|       |
  970|  62.9k|		if (is_cert(obj) && obj != (struct pkcs15_any_object *) cert) {
  ------------------
  |  |  122|   125k|#define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  119|  62.9k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 62.9k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 61.8k, False: 1.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  439|  62.9k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  |  |  ------------------
  |  |  |  Branch (122:23): [True: 11.3k, False: 51.5k]
  |  |  ------------------
  ------------------
  |  Branch (970:23): [True: 10.2k, False: 1.14k]
  ------------------
  971|  10.2k|			struct pkcs15_cert_object *cert2;
  972|  10.2k|			struct sc_pkcs15_cert *c2;
  973|       |
  974|  10.2k|			cert2 = (struct pkcs15_cert_object *) obj;
  975|  10.2k|			c2 = cert2->cert_data;
  976|       |
  977|  10.2k|			if (!c1 || !c2 || !c1->issuer_len || !c2->subject_len)
  ------------------
  |  Branch (977:8): [True: 756, False: 9.44k]
  |  Branch (977:15): [True: 0, False: 9.44k]
  |  Branch (977:22): [True: 58, False: 9.38k]
  |  Branch (977:41): [True: 0, False: 9.38k]
  ------------------
  978|    814|				continue;
  979|  9.38k|			if (c1->issuer_len == c2->subject_len
  ------------------
  |  Branch (979:8): [True: 9.22k, False: 161]
  ------------------
  980|  9.22k|			 && !memcmp(c1->issuer, c2->subject, c1->issuer_len)) {
  ------------------
  |  Branch (980:8): [True: 141, False: 9.08k]
  ------------------
  981|    141|				sc_log(context, "Associating object %d (id %s) as issuer",
  ------------------
  |  |   71|    141|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  982|    141|						i, sc_pkcs15_print_id(&cert2->cert_info->id));
  983|    141|				cert->cert_issuer = (struct pkcs15_cert_object *) obj;
  ------------------
  |  |   95|    141|#define cert_issuer		base.related_cert
  ------------------
  984|    141|				return;
  985|    141|			}
  986|  9.38k|		} else
  987|  52.7k|		if (is_privkey(obj) && !cert->cert_prvkey) {
  ------------------
  |  |  120|   105k|#define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  119|  52.7k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 52.7k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 51.6k, False: 1.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  416|  52.7k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  418|  52.7k|#define SC_PKCS15_TYPE_PRKEY			0x100
  |  |  ------------------
  |  |  |  Branch (120:26): [True: 12.4k, False: 40.3k]
  |  |  ------------------
  ------------------
              		if (is_privkey(obj) && !cert->cert_prvkey) {
  ------------------
  |  |   96|  12.4k|#define cert_prvkey		base.related_privkey
  ------------------
  |  Branch (987:26): [True: 6.92k, False: 5.52k]
  ------------------
  988|  6.92k|			struct pkcs15_prkey_object *pk;
  989|       |
  990|  6.92k|			pk = (struct pkcs15_prkey_object *) obj;
  991|  6.92k|			if (sc_pkcs15_compare_id(&pk->prv_info->id, id)) {
  ------------------
  |  Branch (991:8): [True: 1.09k, False: 5.82k]
  ------------------
  992|  1.09k|				sc_log(context, "Associating object %d as private key", i);
  ------------------
  |  |   71|  1.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  993|  1.09k|				cert->cert_prvkey = pk;
  ------------------
  |  |   96|  1.09k|#define cert_prvkey		base.related_privkey
  ------------------
  994|  1.09k|			}
  995|  6.92k|		}
  996|  62.9k|	}
  997|  1.25k|}
framework-pkcs15.c:_add_pin_related_objects:
 1531|  3.81k|{
 1532|  3.81k|	struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
 1533|  3.81k|	int public_certificates = 1;
 1534|  3.81k|	unsigned i;
 1535|       |
 1536|  3.81k|	sc_log(context, "Add objects related to PIN('%.*s',ID:%s)", (int) sizeof pin_obj->label, pin_obj->label, sc_pkcs15_print_id(&pin_info->auth_id));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1537|  27.9k|	for (i=0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (1537:12): [True: 24.1k, False: 3.81k]
  ------------------
 1538|  24.1k|		struct pkcs15_any_object *obj = fw_data->objects[i];
 1539|       |
 1540|       |		/* "Fake" objects we've generated */
 1541|  24.1k|		if (__p15_type(obj) == (unsigned int)-1)
  ------------------
  |  |  119|  24.1k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  ------------------
  |  |  |  Branch (119:28): [True: 24.1k, False: 0]
  |  |  |  Branch (119:37): [True: 23.8k, False: 239]
  |  |  ------------------
  ------------------
  |  Branch (1541:7): [True: 239, False: 23.8k]
  ------------------
 1542|    239|			continue;
 1543|       |		/* Some objects have an auth_id even though they are
 1544|       |		 * not private. Just ignore those... */
 1545|  23.8k|		if (!(obj->p15_object->flags & SC_PKCS15_CO_FLAG_PRIVATE))
  ------------------
  |  |   50|  23.8k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (1545:7): [True: 15.9k, False: 7.94k]
  ------------------
 1546|  15.9k|			continue;
 1547|  7.94k|		sc_log(context, "ObjID(%p,%.*s,%x):%s", obj, (int) sizeof obj->p15_object->label, obj->p15_object->label,
  ------------------
  |  |   71|  7.94k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1548|  7.94k|				obj->p15_object->type, sc_pkcs15_print_id(&obj->p15_object->auth_id));
 1549|  7.94k|		if (!sc_pkcs15_compare_id(&pin_info->auth_id, &obj->p15_object->auth_id))   {
  ------------------
  |  Branch (1549:7): [True: 2.20k, False: 5.74k]
  ------------------
 1550|  2.20k|			sc_log(context, "Ignoring object %d", i);
  ------------------
  |  |   71|  2.20k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1551|  2.20k|			continue;
 1552|  2.20k|		}
 1553|       |
 1554|  5.74k|		if (is_privkey(obj)) {
  ------------------
  |  |  120|  5.74k|#define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  119|  5.74k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 5.74k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 5.74k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  416|  5.74k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_privkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY)
  |  |  ------------------
  |  |  |  |  418|  5.74k|#define SC_PKCS15_TYPE_PRKEY			0x100
  |  |  ------------------
  |  |  |  Branch (120:26): [True: 2.46k, False: 3.28k]
  |  |  ------------------
  ------------------
 1555|  2.46k|			sc_log(context, "Slot:%p, obj:%p  Adding private key %d to PIN '%.*s'", slot, obj, i, (int) sizeof pin_obj->label, pin_obj->label);
  ------------------
  |  |   71|  2.46k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1556|  2.46k|			pkcs15_add_object(slot, obj, NULL);
 1557|  2.46k|		}
 1558|  3.28k|		else if (is_data(obj)) {
  ------------------
  |  |  132|  3.28k|#define is_data(obj) (__p15_type(obj) == SC_PKCS15_TYPE_DATA_OBJECT)
  |  |  ------------------
  |  |  |  |  119|  3.28k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 3.28k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 3.28k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_data(obj) (__p15_type(obj) == SC_PKCS15_TYPE_DATA_OBJECT)
  |  |  ------------------
  |  |  |  |  442|  3.28k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  |  |  ------------------
  |  |  |  Branch (132:22): [True: 3.07k, False: 205]
  |  |  ------------------
  ------------------
 1559|  3.07k|			sc_log(context, "Slot:%p Adding data object %d to PIN '%.*s'", slot, i, (int) sizeof pin_obj->label, pin_obj->label);
  ------------------
  |  |   71|  3.07k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1560|  3.07k|			pkcs15_add_object(slot, obj, NULL);
 1561|  3.07k|		}
 1562|    205|		else if (is_cert(obj)) {
  ------------------
  |  |  122|    205|#define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  119|    205|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 205, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 205, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  439|    205|#define SC_PKCS15_TYPE_CERT_X509		0x401
  |  |  ------------------
  |  |  |  Branch (122:23): [True: 205, False: 0]
  |  |  ------------------
  ------------------
 1563|    205|			sc_log(context, "Slot:%p Adding cert object %d to PIN '%.*s'", slot, i, (int) sizeof pin_obj->label, pin_obj->label);
  ------------------
  |  |   71|    205|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1564|    205|			pkcs15_add_object(slot, obj, NULL);
 1565|    205|			public_certificates = 0;
 1566|    205|		}
 1567|      0|		else if (is_skey(obj)) {
  ------------------
  |  |  147|      0|#define is_skey(obj) ((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)
  |  |  ------------------
  |  |  |  |  119|      0|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 0, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_skey(obj) ((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)
  |  |  ------------------
  |  |  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_skey(obj) ((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)
  |  |  ------------------
  |  |  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  |  |  ------------------
  |  |  |  Branch (147:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1568|      0|			sc_log(context, "Slot:%p Adding secret key object %d to PIN '%.*s'", slot, i, (int) sizeof pin_obj->label, pin_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__
  |  |  ------------------
  ------------------
 1569|      0|			pkcs15_add_object(slot, obj, NULL);
 1570|      0|		}
 1571|      0|		else   {
 1572|      0|			sc_log(context, "Slot:%p Object %d skipped", slot, 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__
  |  |  ------------------
  ------------------
 1573|      0|			continue;
 1574|      0|		}
 1575|       |
 1576|  5.74k|		if (move_to_fw && move_to_fw != fw_data && move_to_fw->num_objects < MAX_OBJECTS)   {
  ------------------
  |  |   66|      0|#define MAX_OBJECTS	128
  ------------------
  |  Branch (1576:7): [True: 0, False: 5.74k]
  |  Branch (1576:21): [True: 0, False: 0]
  |  Branch (1576:46): [True: 0, False: 0]
  ------------------
 1577|      0|			int tail = fw_data->num_objects - i - 1;
 1578|       |
 1579|      0|			move_to_fw->objects[move_to_fw->num_objects++] = obj;
 1580|      0|			if (tail)
  ------------------
  |  Branch (1580:8): [True: 0, False: 0]
  ------------------
 1581|      0|				memcpy(&fw_data->objects[i], &fw_data->objects[i + 1], sizeof(fw_data->objects[0]) * tail);
 1582|      0|			i--;
 1583|      0|			fw_data->num_objects--;
 1584|      0|		}
 1585|  5.74k|	}
 1586|  3.81k|	_add_profile_object(slot, fw_data, public_certificates);
 1587|  3.81k|}
framework-pkcs15.c:pkcs15_add_object:
 1059|  31.3k|{
 1060|  31.3k|	unsigned int i;
 1061|  31.3k|	struct pkcs15_fw_data *card_fw_data;
 1062|  31.3k|	CK_OBJECT_HANDLE handle =
 1063|  31.3k|		(CK_OBJECT_HANDLE)(uintptr_t)obj; /* cast pointer to long, will truncate on Win64 */
 1064|       |
 1065|  31.3k|	if (obj == NULL || slot == NULL)
  ------------------
  |  Branch (1065:6): [True: 2.68k, False: 28.6k]
  |  Branch (1065:21): [True: 0, False: 28.6k]
  ------------------
 1066|  2.68k|		return;
 1067|  28.6k|	if (obj->base.flags & (SC_PKCS11_OBJECT_HIDDEN | SC_PKCS11_OBJECT_RECURS))
  ------------------
  |  |  138|  28.6k|#define SC_PKCS11_OBJECT_HIDDEN	0x0002
  ------------------
              	if (obj->base.flags & (SC_PKCS11_OBJECT_HIDDEN | SC_PKCS11_OBJECT_RECURS))
  ------------------
  |  |  139|  28.6k|#define SC_PKCS11_OBJECT_RECURS	0x8000
  ------------------
  |  Branch (1067:6): [True: 581, False: 28.0k]
  ------------------
 1068|    581|		return;
 1069|       |
 1070|  28.0k|	if (list_contains(&slot->objects, obj))
  ------------------
  |  Branch (1070:6): [True: 1.23k, False: 26.8k]
  ------------------
 1071|  1.23k|		return;
 1072|       |
 1073|  26.8k|	if (pHandle != NULL)
  ------------------
  |  Branch (1073:6): [True: 14, False: 26.8k]
  ------------------
 1074|     14|		*pHandle = handle;
 1075|       |
 1076|  26.8k|	list_append(&slot->objects, obj);
 1077|  26.8k|	sc_log(context, "Slot:%lX Setting object handle of 0x%lx to 0x%lx",
  ------------------
  |  |   71|  26.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__
  |  |  ------------------
  ------------------
 1078|  26.8k|		   slot->id, obj->base.handle, handle);
 1079|  26.8k|	obj->base.handle = handle;
 1080|  26.8k|	obj->base.flags |= SC_PKCS11_OBJECT_SEEN;
  ------------------
  |  |  137|  26.8k|#define SC_PKCS11_OBJECT_SEEN	0x0001
  ------------------
 1081|  26.8k|	obj->refcount++;
 1082|       |
 1083|       |	/* Add related objects
 1084|       |	 * XXX prevent infinite recursion when a card specifies two certificates
 1085|       |	 * referring to each other.
 1086|       |	 */
 1087|  26.8k|	obj->base.flags |= SC_PKCS11_OBJECT_RECURS;
  ------------------
  |  |  139|  26.8k|#define SC_PKCS11_OBJECT_RECURS	0x8000
  ------------------
 1088|       |
 1089|  26.8k|	switch (__p15_type(obj)) {
  ------------------
  |  |  119|  26.8k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  ------------------
  |  |  |  Branch (119:26): [True: 3.87k, False: 22.9k]
  |  |  |  Branch (119:28): [True: 26.8k, False: 0]
  |  |  |  Branch (119:37): [True: 26.6k, False: 239]
  |  |  ------------------
  ------------------
 1090|  1.66k|	case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  1.66k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (1090:2): [True: 1.66k, False: 25.2k]
  ------------------
 1091|  1.66k|	case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|  1.66k|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (1091:2): [True: 0, False: 26.8k]
  ------------------
 1092|  2.62k|	case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  2.62k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (1092:2): [True: 958, False: 25.9k]
  ------------------
 1093|  2.62k|	case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|  2.62k|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (1093:2): [True: 0, False: 26.8k]
  ------------------
 1094|  2.62k|	case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|  2.62k|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (1094:2): [True: 0, False: 26.8k]
  ------------------
 1095|  2.62k|		if (slot->p11card != NULL) {
  ------------------
  |  Branch (1095:7): [True: 2.62k, False: 0]
  ------------------
 1096|  2.62k|			pkcs15_add_object(slot, (struct pkcs15_any_object *) obj->related_pubkey, NULL);
 1097|  2.62k|			if (!slot->p11card)
  ------------------
  |  Branch (1097:8): [True: 0, False: 2.62k]
  ------------------
 1098|      0|				return;
 1099|  2.62k|			card_fw_data = (struct pkcs15_fw_data *) slot->p11card->fws_data[slot->fw_data_idx];
 1100|  75.9k|			for (i = 0; i < card_fw_data->num_objects; i++) {
  ------------------
  |  Branch (1100:16): [True: 73.3k, False: 2.62k]
  ------------------
 1101|  73.3k|				struct pkcs15_any_object *obj2 = card_fw_data->objects[i];
 1102|  73.3k|				struct pkcs15_cert_object *cert;
 1103|       |
 1104|  73.3k|				if (!is_cert(obj2))
  ------------------
  |  |  122|  73.3k|#define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  119|  73.3k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 73.3k, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 72.7k, False: 644]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  439|  73.3k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  |  |  ------------------
  ------------------
  |  Branch (1104:9): [True: 61.2k, False: 12.1k]
  ------------------
 1105|  61.2k|					continue;
 1106|       |
 1107|  12.1k|				cert = (struct pkcs15_cert_object*) obj2;
 1108|       |
 1109|  12.1k|				if ((struct pkcs15_any_object*)(cert->cert_prvkey) != obj)
  ------------------
  |  |   96|  12.1k|#define cert_prvkey		base.related_privkey
  ------------------
  |  Branch (1109:9): [True: 11.0k, False: 1.09k]
  ------------------
 1110|  11.0k|					continue;
 1111|       |
 1112|  1.09k|				pkcs15_add_object(slot, obj2, NULL);
 1113|  1.09k|			}
 1114|  2.62k|		}
 1115|  2.62k|		break;
 1116|  2.62k|	case SC_PKCS15_TYPE_CERT_X509:
  ------------------
  |  |  439|  1.25k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  |  Branch (1116:2): [True: 1.25k, False: 25.6k]
  ------------------
 1117|  1.25k|		pkcs15_add_object(slot, (struct pkcs15_any_object *) obj->related_pubkey, NULL);
 1118|  1.25k|		pkcs15_add_object(slot, (struct pkcs15_any_object *) obj->related_cert, NULL);
 1119|  1.25k|		break;
 1120|  26.8k|	}
 1121|       |
 1122|  26.8k|	obj->base.flags &= ~SC_PKCS11_OBJECT_RECURS;
  ------------------
  |  |  139|  26.8k|#define SC_PKCS11_OBJECT_RECURS	0x8000
  ------------------
 1123|  26.8k|}
framework-pkcs15.c:_add_profile_object:
 1506|  8.95k|{
 1507|       |	/* Public Certificates Token in PKCS #11 3.0 */
 1508|  8.95k|	struct pkcs15_any_object *any_pobj = NULL;
 1509|  8.95k|	int rv;
 1510|       |
 1511|  8.95k|	if (slot->profile) {
  ------------------
  |  Branch (1511:6): [True: 3.76k, False: 5.18k]
  ------------------
 1512|  3.76k|		struct pkcs15_profile_object *pobj = (struct pkcs15_profile_object *)slot->profile;
 1513|       |		/* already exists -- downgrade if we found some non-public certificates */
 1514|  3.76k|		if (pobj->profile_id == CKP_PUBLIC_CERTIFICATES_TOKEN && !public_certificates) {
  ------------------
  |  | 1046|  7.53k|#define CKP_PUBLIC_CERTIFICATES_TOKEN 0x00000004UL
  ------------------
  |  Branch (1514:7): [True: 3.68k, False: 85]
  |  Branch (1514:60): [True: 0, False: 3.68k]
  ------------------
 1515|      0|			pobj->profile_id = CKP_AUTHENTICATION_TOKEN;
  ------------------
  |  | 1045|      0|#define CKP_AUTHENTICATION_TOKEN 0x00000003UL
  ------------------
 1516|      0|		}
 1517|  3.76k|		return;
 1518|  3.76k|	}
 1519|       |
 1520|  5.18k|	rv = __pkcs15_create_profile_object(fw_data, public_certificates, &any_pobj);
 1521|  5.18k|	if (rv != CKR_OK || any_pobj == NULL) {
  ------------------
  |  | 1086|  10.3k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1521:6): [True: 0, False: 5.18k]
  |  Branch (1521:22): [True: 0, False: 5.18k]
  ------------------
 1522|      0|		return;
 1523|      0|	}
 1524|  5.18k|	pkcs15_add_object(slot, any_pobj, NULL);
 1525|  5.18k|	slot->profile = any_pobj;
 1526|  5.18k|}
framework-pkcs15.c:__pkcs15_create_profile_object:
  846|  5.18k|{
  847|  5.18k|	struct pkcs15_profile_object *pobj = NULL;
  848|  5.18k|	struct pkcs15_any_object *any_pobj = NULL;
  849|  5.18k|	struct sc_pkcs15_object *obj = NULL;
  850|  5.18k|	int rv;
  851|       |
  852|  5.18k|	obj = calloc(1, sizeof(struct sc_pkcs15_object));
  853|       |
  854|  5.18k|	rv = __pkcs15_create_object(fw_data, &any_pobj,
  855|  5.18k|			obj, &pkcs15_profile_ops, sizeof(struct pkcs15_profile_object));
  856|       |
  857|  5.18k|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|  5.18k|#define SC_SUCCESS				0
  ------------------
  |  Branch (857:6): [True: 0, False: 5.18k]
  ------------------
  858|      0|		free(obj);
  859|      0|		return rv;
  860|      0|	}
  861|  5.18k|	pobj = (struct pkcs15_profile_object *) any_pobj;
  862|  5.18k|	pobj->profile_id = public_certificates ? CKP_PUBLIC_CERTIFICATES_TOKEN : CKP_AUTHENTICATION_TOKEN;
  ------------------
  |  | 1046|  5.10k|#define CKP_PUBLIC_CERTIFICATES_TOKEN 0x00000004UL
  ------------------
              	pobj->profile_id = public_certificates ? CKP_PUBLIC_CERTIFICATES_TOKEN : CKP_AUTHENTICATION_TOKEN;
  ------------------
  |  | 1045|  5.27k|#define CKP_AUTHENTICATION_TOKEN 0x00000003UL
  ------------------
  |  Branch (862:21): [True: 5.10k, False: 85]
  ------------------
  863|       |
  864|  5.18k|	if (profile_object != NULL)
  ------------------
  |  Branch (864:6): [True: 5.18k, False: 0]
  ------------------
  865|  5.18k|		*profile_object = (struct pkcs15_any_object *) pobj;
  866|       |
  867|  5.18k|	return rv;
  868|  5.18k|}
framework-pkcs15.c:_add_public_objects:
 1592|  5.13k|{
 1593|  5.13k|	int public_certificates = 1;
 1594|  5.13k|	unsigned i;
 1595|       |
 1596|  5.13k|	if (slot == NULL || fw_data == NULL)
  ------------------
  |  Branch (1596:6): [True: 0, False: 5.13k]
  |  Branch (1596:22): [True: 0, False: 5.13k]
  ------------------
 1597|      0|		return;
 1598|       |
 1599|  5.13k|	sc_log(context, "%i public objects to process", fw_data->num_objects);
  ------------------
  |  |   71|  5.13k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1600|  33.3k|	for (i=0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (1600:12): [True: 28.2k, False: 5.13k]
  ------------------
 1601|  28.2k|		struct pkcs15_any_object *obj = fw_data->objects[i];
 1602|       |
 1603|       |		/* "Fake" objects we've generated */
 1604|  28.2k|		if (__p15_type(obj) == (unsigned int)-1)
  ------------------
  |  |  119|  28.2k|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  ------------------
  |  |  |  Branch (119:28): [True: 28.2k, False: 0]
  |  |  |  Branch (119:37): [True: 27.9k, False: 239]
  |  |  ------------------
  ------------------
  |  Branch (1604:7): [True: 239, False: 27.9k]
  ------------------
 1605|    239|			continue;
 1606|       |		/* Ignore seen object */
 1607|  27.9k|		if (obj->base.flags & SC_PKCS11_OBJECT_SEEN)
  ------------------
  |  |  137|  27.9k|#define SC_PKCS11_OBJECT_SEEN	0x0001
  ------------------
  |  Branch (1607:7): [True: 11.1k, False: 16.8k]
  ------------------
 1608|  11.1k|			continue;
 1609|       |		/* Ignore 'private' object */
 1610|  16.8k|		if (obj->p15_object->flags & SC_PKCS15_CO_FLAG_PRIVATE) {
  ------------------
  |  |   50|  16.8k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (1610:7): [True: 2.65k, False: 14.1k]
  ------------------
 1611|       |			/* If we found some non-accessible public object,
 1612|       |			 * we can no longer claim Public Certificate Token conformance */
 1613|  2.65k|			if ((obj->p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY ||
  ------------------
  |  |  416|  2.65k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              			if ((obj->p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY ||
  ------------------
  |  |  425|  5.30k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1613:8): [True: 0, False: 2.65k]
  ------------------
 1614|  2.65k|				(obj->p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_CERT) {
  ------------------
  |  |  416|  2.65k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              				(obj->p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_CERT) {
  ------------------
  |  |  438|  2.65k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1614:5): [True: 0, False: 2.65k]
  ------------------
 1615|      0|				public_certificates = 0;
 1616|      0|			}
 1617|  2.65k|			continue;
 1618|  2.65k|		}
 1619|       |		/* PKCS#15 4.1.3 is a little vague, but implies if not PRIVATE it is readable
 1620|       |		 * even if there is an auth_id to allow writing for example.
 1621|       |		 * See bug issue #291
 1622|       |		 * treat pubkey and cert as readable.
 1623|       |		 */
 1624|  14.1k|		if (obj->p15_object->auth_id.len && !(is_pubkey(obj) || is_cert(obj)))
  ------------------
  |  |  121|      0|#define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  119|      0|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 0, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  |  |  ------------------
  |  |  |  Branch (121:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
              		if (obj->p15_object->auth_id.len && !(is_pubkey(obj) || is_cert(obj)))
  ------------------
  |  |  122|      0|#define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  119|      0|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 0, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  |  |  ------------------
  |  |  |  Branch (122:23): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (1624:7): [True: 0, False: 14.1k]
  ------------------
 1625|      0|			continue;
 1626|       |
 1627|  14.1k|		sc_log(context, "Add public object(%p,%.*s,%x)", obj,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1628|  14.1k|			(int) sizeof obj->p15_object->label, obj->p15_object->label,
 1629|  14.1k|			obj->p15_object->type);
 1630|       |		pkcs15_add_object(slot, obj, NULL);
 1631|  14.1k|	}
 1632|  5.13k|	_add_profile_object(slot, fw_data, public_certificates);
 1633|  5.13k|}
framework-pkcs15.c:pkcs15_release_token:
 1789|  5.18k|{
 1790|  5.18k|	sc_log(context, "pkcs15_release_token() not implemented");
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1791|  5.18k|	free(fw_token);
 1792|  5.18k|	return CKR_FUNCTION_REJECTED;
  ------------------
  |  | 1180|  5.18k|#define CKR_FUNCTION_REJECTED 0x00000200UL
  ------------------
 1793|  5.18k|}
framework-pkcs15.c:pkcs15_login:
 1799|  1.75k|{
 1800|  1.75k|	struct sc_pkcs11_card *p11card;
 1801|  1.75k|	struct pkcs15_fw_data *fw_data = NULL;
 1802|  1.75k|	struct sc_pkcs15_card *p15card = NULL;
 1803|  1.75k|	struct sc_pkcs15_object *auth_object = NULL;
 1804|  1.75k|	struct sc_pkcs15_auth_info *pin_info = NULL;
 1805|  1.75k|	int rc;
 1806|       |
 1807|  1.75k|	if (slot->p11card == NULL)
  ------------------
  |  Branch (1807:6): [True: 0, False: 1.75k]
  ------------------
 1808|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Login");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1809|  1.75k|	p11card = slot->p11card;
 1810|       |
 1811|  1.75k|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 1812|  1.75k|	if (!fw_data)
  ------------------
  |  Branch (1812:6): [True: 0, False: 1.75k]
  ------------------
 1813|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_Login");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1814|  1.75k|	p15card = fw_data->p15_card;
 1815|  1.75k|	if (!p15card)
  ------------------
  |  Branch (1815:6): [True: 114, False: 1.64k]
  ------------------
 1816|    114|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Login");
  ------------------
  |  |   60|    114|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1817|       |
 1818|  1.64k|	sc_log(context, "pkcs15-login: userType 0x%lX, PIN length %li", userType, ulPinLen);
  ------------------
  |  |   71|  1.64k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1819|  1.64k|	switch (userType) {
 1820|    338|	case CKU_USER:
  ------------------
  |  | 1211|    338|#define CKU_USER 1UL
  ------------------
  |  Branch (1820:2): [True: 338, False: 1.30k]
  ------------------
 1821|    338|		auth_object = slot_data_auth(slot->fw_data);
  ------------------
  |  |   51|    338|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|    338|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (50:23): [True: 338, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|    338|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  ------------------
  |  |  |  Branch (51:29): [True: 338, False: 0]
  |  |  ------------------
  ------------------
 1822|    338|		if (auth_object == NULL)
  ------------------
  |  Branch (1822:7): [True: 0, False: 338]
  ------------------
 1823|      0|			return CKR_USER_PIN_NOT_INITIALIZED;
  ------------------
  |  | 1152|      0|#define CKR_USER_PIN_NOT_INITIALIZED 0x00000102UL
  ------------------
 1824|    338|		break;
 1825|    894|	case CKU_SO:
  ------------------
  |  | 1210|    894|#define CKU_SO 0UL
  ------------------
  |  Branch (1825:2): [True: 894, False: 750]
  ------------------
 1826|       |		/* A card with no SO PIN is treated as if no SO login
 1827|       |		 * is required */
 1828|    894|		rc = sc_pkcs15_find_so_pin(p15card, &auth_object);
 1829|    894|		sc_log(context, "pkcs15-login: find SO PIN: rc %i", rc);
  ------------------
  |  |   71|    894|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1830|       |
 1831|       |		/* If there's no SO PIN on the card, silently
 1832|       |		 * accept any PIN, and lock the card if required */
 1833|    894|		if (rc == SC_ERROR_OBJECT_NOT_FOUND)   {
  ------------------
  |  |   88|    894|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1833:7): [True: 783, False: 111]
  ------------------
 1834|    783|			rc = 0;
 1835|    783|			if (sc_pkcs11_conf.lock_login)
  ------------------
  |  Branch (1835:8): [True: 0, False: 783]
  ------------------
 1836|      0|				rc = lock_card(fw_data);
 1837|       |
 1838|    783|			if (sc_pkcs11_conf.pin_unblock_style == SC_PKCS11_PIN_UNBLOCK_SO_LOGGED_INITPIN)   {
  ------------------
  |  |   42|    783|#define SC_PKCS11_PIN_UNBLOCK_SO_LOGGED_INITPIN	3
  ------------------
  |  Branch (1838:8): [True: 0, False: 783]
  ------------------
 1839|      0|				if (ulPinLen)   {
  ------------------
  |  Branch (1839:9): [True: 0, False: 0]
  ------------------
 1840|      0|					unsigned char *user_puk = sc_mem_secure_alloc(ulPinLen);
 1841|      0|					if (user_puk) {
  ------------------
  |  Branch (1841:10): [True: 0, False: 0]
  ------------------
 1842|      0|						memcpy(user_puk, pPin, ulPinLen);
 1843|       |
 1844|      0|						sc_mem_secure_clear_free(fw_data->user_puk, fw_data->user_puk_len);
  ------------------
  |  | 1580|      0|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|      0|	sc_mem_clear(ptr, len); \
  |  | 1582|      0|	sc_mem_secure_free(ptr, len); \
  |  | 1583|      0|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1845|       |
 1846|      0|						fw_data->user_puk = user_puk;
 1847|      0|						fw_data->user_puk_len = (unsigned int) ulPinLen;
 1848|      0|					}
 1849|      0|				}
 1850|      0|			}
 1851|       |
 1852|    783|			sc_log(context, "No SOPIN found; returns %d", rc);
  ------------------
  |  |   71|    783|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1853|    783|			return sc_to_cryptoki_error(rc, "C_Login");
 1854|    783|		}
 1855|    111|		else if (rc < 0)   {
  ------------------
  |  Branch (1855:12): [True: 0, False: 111]
  ------------------
 1856|      0|			return sc_to_cryptoki_error(rc, "C_Login");
 1857|      0|		}
 1858|       |
 1859|    111|		break;
 1860|    412|	case CKU_CONTEXT_SPECIFIC:
  ------------------
  |  | 1212|    412|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  |  Branch (1860:2): [True: 412, False: 1.23k]
  ------------------
 1861|       |		/*
 1862|       |		 * A session should already be open for user or SO
 1863|       |		 * All we need to do is authenticate to the card
 1864|       |		 * using the correct auth_object.
 1865|       |		 * TODO: handle the CK_SO case
 1866|       |		 */
 1867|    412|		sc_log(context, "context specific login %d", slot->login_user);
  ------------------
  |  |   71|    412|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1868|    412|		if (slot->login_user == CKU_USER) {
  ------------------
  |  | 1211|    412|#define CKU_USER 1UL
  ------------------
  |  Branch (1868:7): [True: 26, False: 386]
  ------------------
 1869|     26|			auth_object = slot_data_auth(slot->fw_data);
  ------------------
  |  |   51|     26|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|     26|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (50:23): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|     26|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  ------------------
  |  |  |  Branch (51:29): [True: 26, False: 0]
  |  |  ------------------
  ------------------
 1870|     26|			if (auth_object == NULL)
  ------------------
  |  Branch (1870:8): [True: 0, False: 26]
  ------------------
 1871|      0|				return CKR_USER_PIN_NOT_INITIALIZED;
  ------------------
  |  | 1152|      0|#define CKR_USER_PIN_NOT_INITIALIZED 0x00000102UL
  ------------------
 1872|     26|			break;
 1873|     26|		}
 1874|       |		/* TODO looks like this was never executed,
 1875|       |		 * And even if it was, why the lock as a session
 1876|       |		 * should already be open and the card locked.
 1877|       |		 */
 1878|       |		/* For a while, used only to unblock User PIN. */
 1879|    386|		rc = 0;
 1880|    386|		if (sc_pkcs11_conf.lock_login)
  ------------------
  |  Branch (1880:7): [True: 0, False: 386]
  ------------------
 1881|      0|			rc = lock_card(fw_data);
 1882|    386|		sc_log(context, "context specific login returns %d", rc);
  ------------------
  |  |   71|    386|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1883|    386|		return sc_to_cryptoki_error(rc, "C_Login");
 1884|      0|	default:
  ------------------
  |  Branch (1884:2): [True: 0, False: 1.64k]
  ------------------
 1885|      0|		return CKR_USER_TYPE_INVALID;
  ------------------
  |  | 1153|      0|#define CKR_USER_TYPE_INVALID 0x00000103UL
  ------------------
 1886|  1.64k|	}
 1887|    475|	pin_info = (struct sc_pkcs15_auth_info *) auth_object->data;
 1888|    475|	if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    475|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1888:6): [True: 0, False: 475]
  ------------------
 1889|      0|		return CKR_FUNCTION_REJECTED;
  ------------------
  |  | 1180|      0|#define CKR_FUNCTION_REJECTED 0x00000200UL
  ------------------
 1890|       |
 1891|    475|	if (!p11card)
  ------------------
  |  Branch (1891:6): [True: 0, False: 475]
  ------------------
 1892|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Login");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1893|       |
 1894|       |	/* By default, we make the reader resource manager keep other
 1895|       |	 * processes from accessing the card while we're logged in.
 1896|       |	 * Otherwise an attacker could perform some crypto operation
 1897|       |	 * after we've authenticated with the card */
 1898|       |
 1899|       |	/* Context specific login is not real login but only a
 1900|       |	 * reassertion of the PIN to the card.
 1901|       |	 * And we don't want to do any extra operations to the card
 1902|       |	 * that could invalidate the assertion of the pin
 1903|       |	 * before the crypto operation that requires the assertion
 1904|       |	 */
 1905|    475|	if (userType != CKU_CONTEXT_SPECIFIC) {
  ------------------
  |  | 1212|    475|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  |  Branch (1905:6): [True: 449, False: 26]
  ------------------
 1906|    449|		if (sc_pkcs11_conf.lock_login && (rc = lock_card(fw_data)) < 0)   {
  ------------------
  |  Branch (1906:7): [True: 0, False: 449]
  |  Branch (1906:36): [True: 0, False: 0]
  ------------------
 1907|      0|			return sc_to_cryptoki_error(rc, "C_Login");
 1908|      0|		}
 1909|    449|	}
 1910|       |
 1911|    475|	if (userType  == CKU_CONTEXT_SPECIFIC) {
  ------------------
  |  | 1212|    475|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  |  Branch (1911:6): [True: 26, False: 449]
  ------------------
 1912|     26|		int auth_meth_saved = pin_info->auth_method;
 1913|       |
 1914|     26|		sc_log(context, "Setting SC_AC_CONTEXT_SPECIFIC");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1915|     26|		pin_info->auth_method = SC_AC_CONTEXT_SPECIFIC;
  ------------------
  |  |  160|     26|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
 1916|     26|		rc = sc_pkcs15_verify_pin(p15card, auth_object, pPin, ulPinLen);
 1917|     26|		pin_info->auth_method = auth_meth_saved;
 1918|     26|	} else
 1919|    449|		rc = sc_pkcs15_verify_pin(p15card, auth_object, pPin, ulPinLen);
 1920|       |
 1921|    475|	sc_log(context, "PKCS15 verify PIN returned %d", rc);
  ------------------
  |  |   71|    475|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1922|       |
 1923|    475|	if (rc != SC_SUCCESS)
  ------------------
  |  |   28|    475|#define SC_SUCCESS				0
  ------------------
  |  Branch (1923:6): [True: 382, False: 93]
  ------------------
 1924|    382|		return sc_to_cryptoki_error(rc, "C_Login");
 1925|       |
 1926|     93|	if (userType == CKU_USER)   {
  ------------------
  |  | 1211|     93|#define CKU_USER 1UL
  ------------------
  |  Branch (1926:6): [True: 47, False: 46]
  ------------------
 1927|     47|		sc_pkcs15_object_t *p15_obj = p15card->obj_list;
 1928|     47|		sc_pkcs15_search_key_t sk;
 1929|       |
 1930|     47|		sc_log(context, "Check if pkcs15 object list can be completed.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1931|       |
 1932|       |		/* Ensure non empty list */
 1933|     47|		if (p15_obj == NULL)
  ------------------
  |  Branch (1933:7): [True: 0, False: 47]
  ------------------
 1934|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 1935|       |
 1936|       |		/* Select last object in list */
 1937|    374|		while(p15_obj->next)
  ------------------
  |  Branch (1937:9): [True: 327, False: 47]
  ------------------
 1938|    327|			p15_obj = p15_obj->next;
 1939|       |
 1940|       |		/* Trigger enumeration of EF.XXX files */
 1941|     47|		memset(&sk, 0, sizeof(sk));
 1942|     47|		sk.class_mask = SC_PKCS15_SEARCH_CLASS_PRKEY | SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  450|     47|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
              		sk.class_mask = SC_PKCS15_SEARCH_CLASS_PRKEY | SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|     47|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1943|     47|				SC_PKCS15_SEARCH_CLASS_CERT  | SC_PKCS15_SEARCH_CLASS_DATA;
  ------------------
  |  |  453|     47|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
              				SC_PKCS15_SEARCH_CLASS_CERT  | SC_PKCS15_SEARCH_CLASS_DATA;
  ------------------
  |  |  454|     47|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1944|     47|		sc_pkcs15_search_objects(p15card, &sk, NULL, 0);
 1945|       |
 1946|       |		/* Iterate over newly discovered objects */
 1947|     47|		while(p15_obj->next) {
  ------------------
  |  Branch (1947:9): [True: 0, False: 47]
  ------------------
 1948|      0|			struct pkcs15_any_object *fw_obj;
 1949|       |
 1950|      0|			p15_obj = p15_obj->next;
 1951|       |
 1952|      0|			if (!sc_pkcs15_compare_id(&pin_info->auth_id, &p15_obj->auth_id))
  ------------------
  |  Branch (1952:8): [True: 0, False: 0]
  ------------------
 1953|      0|				continue;
 1954|       |
 1955|      0|			switch (p15_obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 1956|      0|			case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1956:4): [True: 0, False: 0]
  ------------------
 1957|      0|				__pkcs15_create_prkey_object(fw_data, p15_obj, &fw_obj); break;
 1958|      0|			case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1958:4): [True: 0, False: 0]
  ------------------
 1959|      0|				__pkcs15_create_pubkey_object(fw_data, p15_obj, &fw_obj); break;
 1960|      0|			case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|      0|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1960:4): [True: 0, False: 0]
  ------------------
 1961|      0|				__pkcs15_create_cert_object(fw_data, p15_obj, &fw_obj); break;
 1962|      0|			case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (1962:4): [True: 0, False: 0]
  ------------------
 1963|      0|				__pkcs15_create_data_object(fw_data, p15_obj, &fw_obj); break;
 1964|      0|			default: continue;
  ------------------
  |  Branch (1964:4): [True: 0, False: 0]
  ------------------
 1965|      0|			}
 1966|       |
 1967|      0|			sc_log(context, "new object found: type=0x%03X", p15_obj->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__
  |  |  ------------------
  ------------------
 1968|      0|			pkcs15_add_object(slot, fw_obj, NULL);
 1969|      0|		}
 1970|     47|	}
 1971|       |
 1972|     93|	return CKR_OK;
  ------------------
  |  | 1086|     93|#define CKR_OK 0x00000000UL
  ------------------
 1973|     93|}
framework-pkcs15.c:pkcs15_logout:
 1989|    858|{
 1990|    858|	struct sc_pkcs11_card *p11card = slot->p11card;
 1991|    858|	struct pkcs15_fw_data *fw_data = NULL;
 1992|    858|	CK_RV ret = CKR_OK;
  ------------------
  |  | 1086|    858|#define CKR_OK 0x00000000UL
  ------------------
 1993|       |#if !(defined(SW_PIN_LOGOUT_ONLY) && SW_PIN_LOGOUT_ONLY == 1)
 1994|       |	int rc;
 1995|       |#endif
 1996|       |
 1997|    858|	if (!p11card)
  ------------------
  |  Branch (1997:6): [True: 0, False: 858]
  ------------------
 1998|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Logout");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1999|    858|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 2000|    858|	if (!fw_data)
  ------------------
  |  Branch (2000:6): [True: 0, False: 858]
  ------------------
 2001|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_Logout");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2002|    858|	if (!fw_data->p15_card)
  ------------------
  |  Branch (2002:6): [True: 0, False: 858]
  ------------------
 2003|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Logout");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2004|       |
 2005|    858|	sc_mem_secure_clear_free(fw_data->user_puk, fw_data->user_puk_len);
  ------------------
  |  | 1580|    858|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|    858|	sc_mem_clear(ptr, len); \
  |  | 1582|    858|	sc_mem_secure_free(ptr, len); \
  |  | 1583|    858|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 858]
  |  |  ------------------
  ------------------
 2006|    858|	fw_data->user_puk = NULL;
 2007|    858|	fw_data->user_puk_len = 0;
 2008|       |
 2009|    858|	sc_pkcs15_pincache_clear(fw_data->p15_card);
 2010|       |
 2011|    858|#if defined(SW_PIN_LOGOUT_ONLY) && SW_PIN_LOGOUT_ONLY == 1
 2012|    858|	sc_log(context, "Clearing PIN state without calling sc_logout()");
  ------------------
  |  |   71|    858|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2013|       |#else
 2014|       |	rc = sc_logout(fw_data->p15_card->card);
 2015|       |
 2016|       |	/* Ignore missing card specific logout functions. #302 */
 2017|       |	if (rc == SC_ERROR_NOT_SUPPORTED)
 2018|       |		rc = SC_SUCCESS;
 2019|       |
 2020|       |	if (rc != SC_SUCCESS)
 2021|       |		ret = sc_to_cryptoki_error(rc, "C_Logout");
 2022|       |
 2023|       |	if (sc_pkcs11_conf.lock_login) {
 2024|       |		rc = unlock_card(fw_data);
 2025|       |		if (rc != SC_SUCCESS)
 2026|       |			ret = sc_to_cryptoki_error(rc, "C_Logout");
 2027|       |	}
 2028|       |#endif
 2029|       |
 2030|       |	/* TODO DEE free any session objects ? */
 2031|       |
 2032|    858|	return ret;
 2033|    858|}
framework-pkcs15.c:pkcs15_change_pin:
 2040|    816|{
 2041|    816|	struct sc_pkcs11_card *p11card = slot->p11card;
 2042|    816|	struct sc_pkcs15_card *p15card = NULL;
 2043|    816|	struct pkcs15_fw_data *fw_data = NULL;
 2044|    816|	struct sc_pkcs15_auth_info *auth_info = NULL;
 2045|    816|	struct sc_pkcs15_object *pin_obj = NULL;
 2046|    816|	int login_user = slot->login_user;
 2047|    816|	int rc;
 2048|       |
 2049|    816|	if (!p11card)
  ------------------
  |  Branch (2049:6): [True: 0, False: 816]
  ------------------
 2050|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_SetPin");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2051|    816|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 2052|    816|	if (!fw_data)
  ------------------
  |  Branch (2052:6): [True: 0, False: 816]
  ------------------
 2053|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_SetPin");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2054|    816|	p15card = fw_data->p15_card;
 2055|    816|	if (!p15card)
  ------------------
  |  Branch (2055:6): [True: 261, False: 555]
  ------------------
 2056|    261|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_SetPin");
  ------------------
  |  |   60|    261|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2057|       |
 2058|    555|	if (login_user == CKU_SO) {
  ------------------
  |  | 1210|    555|#define CKU_SO 0UL
  ------------------
  |  Branch (2058:6): [True: 48, False: 507]
  ------------------
 2059|     48|		rc = sc_pkcs15_find_so_pin(p15card, &pin_obj);
 2060|     48|		sc_log(context, "pkcs15-login: find SO PIN: rc %i", rc);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2061|    507|	} else {
 2062|    507|		pin_obj = slot_data_auth(slot->fw_data);
  ------------------
  |  |   51|    507|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|    502|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (50:23): [True: 502, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|    502|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  ------------------
  |  |  |  Branch (51:29): [True: 502, False: 5]
  |  |  ------------------
  ------------------
 2063|    507|	}
 2064|       |
 2065|    555|	if (!pin_obj)
  ------------------
  |  Branch (2065:6): [True: 83, False: 472]
  ------------------
 2066|     83|		return CKR_USER_PIN_NOT_INITIALIZED;
  ------------------
  |  | 1152|     83|#define CKR_USER_PIN_NOT_INITIALIZED 0x00000102UL
  ------------------
 2067|       |
 2068|    472|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
 2069|    472|	if (!auth_info)
  ------------------
  |  Branch (2069:6): [True: 0, False: 472]
  ------------------
 2070|      0|		return CKR_USER_PIN_NOT_INITIALIZED;
  ------------------
  |  | 1152|      0|#define CKR_USER_PIN_NOT_INITIALIZED 0x00000102UL
  ------------------
 2071|       |
 2072|    472|	sc_log(context, "Change '%.*s' (ref:%i,type:%i)", (int) sizeof pin_obj->label, pin_obj->label, auth_info->attrs.pin.reference, login_user);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2073|    472|	if (pNewPin && (ulNewLen < auth_info->attrs.pin.min_length || ulNewLen > auth_info->attrs.pin.max_length)) {
  ------------------
  |  Branch (2073:6): [True: 472, False: 0]
  |  Branch (2073:18): [True: 314, False: 158]
  |  Branch (2073:64): [True: 40, False: 118]
  ------------------
 2074|    354|		return CKR_PIN_LEN_RANGE;
  ------------------
  |  | 1129|    354|#define CKR_PIN_LEN_RANGE 0x000000A2UL
  ------------------
 2075|    354|	}
 2076|       |
 2077|    118|	if (login_user < 0 && sc_pkcs11_conf.pin_unblock_style == SC_PKCS11_PIN_UNBLOCK_UNLOGGED_SETPIN) {
  ------------------
  |  |   40|    111|#define SC_PKCS11_PIN_UNBLOCK_UNLOGGED_SETPIN	1
  ------------------
  |  Branch (2077:6): [True: 111, False: 7]
  |  Branch (2077:24): [True: 0, False: 111]
  ------------------
 2078|      0|		rc = sc_pkcs15_unblock_pin(fw_data->p15_card, pin_obj, pOldPin, ulOldLen, pNewPin, ulNewLen);
 2079|      0|	}
 2080|    118|	else if (login_user == CKU_CONTEXT_SPECIFIC)   {
  ------------------
  |  | 1212|    118|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  |  Branch (2080:11): [True: 0, False: 118]
  ------------------
 2081|      0|		if (sc_pkcs11_conf.pin_unblock_style != SC_PKCS11_PIN_UNBLOCK_SCONTEXT_SETPIN) {
  ------------------
  |  |   41|      0|#define SC_PKCS11_PIN_UNBLOCK_SCONTEXT_SETPIN	2
  ------------------
  |  Branch (2081:7): [True: 0, False: 0]
  ------------------
 2082|      0|			sc_log(context, "PIN unlock is not allowed with CKU_CONTEXT_SPECIFIC login");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2083|      0|			return CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
 2084|      0|		}
 2085|      0|		rc = sc_pkcs15_unblock_pin(fw_data->p15_card, pin_obj, pOldPin, ulOldLen, pNewPin, ulNewLen);
 2086|      0|	}
 2087|    118|	else if (login_user < 0 || login_user == CKU_USER || login_user == CKU_SO) {
  ------------------
  |  | 1211|    125|#define CKU_USER 1UL
  ------------------
              	else if (login_user < 0 || login_user == CKU_USER || login_user == CKU_SO) {
  ------------------
  |  | 1210|      1|#define CKU_SO 0UL
  ------------------
  |  Branch (2087:11): [True: 111, False: 7]
  |  Branch (2087:29): [True: 6, False: 1]
  |  Branch (2087:55): [True: 1, False: 0]
  ------------------
 2088|    118|		rc = sc_pkcs15_change_pin(fw_data->p15_card, pin_obj, pOldPin, ulOldLen, pNewPin, ulNewLen);
 2089|    118|	}
 2090|      0|	else {
 2091|      0|		sc_log(context, "cannot change PIN: non supported login type: %i", login_user);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2092|      0|		return CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
 2093|      0|	}
 2094|       |
 2095|    118|	sc_log(context, "PIN change returns %d", rc);
  ------------------
  |  |   71|    118|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2096|    118|	return sc_to_cryptoki_error(rc, "C_SetPIN");
 2097|    118|}
framework-pkcs15.c:pkcs15_init_pin:
 2233|    145|{
 2234|    145|	struct sc_pkcs11_card *p11card = slot->p11card;
 2235|    145|	struct pkcs15_fw_data *fw_data = NULL;
 2236|    145|	struct sc_pkcs15init_pinargs args;
 2237|    145|	struct sc_profile	*profile = NULL;
 2238|    145|	struct sc_pkcs15_object	*auth_obj = NULL;
 2239|    145|	struct sc_pkcs15_auth_info *auth_info = NULL;
 2240|    145|	struct sc_cardctl_pkcs11_init_pin p11args;
 2241|    145|	int rc;
 2242|       |
 2243|    145|	memset(&p11args, 0, sizeof(p11args));
 2244|    145|	p11args.pin = pPin;
 2245|    145|	p11args.pin_len = ulPinLen;
 2246|       |
 2247|    145|	if (!p11card)
  ------------------
  |  Branch (2247:6): [True: 0, False: 145]
  ------------------
 2248|      0|		return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
 2249|    145|	rc = sc_card_ctl(p11card->card, SC_CARDCTL_PKCS11_INIT_PIN, &p11args);
 2250|    145|	if (rc != SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|    145|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (2250:6): [True: 7, False: 138]
  ------------------
 2251|      7|		if (rc == SC_SUCCESS)
  ------------------
  |  |   28|      7|#define SC_SUCCESS				0
  ------------------
  |  Branch (2251:7): [True: 1, False: 6]
  ------------------
 2252|      1|			return CKR_OK;
  ------------------
  |  | 1086|      1|#define CKR_OK 0x00000000UL
  ------------------
 2253|      6|		return sc_to_cryptoki_error(rc, "C_InitPin");
 2254|      7|	}
 2255|       |
 2256|    138|	sc_log(context, "Init PIN: pin %p:%lu; unblock style %i", pPin,
  ------------------
  |  |   71|    138|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2257|    138|		ulPinLen, sc_pkcs11_conf.pin_unblock_style);
 2258|       |
 2259|    138|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 2260|    138|	if (!fw_data)
  ------------------
  |  Branch (2260:6): [True: 0, False: 138]
  ------------------
 2261|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_InitPin");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2262|       |
 2263|    138|	auth_info = slot_data_auth_info(slot->fw_data);
  ------------------
  |  |   52|    138|#define slot_data_auth_info(p)	(((p) && slot_data_auth(p))? \
  |  |  ------------------
  |  |  |  |   51|    137|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|    137|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 137, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|    137|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:27): [True: 16, False: 121]
  |  |  |  |  |  Branch (51:29): [True: 137, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (52:34): [True: 137, False: 1]
  |  |  ------------------
  |  |   53|    138|		(struct sc_pkcs15_auth_info *) slot_data_auth(p)->data : NULL)
  |  |  ------------------
  |  |  |  |   51|     16|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     16|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 16, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     16|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:29): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2264|    138|	if (auth_info && sc_pkcs11_conf.pin_unblock_style == SC_PKCS11_PIN_UNBLOCK_SO_LOGGED_INITPIN)   {
  ------------------
  |  |   42|     16|#define SC_PKCS11_PIN_UNBLOCK_SO_LOGGED_INITPIN	3
  ------------------
  |  Branch (2264:6): [True: 16, False: 122]
  |  Branch (2264:19): [True: 0, False: 16]
  ------------------
 2265|      0|		if (!fw_data->p15_card)
  ------------------
  |  Branch (2265:7): [True: 0, False: 0]
  ------------------
 2266|      0|			return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_InitPin");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2267|       |		/* C_InitPIN is used to unblock User PIN or set it in the SO session .*/
 2268|      0|		auth_obj = slot_data_auth(slot->fw_data);
  ------------------
  |  |   51|      0|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|      0|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (50:23): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  ------------------
  |  |  |  |   50|      0|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  ------------------
  |  |  |  Branch (51:29): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2269|      0|		if (fw_data->user_puk_len)
  ------------------
  |  Branch (2269:7): [True: 0, False: 0]
  ------------------
 2270|      0|			rc = sc_pkcs15_unblock_pin(fw_data->p15_card, auth_obj,
 2271|      0|					fw_data->user_puk, fw_data->user_puk_len, pPin, ulPinLen);
 2272|      0|		else
 2273|       |			/* FIXME (VT): Actually sc_pkcs15_unblock_pin() do not accepts zero length PUK.
 2274|       |			 * Something like sc_pkcs15_set_pin() should be introduced.
 2275|       |			 * For a while, use the 'libopensc' API to set PIN. */
 2276|      0|			rc = sc_reset_retry_counter(fw_data->p15_card->card, SC_AC_CHV, auth_info->attrs.pin.reference,
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2277|      0|					NULL, 0, pPin, ulPinLen);
 2278|       |
 2279|      0|		return sc_to_cryptoki_error(rc, "C_InitPIN");
 2280|      0|	}
 2281|       |
 2282|    138|	rc = sc_lock(p11card->card);
 2283|    138|	if (rc < 0)
  ------------------
  |  Branch (2283:6): [True: 0, False: 138]
  ------------------
 2284|      0|		return sc_to_cryptoki_error(rc, "C_InitPIN");
 2285|       |
 2286|    138|	rc = sc_pkcs15init_bind(p11card->card, "pkcs15", NULL, NULL, &profile);
 2287|    138|	if (rc < 0) {
  ------------------
  |  Branch (2287:6): [True: 138, False: 0]
  ------------------
 2288|    138|		sc_unlock(p11card->card);
 2289|    138|		return sc_to_cryptoki_error(rc, "C_InitPIN");
 2290|    138|	}
 2291|       |
 2292|      0|	rc = sc_pkcs15init_finalize_profile(p11card->card, profile, NULL);
 2293|      0|	if (rc != CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2293:6): [True: 0, False: 0]
  ------------------
 2294|      0|		sc_log(context, "Cannot finalize profile: %i", rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2295|      0|		return sc_to_cryptoki_error(rc, "C_InitPIN");
 2296|      0|	}
 2297|       |
 2298|      0|	memset(&args, 0, sizeof(args));
 2299|      0|	args.label = "User PIN";
 2300|      0|	args.pin = pPin;
 2301|      0|	args.pin_len = ulPinLen;
 2302|      0|	rc = sc_pkcs15init_store_pin(fw_data->p15_card, profile, &args);
 2303|       |
 2304|      0|	sc_pkcs15init_unbind(profile);
 2305|      0|	sc_unlock(p11card->card);
 2306|      0|	if (rc < 0)
  ------------------
  |  Branch (2306:6): [True: 0, False: 0]
  ------------------
 2307|      0|		return sc_to_cryptoki_error(rc, "C_InitPIN");
 2308|       |
 2309|      0|	rc = sc_pkcs15_find_pin_by_auth_id(fw_data->p15_card, &args.auth_id, &auth_obj);
 2310|      0|	if (rc < 0)
  ------------------
  |  Branch (2310:6): [True: 0, False: 0]
  ------------------
 2311|      0|		return sc_to_cryptoki_error(rc, "C_InitPIN");
 2312|       |
 2313|       |	/* Re-initialize the slot */
 2314|      0|	free(slot->fw_data);
 2315|      0|	pkcs15_init_slot(fw_data->p15_card, slot, auth_obj, slot->app_info);
 2316|       |
 2317|      0|	return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 2318|      0|}
framework-pkcs15.c:pkcs15_create_object:
 3105|    327|{
 3106|    327|	struct sc_pkcs11_card *p11card = slot->p11card;
 3107|    327|	struct pkcs15_fw_data *fw_data = NULL;
 3108|    327|	struct sc_profile *profile = NULL;
 3109|    327|	CK_OBJECT_CLASS	_class;
 3110|    327|	CK_BBOOL _token = FALSE;
  ------------------
  |  |   48|    327|#define FALSE 0
  ------------------
 3111|    327|	CK_RV rv;
 3112|    327|	int rc;
 3113|    327|	CK_BBOOL p15init_create_object;
 3114|       |
 3115|    327|	if (!p11card)
  ------------------
  |  Branch (3115:6): [True: 0, False: 327]
  ------------------
 3116|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3117|    327|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 3118|    327|	if (!fw_data)
  ------------------
  |  Branch (3118:6): [True: 0, False: 327]
  ------------------
 3119|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_CreateObject");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3120|    327|	if (!fw_data->p15_card)
  ------------------
  |  Branch (3120:6): [True: 176, False: 151]
  ------------------
 3121|    176|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|    176|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3122|       |
 3123|    151|	rv = attr_find(pTemplate, ulCount, CKA_CLASS, &_class, NULL);
  ------------------
  |  |  137|    151|#define CKA_CLASS 0x00000000UL
  ------------------
 3124|    151|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    151|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3124:6): [True: 0, False: 151]
  ------------------
 3125|      0|		return rv;
 3126|       |
 3127|    151|	rv = attr_find(pTemplate, ulCount, CKA_TOKEN, &_token, NULL);
  ------------------
  |  |  138|    151|#define CKA_TOKEN 0x00000001UL
  ------------------
 3128|    151|	if (rv != CKR_TEMPLATE_INCOMPLETE && rv != CKR_OK) {
  ------------------
  |  | 1142|    302|#define CKR_TEMPLATE_INCOMPLETE 0x000000D0UL
  ------------------
              	if (rv != CKR_TEMPLATE_INCOMPLETE && rv != CKR_OK) {
  ------------------
  |  | 1086|    151|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3128:6): [True: 151, False: 0]
  |  Branch (3128:39): [True: 0, False: 151]
  ------------------
 3129|      0|		return rv;
 3130|      0|	}
 3131|       |
 3132|       |	/* Dont need profile if creating session only objects,
 3133|       |	 * except when the card supports temporary on card session objects */
 3134|    151|	p15init_create_object = _token == TRUE || (p11card->card->caps & SC_CARD_CAP_ONCARD_SESSION_OBJECTS) == SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |   51|    302|#define TRUE 1
  ------------------
              	p15init_create_object = _token == TRUE || (p11card->card->caps & SC_CARD_CAP_ONCARD_SESSION_OBJECTS) == SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |  569|     55|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
              	p15init_create_object = _token == TRUE || (p11card->card->caps & SC_CARD_CAP_ONCARD_SESSION_OBJECTS) == SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |  569|    206|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
  |  Branch (3134:26): [True: 96, False: 55]
  |  Branch (3134:44): [True: 0, False: 55]
  ------------------
 3135|       |
 3136|    151|	if (p15init_create_object) {
  ------------------
  |  Branch (3136:6): [True: 96, False: 55]
  ------------------
 3137|     96|		struct sc_aid *aid = NULL;
 3138|       |
 3139|     96|		rc = sc_lock(p11card->card);
 3140|     96|		if (rc < 0)
  ------------------
  |  Branch (3140:7): [True: 0, False: 96]
  ------------------
 3141|      0|			return sc_to_cryptoki_error(rc, "C_CreateObject");
 3142|       |
 3143|       |		/* Bind the profile */
 3144|     96|		rc = sc_pkcs15init_bind(p11card->card, "pkcs15", NULL, slot->app_info, &profile);
 3145|     96|		if (rc < 0) {
  ------------------
  |  Branch (3145:7): [True: 96, False: 0]
  ------------------
 3146|     96|			sc_unlock(p11card->card);
 3147|     96|			return sc_to_cryptoki_error(rc, "C_CreateObject");
 3148|     96|		}
 3149|       |
 3150|      0|		if (slot->app_info)
  ------------------
  |  Branch (3150:7): [True: 0, False: 0]
  ------------------
 3151|      0|			aid = &slot->app_info->aid;
 3152|       |
 3153|      0|		rc = sc_pkcs15init_finalize_profile(p11card->card, profile, aid);
 3154|      0|		if (rc != CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3154:7): [True: 0, False: 0]
  ------------------
 3155|      0|			sc_log(context, "Cannot finalize profile: %i", rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3156|      0|			sc_unlock(p11card->card);
 3157|      0|			return sc_to_cryptoki_error(rc, "C_CreateObject");
 3158|      0|		}
 3159|       |
 3160|      0|		sc_pkcs15init_set_p15card(profile, fw_data->p15_card);
 3161|      0|	}
 3162|     55|	switch (_class) {
 3163|      0|	case CKO_PRIVATE_KEY:
  ------------------
  |  | 1030|      0|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (3163:2): [True: 0, False: 55]
  ------------------
 3164|      0|		rv = pkcs15_create_private_key(slot, profile, pTemplate, ulCount, phObject);
 3165|      0|		break;
 3166|      0|	case CKO_PUBLIC_KEY:
  ------------------
  |  | 1029|      0|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
  |  Branch (3166:2): [True: 0, False: 55]
  ------------------
 3167|      0|		rv = pkcs15_create_public_key(slot, profile, pTemplate, ulCount, phObject);
 3168|      0|		break;
 3169|      3|	case CKO_CERTIFICATE:
  ------------------
  |  | 1028|      3|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
  |  Branch (3169:2): [True: 3, False: 52]
  ------------------
 3170|      3|		rv = pkcs15_create_certificate(slot, profile, pTemplate, ulCount, phObject);
 3171|      3|		break;
 3172|     36|	case CKO_DATA:
  ------------------
  |  | 1027|     36|#define CKO_DATA 0x00000000UL
  ------------------
  |  Branch (3172:2): [True: 36, False: 19]
  ------------------
 3173|     36|		rv = pkcs15_create_data(slot, profile, pTemplate, ulCount, phObject);
 3174|     36|		break;
 3175|     16|	case CKO_SECRET_KEY:
  ------------------
  |  | 1031|     16|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  |  Branch (3175:2): [True: 16, False: 39]
  ------------------
 3176|     16|		rv = pkcs15_create_secret_key(slot, profile, pTemplate, ulCount, phObject);
 3177|     16|		break;
 3178|      0|	default:
  ------------------
  |  Branch (3178:2): [True: 0, False: 55]
  ------------------
 3179|      0|		rv = CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
 3180|     55|	}
 3181|       |
 3182|     55|	if (p15init_create_object) {
  ------------------
  |  Branch (3182:6): [True: 0, False: 55]
  ------------------
 3183|       |		// TODO: after sc_pkcs15init_unbind, user may have to enter PIN on a pin pad reader even though authentication state
 3184|       |		// is supposed to remain open. Check why this happens.
 3185|      0|		sc_pkcs15init_unbind(profile);
 3186|      0|		sc_unlock(p11card->card);
 3187|      0|	}
 3188|       |
 3189|     55|	return rv;
 3190|     55|}
framework-pkcs15.c:set_cka_label:
  470|      5|{
  471|      5|	char *l = (char *)attr->pValue;
  472|      5|	unsigned long len = attr->ulValueLen;
  473|       |
  474|      5|	if (len >= SC_PKCS15_MAX_LABEL_SIZE)
  ------------------
  |  |   35|      5|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  |  Branch (474:6): [True: 0, False: 5]
  ------------------
  475|      0|		len = SC_PKCS15_MAX_LABEL_SIZE-1;
  ------------------
  |  |   35|      0|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  476|      5|	memcpy(label, l, len);
  477|      5|	label[len] = '\0';
  478|      5|	return label;
  479|      5|}
framework-pkcs15.c:pkcs15_check_bool_cka:
 2323|     45|{
 2324|     45|	if (attr->ulValueLen != sizeof(CK_BBOOL) || !attr->pValue)
  ------------------
  |  Branch (2324:6): [True: 0, False: 45]
  |  Branch (2324:46): [True: 0, False: 45]
  ------------------
 2325|      0|		return 0;
 2326|       |
 2327|     45|	if (*((CK_BBOOL *)attr->pValue))
  ------------------
  |  Branch (2327:6): [True: 19, False: 26]
  ------------------
 2328|     19|		return flag;
 2329|       |
 2330|     26|	return 0;
 2331|     45|}
framework-pkcs15.c:pkcs15_create_certificate:
 2932|      3|{
 2933|      3|	struct sc_pkcs11_card *p11card = slot->p11card;
 2934|      3|	struct pkcs15_fw_data *fw_data = NULL;
 2935|      3|	struct sc_pkcs15init_certargs args;
 2936|      3|	struct pkcs15_any_object *cert_any_obj = NULL;
 2937|      3|	struct sc_pkcs15_object	*cert_obj = NULL;
 2938|      3|	CK_CERTIFICATE_TYPE	cert_type;
 2939|      3|	CK_BBOOL		bValue;
 2940|      3|	int			rc;
 2941|      3|	CK_RV rv;
 2942|      3|	char label[SC_PKCS15_MAX_LABEL_SIZE];
 2943|       |
 2944|      3|	memset(&args, 0, sizeof(args));
 2945|      3|	if (!p11card)
  ------------------
  |  Branch (2945:6): [True: 0, False: 3]
  ------------------
 2946|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2947|      3|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 2948|      3|	if (!fw_data)
  ------------------
  |  Branch (2948:6): [True: 0, False: 3]
  ------------------
 2949|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_CreateObject");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2950|      3|	if (!fw_data->p15_card)
  ------------------
  |  Branch (2950:6): [True: 0, False: 3]
  ------------------
 2951|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2952|       |
 2953|       |	/* Get the key type */
 2954|      3|	rv = attr_find(pTemplate, ulCount, CKA_CERTIFICATE_TYPE,
  ------------------
  |  |  145|      3|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
 2955|      3|				&cert_type, NULL);
 2956|      3|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      3|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2956:6): [True: 0, False: 3]
  ------------------
 2957|      0|		return rv;
 2958|      3|	if (cert_type != CKC_X_509)
  ------------------
  |  |  303|      3|#define CKC_X_509 0x00000000UL
  ------------------
  |  Branch (2958:6): [True: 0, False: 3]
  ------------------
 2959|      0|		return CKR_ATTRIBUTE_VALUE_INVALID;
  ------------------
  |  | 1099|      0|#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013UL
  ------------------
 2960|       |
 2961|     16|	while (ulCount--) {
  ------------------
  |  Branch (2961:9): [True: 15, False: 1]
  ------------------
 2962|     15|		CK_ATTRIBUTE_PTR attr = pTemplate++;
 2963|       |
 2964|     15|		switch (attr->type) {
 2965|       |		/* Skip attrs we already know or don't care for */
 2966|      3|		case CKA_CLASS:
  ------------------
  |  |  137|      3|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (2966:3): [True: 3, False: 12]
  ------------------
 2967|      3|			break;
 2968|      3|		case CKA_PRIVATE:
  ------------------
  |  |  139|      3|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (2968:3): [True: 3, False: 12]
  ------------------
 2969|      3|			attr_extract(attr, &bValue, NULL);
 2970|      3|			if (bValue) {
  ------------------
  |  Branch (2970:8): [True: 2, False: 1]
  ------------------
 2971|      2|				rv = CKR_TEMPLATE_INCONSISTENT;
  ------------------
  |  | 1143|      2|#define CKR_TEMPLATE_INCONSISTENT 0x000000D1UL
  ------------------
 2972|      2|				goto out;
 2973|      2|			}
 2974|      1|			break;
 2975|      1|		case CKA_LABEL:
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (2975:3): [True: 0, False: 15]
  ------------------
 2976|      0|			args.label = set_cka_label(attr, label);
 2977|      0|			break;
 2978|      0|		case CKA_ID:
  ------------------
  |  |  161|      0|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (2978:3): [True: 0, False: 15]
  ------------------
 2979|      0|			args.id.len = sizeof(args.id.value);
 2980|      0|			rv = attr_extract(attr, args.id.value, &args.id.len);
 2981|      0|			if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2981:8): [True: 0, False: 0]
  ------------------
 2982|      0|				goto out;
 2983|      0|			break;
 2984|      3|		case CKA_VALUE:
  ------------------
  |  |  143|      3|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (2984:3): [True: 3, False: 12]
  ------------------
 2985|      3|			args.der_encoded.len = attr->ulValueLen;
 2986|      3|			args.der_encoded.value = (u8 *) attr->pValue;
 2987|      3|			break;
 2988|      6|		default:
  ------------------
  |  Branch (2988:3): [True: 6, False: 9]
  ------------------
 2989|       |			/* ignore unknown attrs, or flag error? */
 2990|      6|			continue;
 2991|     15|		}
 2992|     15|	}
 2993|       |
 2994|      1|	if (args.der_encoded.len == 0) {
  ------------------
  |  Branch (2994:6): [True: 0, False: 1]
  ------------------
 2995|      0|		rv = CKR_TEMPLATE_INCOMPLETE;
  ------------------
  |  | 1142|      0|#define CKR_TEMPLATE_INCOMPLETE 0x000000D0UL
  ------------------
 2996|      0|		goto out;
 2997|      0|	}
 2998|       |
 2999|      1|	rc = sc_pkcs15init_store_certificate(fw_data->p15_card, profile, &args, &cert_obj);
 3000|      1|	if (rc < 0) {
  ------------------
  |  Branch (3000:6): [True: 1, False: 0]
  ------------------
 3001|      1|		rv = sc_to_cryptoki_error(rc, "C_CreateObject");
 3002|      1|		goto out;
 3003|      1|	}
 3004|       |	/* Create a new pkcs11 object for it */
 3005|      0|	__pkcs15_create_cert_object(fw_data, cert_obj, &cert_any_obj);
 3006|      0|	pkcs15_add_object(slot, cert_any_obj, phObject);
 3007|       |
 3008|      0|	rv = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3009|       |
 3010|      3|out:	return rv;
 3011|      0|}
framework-pkcs15.c:pkcs15_create_data:
 3018|     36|{
 3019|     36|	struct sc_pkcs11_card *p11card = slot->p11card;
 3020|     36|	struct pkcs15_fw_data *fw_data = NULL;
 3021|     36|	struct sc_pkcs15init_dataargs args;
 3022|     36|	struct pkcs15_any_object *data_any_obj = NULL;
 3023|     36|	struct sc_pkcs15_object	*data_obj = NULL;
 3024|     36|	struct sc_pkcs15_auth_info *pin = NULL;
 3025|     36|	CK_BBOOL bValue;
 3026|     36|	int rc;
 3027|     36|	CK_RV rv;
 3028|     36|	char label[SC_PKCS15_MAX_LABEL_SIZE];
 3029|       |
 3030|     36|	memset(&args, 0, sizeof(args));
 3031|     36|	sc_init_oid(&args.app_oid);
 3032|       |
 3033|     36|	if (!p11card)
  ------------------
  |  Branch (3033:6): [True: 0, False: 36]
  ------------------
 3034|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3035|     36|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 3036|     36|	if (!fw_data)
  ------------------
  |  Branch (3036:6): [True: 0, False: 36]
  ------------------
 3037|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_CreateObject");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3038|     36|	if (!fw_data->p15_card)
  ------------------
  |  Branch (3038:6): [True: 0, False: 36]
  ------------------
 3039|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3040|       |
 3041|    197|	while (ulCount--) {
  ------------------
  |  Branch (3041:9): [True: 171, False: 26]
  ------------------
 3042|    171|		CK_ATTRIBUTE_PTR attr = pTemplate++;
 3043|       |
 3044|    171|		switch (attr->type) {
 3045|       |		/* Skip attrs we already know or don't care for */
 3046|     36|		case CKA_CLASS:
  ------------------
  |  |  137|     36|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (3046:3): [True: 36, False: 135]
  ------------------
 3047|     36|			break;
 3048|     36|		case CKA_PRIVATE:
  ------------------
  |  |  139|     36|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (3048:3): [True: 36, False: 135]
  ------------------
 3049|     36|			attr_extract(attr, &bValue, NULL);
 3050|     36|			if (bValue) {
  ------------------
  |  Branch (3050:8): [True: 27, False: 9]
  ------------------
 3051|     27|				pin = slot_data_auth_info(slot->fw_data);
  ------------------
  |  |   52|     27|#define slot_data_auth_info(p)	(((p) && slot_data_auth(p))? \
  |  |  ------------------
  |  |  |  |   51|     27|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     27|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 27, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     27|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:27): [True: 26, False: 1]
  |  |  |  |  |  Branch (51:29): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (52:34): [True: 27, False: 0]
  |  |  ------------------
  |  |   53|     27|		(struct sc_pkcs15_auth_info *) slot_data_auth(p)->data : NULL)
  |  |  ------------------
  |  |  |  |   51|     26|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     26|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 26, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     26|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:29): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3052|     27|				if (pin == NULL) {
  ------------------
  |  Branch (3052:9): [True: 1, False: 26]
  ------------------
 3053|      1|					rv = CKR_TEMPLATE_INCOMPLETE;
  ------------------
  |  | 1142|      1|#define CKR_TEMPLATE_INCOMPLETE 0x000000D0UL
  ------------------
 3054|      1|					goto out;
 3055|      1|				}
 3056|     26|				args.auth_id = pin->auth_id;
 3057|     26|			}
 3058|     35|			break;
 3059|     35|		case CKA_LABEL:
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (3059:3): [True: 0, False: 171]
  ------------------
 3060|      0|			args.label = set_cka_label(attr, label);
 3061|      0|			break;
 3062|      0|		case CKA_ID:
  ------------------
  |  |  161|      0|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (3062:3): [True: 0, False: 171]
  ------------------
 3063|      0|			args.id.len = sizeof(args.id.value);
 3064|      0|			rv = attr_extract(attr, args.id.value, &args.id.len);
 3065|      0|			if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3065:8): [True: 0, False: 0]
  ------------------
 3066|      0|				goto out;
 3067|      0|			break;
 3068|      0|		case CKA_APPLICATION:
  ------------------
  |  |  142|      0|#define CKA_APPLICATION 0x00000010UL
  ------------------
  |  Branch (3068:3): [True: 0, False: 171]
  ------------------
 3069|      0|			args.app_label = (char *) attr->pValue;
 3070|      0|			break;
 3071|     27|		case CKA_OBJECT_ID:
  ------------------
  |  |  144|     27|#define CKA_OBJECT_ID 0x00000012UL
  ------------------
  |  Branch (3071:3): [True: 27, False: 144]
  ------------------
 3072|     27|			if (sc_asn1_decode_object_id(attr->pValue, attr->ulValueLen, &args.app_oid)) {
  ------------------
  |  Branch (3072:8): [True: 9, False: 18]
  ------------------
 3073|      9|				rv = CKR_ATTRIBUTE_VALUE_INVALID;
  ------------------
  |  | 1099|      9|#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013UL
  ------------------
 3074|      9|				goto out;
 3075|      9|			}
 3076|     18|			break;
 3077|     36|		case CKA_VALUE:
  ------------------
  |  |  143|     36|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (3077:3): [True: 36, False: 135]
  ------------------
 3078|     36|			args.der_encoded.len = attr->ulValueLen;
 3079|     36|			args.der_encoded.value = (u8 *) attr->pValue;
 3080|     36|			break;
 3081|     36|		default:
  ------------------
  |  Branch (3081:3): [True: 36, False: 135]
  ------------------
 3082|       |			/* ignore unknown attrs, or flag error? */
 3083|     36|			continue;
 3084|    171|		}
 3085|    171|	}
 3086|       |
 3087|     26|	rc = sc_pkcs15init_store_data_object(fw_data->p15_card, profile, &args, &data_obj);
 3088|     26|	if (rc < 0) {
  ------------------
  |  Branch (3088:6): [True: 26, False: 0]
  ------------------
 3089|     26|		rv = sc_to_cryptoki_error(rc, "C_CreateObject");
 3090|     26|		goto out;
 3091|     26|	}
 3092|       |	/* Create a new pkcs11 object for it */
 3093|      0|	__pkcs15_create_data_object(fw_data, data_obj, &data_any_obj);
 3094|      0|	pkcs15_add_object(slot, data_any_obj, phObject);
 3095|       |
 3096|      0|	rv = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3097|       |
 3098|     36|out:	return rv;
 3099|      0|}
framework-pkcs15.c:pkcs15_create_secret_key:
 2551|     16|{
 2552|     16|	struct sc_pkcs11_card *p11card = slot->p11card;
 2553|     16|	struct pkcs15_fw_data *fw_data = NULL;
 2554|     16|	struct sc_pkcs15init_skeyargs args;
 2555|     16|	struct pkcs15_any_object *key_any_obj = NULL;
 2556|     16|	struct sc_pkcs15_object	*key_obj = NULL;
 2557|     16|	struct sc_pkcs15_auth_info *pin = NULL;
 2558|     16|	struct sc_pkcs15_skey_info *skey_info;
 2559|     16|	CK_KEY_TYPE key_type;
 2560|     16|	CK_BBOOL _token = FALSE;
  ------------------
  |  |   48|     16|#define FALSE 0
  ------------------
 2561|     16|	CK_RV rv;
 2562|     16|	int rc;
 2563|     16|	char label[SC_PKCS15_MAX_LABEL_SIZE];
 2564|     16|	CK_BBOOL temp_object = FALSE;
  ------------------
  |  |   48|     16|#define FALSE 0
  ------------------
 2565|       |
 2566|     16|	memset(&args, 0, sizeof(args));
 2567|     16|	if (!p11card)
  ------------------
  |  Branch (2567:6): [True: 0, False: 16]
  ------------------
 2568|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2569|     16|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 2570|     16|	if (!fw_data)
  ------------------
  |  Branch (2570:6): [True: 0, False: 16]
  ------------------
 2571|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_CreateObject");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2572|     16|	if (!fw_data->p15_card)
  ------------------
  |  Branch (2572:6): [True: 0, False: 16]
  ------------------
 2573|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_CreateObject");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2574|       |
 2575|       |	/* Get the key type */
 2576|     16|	rv = attr_find(pTemplate, ulCount, CKA_KEY_TYPE, &key_type, NULL);
  ------------------
  |  |  159|     16|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
 2577|     16|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     16|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2577:6): [True: 1, False: 15]
  ------------------
 2578|      1|		return rv;
 2579|       |
 2580|       |	/* CKA_TOKEN defaults to false */
 2581|     15|	rv = attr_find(pTemplate, ulCount, CKA_TOKEN, &_token, NULL);
  ------------------
  |  |  138|     15|#define CKA_TOKEN 0x00000001UL
  ------------------
 2582|     15|	if (rv != CKR_TEMPLATE_INCOMPLETE && rv != CKR_OK) {
  ------------------
  |  | 1142|     30|#define CKR_TEMPLATE_INCOMPLETE 0x000000D0UL
  ------------------
              	if (rv != CKR_TEMPLATE_INCOMPLETE && rv != CKR_OK) {
  ------------------
  |  | 1086|     15|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2582:6): [True: 15, False: 0]
  |  Branch (2582:39): [True: 0, False: 15]
  ------------------
 2583|      0|		return rv;
 2584|      0|	}
 2585|       |
 2586|       |	/* See if the "slot" is pin protected. If so, get the PIN id */
 2587|     15|	if ((pin = slot_data_auth_info(slot->fw_data)) != NULL)
  ------------------
  |  |   52|     15|#define slot_data_auth_info(p)	(((p) && slot_data_auth(p))? \
  |  |  ------------------
  |  |  |  |   51|     15|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     15|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 15, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     15|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:27): [True: 15, False: 0]
  |  |  |  |  |  Branch (51:29): [True: 15, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (52:34): [True: 15, False: 0]
  |  |  ------------------
  |  |   53|     15|		(struct sc_pkcs15_auth_info *) slot_data_auth(p)->data : NULL)
  |  |  ------------------
  |  |  |  |   51|     15|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     15|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 15, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|     15|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:29): [True: 15, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (2587:6): [True: 15, False: 0]
  ------------------
 2588|     15|		args.auth_id = pin->auth_id;
 2589|       |
 2590|     15|	switch (key_type) {
 2591|      6|		case CKK_GENERIC_SECRET:
  ------------------
  |  |  470|      6|#define CKK_GENERIC_SECRET 0x00000010UL
  ------------------
  |  Branch (2591:3): [True: 6, False: 9]
  ------------------
 2592|      6|			args.algorithm = SC_ALGORITHM_UNDEFINED;
  ------------------
  |  |   80|      6|#define SC_ALGORITHM_UNDEFINED		68	/* used with CKK_GENERIC_SECRET type keys */
  ------------------
 2593|      6|			break;
 2594|      3|		case CKK_AES:
  ------------------
  |  |  485|      3|#define CKK_AES 0x0000001FUL
  ------------------
  |  Branch (2594:3): [True: 3, False: 12]
  ------------------
 2595|      3|			args.algorithm = SC_ALGORITHM_AES;
  ------------------
  |  |   79|      3|#define SC_ALGORITHM_AES		67
  ------------------
 2596|      3|			break;
 2597|      2|		case CKK_DES3:
  ------------------
  |  |  475|      2|#define CKK_DES3 0x00000015UL
  ------------------
  |  Branch (2597:3): [True: 2, False: 13]
  ------------------
 2598|      2|			args.algorithm = SC_ALGORITHM_3DES;
  ------------------
  |  |   77|      2|#define SC_ALGORITHM_3DES		65
  ------------------
 2599|      2|			break;
 2600|      3|		case CKK_DES:
  ------------------
  |  |  473|      3|#define CKK_DES 0x00000013UL
  ------------------
  |  Branch (2600:3): [True: 3, False: 12]
  ------------------
 2601|      3|			args.algorithm = SC_ALGORITHM_DES;
  ------------------
  |  |   76|      3|#define SC_ALGORITHM_DES		64
  ------------------
 2602|      3|			break;
 2603|      1|		default:
  ------------------
  |  Branch (2603:3): [True: 1, False: 14]
  ------------------
 2604|      1|			return CKR_ATTRIBUTE_VALUE_INVALID;
  ------------------
  |  | 1099|      1|#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013UL
  ------------------
 2605|     15|	}
 2606|       |
 2607|    186|	while (ulCount--) {
  ------------------
  |  Branch (2607:9): [True: 172, False: 14]
  ------------------
 2608|    172|		CK_ATTRIBUTE_PTR attr = pTemplate++;
 2609|       |
 2610|    172|		switch (attr->type) {
 2611|       |		/* Skip attrs we already know or don't care for */
 2612|     14|		case CKA_CLASS:
  ------------------
  |  |  137|     14|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (2612:3): [True: 14, False: 158]
  ------------------
 2613|     28|		case CKA_KEY_TYPE:
  ------------------
  |  |  159|     28|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (2613:3): [True: 14, False: 158]
  ------------------
 2614|     37|		case CKA_MODULUS_BITS:
  ------------------
  |  |  175|     37|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
  |  Branch (2614:3): [True: 9, False: 163]
  ------------------
 2615|     51|		case CKA_PRIVATE:
  ------------------
  |  |  139|     51|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (2615:3): [True: 14, False: 158]
  ------------------
 2616|     51|			break;
 2617|      5|		case CKA_LABEL:
  ------------------
  |  |  140|      5|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (2617:3): [True: 5, False: 167]
  ------------------
 2618|      5|			args.label = set_cka_label(attr, label);
 2619|      5|			break;
 2620|      4|		case CKA_ID:
  ------------------
  |  |  161|      4|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (2620:3): [True: 4, False: 168]
  ------------------
 2621|      4|			args.id.len = sizeof(args.id.value);
 2622|      4|			rv = attr_extract(attr, args.id.value, &args.id.len);
 2623|      4|			if (rv != CKR_OK)
  ------------------
  |  | 1086|      4|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2623:8): [True: 0, False: 4]
  ------------------
 2624|      0|				goto out;
 2625|      4|			break;
 2626|      4|		case CKA_VALUE_LEN:
  ------------------
  |  |  191|      0|#define CKA_VALUE_LEN 0x00000161UL
  ------------------
  |  Branch (2626:3): [True: 0, False: 172]
  ------------------
 2627|      0|			attr_extract(attr, &args.value_len, NULL);
 2628|      0|			break;
 2629|      0|		case CKA_VALUE:
  ------------------
  |  |  143|      0|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (2629:3): [True: 0, False: 172]
  ------------------
 2630|      0|			if (attr->pValue) {
  ------------------
  |  Branch (2630:8): [True: 0, False: 0]
  ------------------
 2631|      0|				free(args.key.data);
 2632|      0|				args.key.data = calloc(1,attr->ulValueLen);
 2633|      0|				if (!args.key.data)
  ------------------
  |  Branch (2633:9): [True: 0, False: 0]
  ------------------
 2634|      0|					return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 2635|      0|				memcpy(args.key.data, attr->pValue, attr->ulValueLen);
 2636|      0|				args.key.data_len = attr->ulValueLen;
 2637|      0|			}
 2638|      0|			break;
 2639|      8|		case CKA_DECRYPT:
  ------------------
  |  |  164|      8|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (2639:3): [True: 8, False: 164]
  ------------------
 2640|      8|			args.usage |= pkcs15_check_bool_cka(attr, SC_PKCS15_PRKEY_USAGE_DECRYPT);
  ------------------
  |  |  306|      8|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
 2641|      8|			break;
 2642|      7|		case CKA_ENCRYPT:
  ------------------
  |  |  163|      7|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (2642:3): [True: 7, False: 165]
  ------------------
 2643|      7|			args.usage |= pkcs15_check_bool_cka(attr, SC_PKCS15_PRKEY_USAGE_ENCRYPT);
  ------------------
  |  |  305|      7|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
 2644|      7|			break;
 2645|      9|		case CKA_WRAP:
  ------------------
  |  |  165|      9|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (2645:3): [True: 9, False: 163]
  ------------------
 2646|      9|			args.usage |= pkcs15_check_bool_cka(attr, SC_PKCS15_PRKEY_USAGE_WRAP);
  ------------------
  |  |  309|      9|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
 2647|      9|			break;
 2648|     12|		case CKA_UNWRAP:
  ------------------
  |  |  166|     12|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (2648:3): [True: 12, False: 160]
  ------------------
 2649|     12|			args.usage |= pkcs15_check_bool_cka(attr, SC_PKCS15_PRKEY_USAGE_UNWRAP);
  ------------------
  |  |  310|     12|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
 2650|     12|			break;
 2651|      9|		case CKA_EXTRACTABLE:
  ------------------
  |  |  192|      9|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (2651:3): [True: 9, False: 163]
  ------------------
 2652|      9|			if (pkcs15_check_bool_cka(attr, 1))
  ------------------
  |  Branch (2652:8): [True: 8, False: 1]
  ------------------
 2653|      8|				args.access_flags |= SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|      8|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
 2654|      9|			break;
 2655|      0|		case CKA_OPENSC_ALWAYS_AUTH_ANY_OBJECT:
  ------------------
  |  |   26|      0|#define CKA_OPENSC_ALWAYS_AUTH_ANY_OBJECT (CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 3UL)
  |  |  ------------------
  |  |  |  |  289|      0|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_OPENSC_ALWAYS_AUTH_ANY_OBJECT (CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 3UL)
  |  |  ------------------
  |  |  |  |   12|      0|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
  |  Branch (2655:3): [True: 0, False: 172]
  ------------------
 2656|      0|			args.user_consent = (int) (pkcs15_check_bool_cka(attr, 1));
 2657|      0|			break;
 2658|     67|		default:
  ------------------
  |  Branch (2658:3): [True: 67, False: 105]
  ------------------
 2659|       |			/* ignore unknown attrs, or flag error? */
 2660|     67|			continue;
 2661|    172|		}
 2662|    172|	}
 2663|       |
 2664|       |	/* If creating a PKCS#11 session object, i.e. one that is only in memory */
 2665|     14|	if (_token == FALSE && (fw_data->p15_card->card->caps & SC_CARD_CAP_ONCARD_SESSION_OBJECTS) == 0) {
  ------------------
  |  |   48|     28|#define FALSE 0
  ------------------
              	if (_token == FALSE && (fw_data->p15_card->card->caps & SC_CARD_CAP_ONCARD_SESSION_OBJECTS) == 0) {
  ------------------
  |  |  569|     14|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
  |  Branch (2665:6): [True: 14, False: 0]
  |  Branch (2665:25): [True: 14, False: 0]
  ------------------
 2666|       |
 2667|       |		/* TODO Have 3 choices as to how to create the object.
 2668|       |		 * (1)create a sc_pkcs15init_store_secret_key routine like the others
 2669|       |		 * (2)use the sc_pkcs15emu_ routines
 2670|       |		 * (3)do it inline here (Will do this for now)
 2671|       |		 */
 2672|       |
 2673|     14|		key_obj = calloc(1, sizeof(sc_pkcs15_object_t));
 2674|     14|		if (key_obj == NULL) {
  ------------------
  |  Branch (2674:7): [True: 0, False: 14]
  ------------------
 2675|      0|			rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 2676|      0|			goto out;
 2677|      0|		}
 2678|     14|		temp_object = TRUE;
  ------------------
  |  |   51|     14|#define TRUE 1
  ------------------
 2679|     14|		key_obj->type = SC_PKCS15_TYPE_SKEY;
  ------------------
  |  |  432|     14|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
 2680|       |
 2681|     14|		if (args.id.len)
  ------------------
  |  Branch (2681:7): [True: 4, False: 10]
  ------------------
 2682|      4|			memcpy(key_obj->label, args.id.value, args.id.len);
 2683|       |
 2684|     14|		key_obj->flags = 2; /* TODO not sure what these mean */
 2685|       |
 2686|     14|		skey_info = calloc(1, sizeof(sc_pkcs15_skey_info_t));
 2687|     14|		if (skey_info == NULL) {
  ------------------
  |  Branch (2687:7): [True: 0, False: 14]
  ------------------
 2688|      0|			rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 2689|      0|			goto out;
 2690|      0|		}
 2691|     14|		key_obj->data = skey_info;
 2692|     14|		skey_info->usage = (unsigned int) args.usage;
 2693|     14|		skey_info->native = 0; /* card can not use this */
 2694|     14|		skey_info->access_flags = 0; /* looks like not needed */
 2695|     14|		skey_info->key_type = key_type; /* PKCS#11 CKK_* */
 2696|     14|		skey_info->data.value = args.key.data;
 2697|     14|		skey_info->data.len = args.key.data_len;
 2698|     14|		skey_info->value_len = args.value_len * 8; /* key length comes in number of bytes, use length in bits in PKCS#15. */
 2699|     14|		args.key.data = NULL;
 2700|     14|		key_obj->session_object = 1;
 2701|     14|	}
 2702|      0|	else {
 2703|      0|		if(_token == FALSE)
  ------------------
  |  |   48|      0|#define FALSE 0
  ------------------
  |  Branch (2703:6): [True: 0, False: 0]
  ------------------
 2704|      0|			args.session_object = 1;	/* store the object on card for duration of the session. */
 2705|       |
 2706|      0|		args.value_len = args.value_len * 8; /* CKA_VALUE_LEN is number of bytes, PKCS#15 needs key length in bits */
 2707|      0|		rc = sc_pkcs15init_store_secret_key(fw_data->p15_card, profile, &args, &key_obj);
 2708|      0|		if (rc < 0) {
  ------------------
  |  Branch (2708:7): [True: 0, False: 0]
  ------------------
 2709|      0|			rv = sc_to_cryptoki_error(rc, "C_CreateObject");
 2710|      0|			goto out;
 2711|      0|		}
 2712|      0|	}
 2713|       |
 2714|       |	/* Create a new pkcs11 object for it */
 2715|     14|	__pkcs15_create_secret_key_object(fw_data, key_obj, &key_any_obj);
 2716|     14|	pkcs15_add_object(slot, key_any_obj, phObject);
 2717|       |
 2718|     14|	rv = CKR_OK;
  ------------------
  |  | 1086|     14|#define CKR_OK 0x00000000UL
  ------------------
 2719|       |
 2720|     14|out:
 2721|     14|	free(args.key.data); /* if allocated */
 2722|       |
 2723|       |	/* on error, free key_obj, unless it's created by pkcs15init. if OK, let it live as part of key_any_obj. */
 2724|     14|	if (rv != CKR_OK && temp_object)
  ------------------
  |  | 1086|     28|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (2724:6): [True: 0, False: 14]
  |  Branch (2724:22): [True: 0, False: 0]
  ------------------
 2725|      0|		free(key_obj); /* do not free if the object was created by pkcs15init. It will be freed in C_Finalize */
 2726|     14|	return rv;
 2727|     14|}
framework-pkcs15.c:pkcs15_gen_keypair:
 3368|    286|{
 3369|    286|	struct sc_profile *profile = NULL;
 3370|    286|	struct sc_pkcs11_card *p11card = slot->p11card;
 3371|    286|	struct sc_pkcs15_auth_info *pin = NULL;
 3372|    286|	struct sc_aid *aid = NULL;
 3373|    286|	struct pkcs15_fw_data *fw_data = NULL;
 3374|    286|	struct sc_pkcs15init_keygen_args keygen_args;
 3375|    286|	struct sc_pkcs15_object	 *priv_key_obj = NULL, *pub_key_obj = NULL;
 3376|    286|	struct pkcs15_any_object *priv_any_obj = NULL, *pub_any_obj = NULL;
 3377|    286|	struct pkcs15_prkey_object *priv_prk_obj = NULL;
 3378|    286|	struct sc_pkcs15_id id;
 3379|    286|	size_t		len;
 3380|    286|	CK_KEY_TYPE	keytype;
 3381|    286|	CK_ULONG	keybits = 0;
 3382|    286|	char		pub_label[SC_PKCS15_MAX_LABEL_SIZE];
 3383|    286|	char		priv_label[SC_PKCS15_MAX_LABEL_SIZE];
 3384|    286|	int		rc;
 3385|    286|	CK_RV rv = CKR_OK;
  ------------------
  |  | 1086|    286|#define CKR_OK 0x00000000UL
  ------------------
 3386|    286|	CK_BBOOL always_auth = CK_FALSE;
  ------------------
  |  |   35|    286|#define CK_FALSE 0
  ------------------
 3387|    286|	CK_BBOOL sensitive = CK_FALSE;
  ------------------
  |  |   35|    286|#define CK_FALSE 0
  ------------------
 3388|    286|	CK_BBOOL extractable = CK_FALSE;
  ------------------
  |  |   35|    286|#define CK_FALSE 0
  ------------------
 3389|       |
 3390|    286|	sc_log(context, "Key pair generation, mech = 0x%0lx",
  ------------------
  |  |   71|    286|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3391|    286|		   pMechanism->mechanism);
 3392|       |
 3393|    286|	if (pMechanism->mechanism != CKM_RSA_PKCS_KEY_PAIR_GEN
  ------------------
  |  |  538|    572|#define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000UL
  ------------------
  |  Branch (3393:6): [True: 277, False: 9]
  ------------------
 3394|    277|			&& pMechanism->mechanism != CKM_GOSTR3410_KEY_PAIR_GEN
  ------------------
  |  |  908|    563|#define CKM_GOSTR3410_KEY_PAIR_GEN 0x00001200UL
  ------------------
  |  Branch (3394:7): [True: 276, False: 1]
  ------------------
 3395|    276|			&& pMechanism->mechanism != CKM_EC_KEY_PAIR_GEN
  ------------------
  |  |  859|    562|#define CKM_EC_KEY_PAIR_GEN 0x00001040UL
  ------------------
  |  Branch (3395:7): [True: 275, False: 1]
  ------------------
 3396|    275|			&& pMechanism->mechanism != CKM_EC_EDWARDS_KEY_PAIR_GEN
  ------------------
  |  |  988|    561|#define CKM_EC_EDWARDS_KEY_PAIR_GEN 0x00001055UL
  ------------------
  |  Branch (3396:7): [True: 273, False: 2]
  ------------------
 3397|    273|			&& pMechanism->mechanism != CKM_EC_MONTGOMERY_KEY_PAIR_GEN)
  ------------------
  |  |  989|    273|#define CKM_EC_MONTGOMERY_KEY_PAIR_GEN 0x00001056UL
  ------------------
  |  Branch (3397:7): [True: 272, False: 1]
  ------------------
 3398|    272|		return CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|    272|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
 3399|       |
 3400|     14|	if (!p11card)
  ------------------
  |  Branch (3400:6): [True: 0, False: 14]
  ------------------
 3401|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GenerateKeyPair");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3402|     14|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 3403|     14|	if (!fw_data)
  ------------------
  |  Branch (3403:6): [True: 0, False: 14]
  ------------------
 3404|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GenerateKeyPair");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3405|     14|	if (!fw_data->p15_card)
  ------------------
  |  Branch (3405:6): [True: 5, False: 9]
  ------------------
 3406|      5|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GenerateKeyPair");
  ------------------
  |  |   60|      5|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3407|       |
 3408|      9|	rc = sc_lock(p11card->card);
 3409|      9|	if (rc < 0)
  ------------------
  |  Branch (3409:6): [True: 0, False: 9]
  ------------------
 3410|      0|		return sc_to_cryptoki_error(rc, "C_GenerateKeyPair");
 3411|       |
 3412|      9|	rc = sc_pkcs15init_bind(p11card->card, "pkcs15", NULL, slot->app_info, &profile);
 3413|      9|	if (rc < 0) {
  ------------------
  |  Branch (3413:6): [True: 9, False: 0]
  ------------------
 3414|      9|		sc_unlock(p11card->card);
 3415|      9|		return sc_to_cryptoki_error(rc, "C_GenerateKeyPair");
 3416|      9|	}
 3417|       |
 3418|      0|	if(slot->app_info)
  ------------------
  |  Branch (3418:5): [True: 0, False: 0]
  ------------------
 3419|      0|		aid = &slot->app_info->aid;
 3420|       |
 3421|      0|	rc = sc_pkcs15init_finalize_profile(p11card->card, profile, aid);
 3422|      0|	if (rc != CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3422:6): [True: 0, False: 0]
  ------------------
 3423|      0|		sc_log(context, "Cannot finalize profile: %i", rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3424|      0|		return sc_to_cryptoki_error(rc, "C_GenerateKeyPair");
 3425|      0|	}
 3426|       |
 3427|      0|	memset(&keygen_args, 0, sizeof(keygen_args));
 3428|       |
 3429|       |	/* 1. Convert the pkcs11 attributes to pkcs15init args */
 3430|       |
 3431|      0|	if ((pin = slot_data_auth_info(slot->fw_data)) != NULL)
  ------------------
  |  |   52|      0|#define slot_data_auth_info(p)	(((p) && slot_data_auth(p))? \
  |  |  ------------------
  |  |  |  |   51|      0|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|      0|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 0, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|      0|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:27): [True: 0, False: 0]
  |  |  |  |  |  Branch (51:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (52:34): [True: 0, False: 0]
  |  |  ------------------
  |  |   53|      0|		(struct sc_pkcs15_auth_info *) slot_data_auth(p)->data : NULL)
  |  |  ------------------
  |  |  |  |   51|      0|#define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|      0|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (50:23): [True: 0, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define slot_data_auth(p)	(((p) && slot_data(p)) ? slot_data(p)->auth_obj : NULL)
  |  |  |  |  ------------------
  |  |  |  |  |  |   50|      0|#define slot_data(p)		((struct pkcs15_slot_data *) (p))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (51:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (3431:6): [True: 0, False: 0]
  ------------------
 3432|      0|		keygen_args.prkey_args.auth_id = pin->auth_id;
 3433|       |
 3434|      0|	rv = attr_find2(pPubTpl, ulPubCnt, pPrivTpl, ulPrivCnt, CKA_KEY_TYPE,
  ------------------
  |  |  159|      0|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
 3435|      0|		&keytype, NULL);
 3436|      0|	if (rv != CKR_OK && pMechanism->mechanism == CKM_RSA_PKCS_KEY_PAIR_GEN)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	if (rv != CKR_OK && pMechanism->mechanism == CKM_RSA_PKCS_KEY_PAIR_GEN)
  ------------------
  |  |  538|      0|#define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000UL
  ------------------
  |  Branch (3436:6): [True: 0, False: 0]
  |  Branch (3436:22): [True: 0, False: 0]
  ------------------
 3437|      0|		keytype = CKK_RSA;
  ------------------
  |  |  464|      0|#define CKK_RSA 0x00000000UL
  ------------------
 3438|      0|	else if (rv != CKR_OK && pMechanism->mechanism == CKM_EC_KEY_PAIR_GEN)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	else if (rv != CKR_OK && pMechanism->mechanism == CKM_EC_KEY_PAIR_GEN)
  ------------------
  |  |  859|      0|#define CKM_EC_KEY_PAIR_GEN 0x00001040UL
  ------------------
  |  Branch (3438:11): [True: 0, False: 0]
  |  Branch (3438:27): [True: 0, False: 0]
  ------------------
 3439|      0|		keytype = CKK_EC;
  ------------------
  |  |  467|      0|#define CKK_EC 0x00000003UL
  ------------------
 3440|      0|	else if (rv != CKR_OK && pMechanism->mechanism == CKM_EC_EDWARDS_KEY_PAIR_GEN)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	else if (rv != CKR_OK && pMechanism->mechanism == CKM_EC_EDWARDS_KEY_PAIR_GEN)
  ------------------
  |  |  988|      0|#define CKM_EC_EDWARDS_KEY_PAIR_GEN 0x00001055UL
  ------------------
  |  Branch (3440:11): [True: 0, False: 0]
  |  Branch (3440:27): [True: 0, False: 0]
  ------------------
 3441|      0|		keytype = CKK_EC_EDWARDS;
  ------------------
  |  |  518|      0|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
 3442|      0|	else if (rv != CKR_OK && pMechanism->mechanism == CKM_EC_MONTGOMERY_KEY_PAIR_GEN)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	else if (rv != CKR_OK && pMechanism->mechanism == CKM_EC_MONTGOMERY_KEY_PAIR_GEN)
  ------------------
  |  |  989|      0|#define CKM_EC_MONTGOMERY_KEY_PAIR_GEN 0x00001056UL
  ------------------
  |  Branch (3442:11): [True: 0, False: 0]
  |  Branch (3442:27): [True: 0, False: 0]
  ------------------
 3443|      0|		keytype = CKK_EC_MONTGOMERY;
  ------------------
  |  |  519|      0|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
 3444|      0|	else if (rv != CKR_OK && pMechanism->mechanism == CKM_GOSTR3410_KEY_PAIR_GEN)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	else if (rv != CKR_OK && pMechanism->mechanism == CKM_GOSTR3410_KEY_PAIR_GEN)
  ------------------
  |  |  908|      0|#define CKM_GOSTR3410_KEY_PAIR_GEN 0x00001200UL
  ------------------
  |  Branch (3444:11): [True: 0, False: 0]
  |  Branch (3444:27): [True: 0, False: 0]
  ------------------
 3445|      0|		keytype = CKK_GOSTR3410;
  ------------------
  |  |  502|      0|#define CKK_GOSTR3410 0x00000030UL
  ------------------
 3446|      0|	else if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3446:11): [True: 0, False: 0]
  ------------------
 3447|      0|		goto kpgen_done;
 3448|       |
 3449|      0|	if (keytype == CKK_GOSTR3410)   {
  ------------------
  |  |  502|      0|#define CKK_GOSTR3410 0x00000030UL
  ------------------
  |  Branch (3449:6): [True: 0, False: 0]
  ------------------
 3450|      0|		keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
 3451|      0|		rv = set_gost3410_params(&keygen_args.prkey_args, NULL,
 3452|      0|				pPubTpl, ulPubCnt, pPrivTpl, ulPrivCnt);
 3453|      0|		if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3453:7): [True: 0, False: 0]
  ------------------
 3454|      0|			goto kpgen_done;
 3455|      0|		keybits = SC_PKCS15_GOSTR3410_KEYSIZE;
  ------------------
  |  |  326|      0|#define SC_PKCS15_GOSTR3410_KEYSIZE             256
  ------------------
 3456|      0|	}
 3457|      0|	else if (keytype == CKK_RSA)   {
  ------------------
  |  |  464|      0|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (3457:11): [True: 0, False: 0]
  ------------------
 3458|       |		/* default value (CKA_KEY_TYPE isn't set) or CKK_RSA is set */
 3459|      0|		keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
 3460|       |
 3461|      0|		rv = attr_find2(pPubTpl, ulPubCnt, pPrivTpl, ulPrivCnt,	CKA_MODULUS_BITS, &keybits, NULL);
  ------------------
  |  |  175|      0|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
 3462|      0|		if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3462:7): [True: 0, False: 0]
  ------------------
 3463|      0|			keybits = 1024; /* Default key size */
 3464|       |		/* TODO: check allowed values of keybits */
 3465|      0|	} else if (keytype == CKK_EC || keytype == CKK_EC_EDWARDS || keytype == CKK_EC_MONTGOMERY) {
  ------------------
  |  |  467|      0|#define CKK_EC 0x00000003UL
  ------------------
              	} else if (keytype == CKK_EC || keytype == CKK_EC_EDWARDS || keytype == CKK_EC_MONTGOMERY) {
  ------------------
  |  |  518|      0|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
              	} else if (keytype == CKK_EC || keytype == CKK_EC_EDWARDS || keytype == CKK_EC_MONTGOMERY) {
  ------------------
  |  |  519|      0|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
  |  Branch (3465:13): [True: 0, False: 0]
  |  Branch (3465:34): [True: 0, False: 0]
  |  Branch (3465:63): [True: 0, False: 0]
  ------------------
 3466|      0|		struct sc_lv_data *der = &keygen_args.prkey_args.key.u.ec.params.der;
 3467|      0|		void *ptr = NULL;
 3468|       |
 3469|      0|		rv = attr_find_and_allocate_ptr(pPubTpl, ulPubCnt, CKA_EC_PARAMS, &ptr, &der->len);
  ------------------
  |  |  200|      0|#define CKA_EC_PARAMS 0x00000180UL
  ------------------
 3470|      0|		der->value = (unsigned char *) ptr;
 3471|      0|		if (rv != CKR_OK)   {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3471:7): [True: 0, False: 0]
  ------------------
 3472|      0|			sc_unlock(p11card->card);
 3473|      0|			return rv;
 3474|      0|		}
 3475|      0|		if (sc_pkcs15_fix_ec_parameters(context, &keygen_args.prkey_args.key.u.ec.params) < 0) {
  ------------------
  |  Branch (3475:7): [True: 0, False: 0]
  ------------------
 3476|      0|			rv = CKR_CURVE_NOT_SUPPORTED;
  ------------------
  |  | 1164|      0|#define CKR_CURVE_NOT_SUPPORTED 0x00000140UL
  ------------------
 3477|      0|			goto kpgen_done;
 3478|      0|		}
 3479|      0|	} else {
 3480|       |		/* CKA_KEY_TYPE is set, but keytype isn't correct */
 3481|      0|		rv = CKR_ATTRIBUTE_VALUE_INVALID;
  ------------------
  |  | 1099|      0|#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013UL
  ------------------
 3482|      0|		goto kpgen_done;
 3483|      0|	}
 3484|       |
 3485|      0|	if (keytype == CKK_EC) {
  ------------------
  |  |  467|      0|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (3485:6): [True: 0, False: 0]
  ------------------
 3486|      0|		keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
 3487|      0|	} else if (keytype == CKK_EC_EDWARDS) {
  ------------------
  |  |  518|      0|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
  |  Branch (3487:13): [True: 0, False: 0]
  ------------------
 3488|      0|		keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
 3489|      0|	} else if (keytype == CKK_EC_MONTGOMERY) {
  ------------------
  |  |  519|      0|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
  |  Branch (3489:13): [True: 0, False: 0]
  ------------------
 3490|      0|		keygen_args.prkey_args.key.algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 3491|      0|	}
 3492|       |
 3493|      0|	id.len = SC_PKCS15_MAX_ID_SIZE;
  ------------------
  |  |   36|      0|#define SC_PKCS15_MAX_ID_SIZE		255
  ------------------
 3494|      0|	rv = attr_find2(pPubTpl, ulPubCnt, pPrivTpl, ulPrivCnt,	CKA_ID, &id.value, &id.len);
  ------------------
  |  |  161|      0|#define CKA_ID 0x00000102UL
  ------------------
 3495|      0|	if (rv == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3495:6): [True: 0, False: 0]
  ------------------
 3496|      0|		keygen_args.prkey_args.id = id;
 3497|       |
 3498|      0|	len = sizeof(priv_label) - 1;
 3499|      0|	rv = attr_find(pPrivTpl, ulPrivCnt, CKA_LABEL, priv_label, &len);
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
 3500|      0|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3500:6): [True: 0, False: 0]
  ------------------
 3501|      0|		priv_label[len] = '\0';
 3502|      0|		keygen_args.prkey_args.label = priv_label;
 3503|      0|	}
 3504|      0|	len = sizeof(pub_label) - 1;
 3505|      0|	rv = attr_find(pPubTpl, ulPubCnt, CKA_LABEL, pub_label, &len);
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
 3506|      0|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3506:6): [True: 0, False: 0]
  ------------------
 3507|      0|		pub_label[len] = '\0';
 3508|      0|		keygen_args.pubkey_label = pub_label;
 3509|      0|	}
 3510|       |
 3511|      0|	rv = get_usage_privk(pPrivTpl, ulPrivCnt, &keygen_args.prkey_args.x509_usage, &keygen_args.prkey_args.usage);
 3512|      0|	if (rv == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3512:6): [True: 0, False: 0]
  ------------------
 3513|      0|		rv = get_usage_pubk(pPubTpl, ulPubCnt, &keygen_args.prkey_args.x509_usage, &keygen_args.pubkey_usage);
 3514|      0|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (3514:6): [True: 0, False: 0]
  ------------------
 3515|      0|		goto kpgen_done;
 3516|       |
 3517|      0|	len = sizeof(always_auth);
 3518|      0|	rv = attr_find(pPrivTpl, ulPrivCnt, CKA_ALWAYS_AUTHENTICATE, &always_auth, &len);
  ------------------
  |  |  202|      0|#define CKA_ALWAYS_AUTHENTICATE 0x00000202UL
  ------------------
 3519|      0|	if (rv == CKR_OK && always_auth == CK_TRUE) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	if (rv == CKR_OK && always_auth == CK_TRUE) {
  ------------------
  |  |   34|      0|#define CK_TRUE 1
  ------------------
  |  Branch (3519:6): [True: 0, False: 0]
  |  Branch (3519:22): [True: 0, False: 0]
  ------------------
 3520|      0|		keygen_args.prkey_args.user_consent = 1;
 3521|      0|	}
 3522|       |
 3523|       |	/* set EXTRACTABLE and SENSITIVESE flags */
 3524|      0|	len = sizeof(extractable);
 3525|      0|	rv = attr_find(pPrivTpl, ulPrivCnt, CKA_EXTRACTABLE, &extractable, &len);
  ------------------
  |  |  192|      0|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
 3526|      0|	if (rv == CKR_OK && extractable == CK_TRUE)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	if (rv == CKR_OK && extractable == CK_TRUE)
  ------------------
  |  |   34|      0|#define CK_TRUE 1
  ------------------
  |  Branch (3526:6): [True: 0, False: 0]
  |  Branch (3526:22): [True: 0, False: 0]
  ------------------
 3527|      0|		keygen_args.prkey_args.access_flags |= SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|      0|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
 3528|      0|	else
 3529|      0|		keygen_args.prkey_args.access_flags |= SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE;
  ------------------
  |  |  319|      0|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
 3530|       |
 3531|      0|	len = sizeof(sensitive);
 3532|      0|	rv = attr_find(pPrivTpl, ulPrivCnt, CKA_SENSITIVE, &sensitive, &len);
  ------------------
  |  |  162|      0|#define CKA_SENSITIVE 0x00000103UL
  ------------------
 3533|      0|	if (rv == CKR_OK && sensitive == CK_TRUE) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              	if (rv == CKR_OK && sensitive == CK_TRUE) {
  ------------------
  |  |   34|      0|#define CK_TRUE 1
  ------------------
  |  Branch (3533:6): [True: 0, False: 0]
  |  Branch (3533:22): [True: 0, False: 0]
  ------------------
 3534|      0|		keygen_args.prkey_args.access_flags |= SC_PKCS15_PRKEY_ACCESS_SENSITIVE;
  ------------------
  |  |  316|      0|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
 3535|      0|		keygen_args.prkey_args.access_flags |= SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE;
  ------------------
  |  |  318|      0|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
 3536|      0|	}
 3537|       |
 3538|       |	/* This is called form C_GenerateKey, key is alwways LOCAL (PKCS#11 v3.0 section 4.7.2) */
 3539|      0|	keygen_args.prkey_args.access_flags |= SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|      0|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
 3540|       |
 3541|       |	/* 3.a Try on-card key pair generation */
 3542|       |
 3543|      0|	sc_pkcs15init_set_p15card(profile, fw_data->p15_card);
 3544|       |
 3545|      0|	sc_log(context, "Try on-card key pair generation");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3546|      0|	rc = sc_pkcs15init_generate_key(fw_data->p15_card, profile, &keygen_args, (unsigned int) keybits, &priv_key_obj);
 3547|      0|	if (rc >= 0) {
  ------------------
  |  Branch (3547:6): [True: 0, False: 0]
  ------------------
 3548|      0|		id = ((struct sc_pkcs15_prkey_info *) priv_key_obj->data)->id;
 3549|      0|		rc = sc_pkcs15_find_pubkey_by_id(fw_data->p15_card, &id, &pub_key_obj);
 3550|      0|		if (rc != 0) {
  ------------------
  |  Branch (3550:7): [True: 0, False: 0]
  ------------------
 3551|      0|			sc_log(context, "sc_pkcs15_find_pubkey_by_id returned %d", rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3552|      0|			rv = sc_to_cryptoki_error(rc, "C_GenerateKeyPair");
 3553|      0|			goto kpgen_done;
 3554|      0|		}
 3555|      0|	}
 3556|      0|	else {
 3557|      0|		sc_log(context, "sc_pkcs15init_generate_key returned %d", rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3558|      0|		rv = sc_to_cryptoki_error(rc, "C_GenerateKeyPair");
 3559|      0|		goto kpgen_done;
 3560|      0|	}
 3561|       |
 3562|       |	/* 4. Create new pkcs11 public and private key object */
 3563|       |
 3564|      0|	rc = __pkcs15_create_prkey_object(fw_data, priv_key_obj, &priv_any_obj);
 3565|      0|	if (rc == 0)
  ------------------
  |  Branch (3565:6): [True: 0, False: 0]
  ------------------
 3566|      0|		rc = __pkcs15_create_pubkey_object(fw_data, pub_key_obj, &pub_any_obj);
 3567|      0|	if (rc != 0) {
  ------------------
  |  Branch (3567:6): [True: 0, False: 0]
  ------------------
 3568|      0|		sc_log(context, "__pkcs15_create_pr/pubkey_object returned %d", rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3569|      0|		rv = sc_to_cryptoki_error(rc, "C_GenerateKeyPair");
 3570|      0|		goto kpgen_done;
 3571|      0|	}
 3572|      0|	pkcs15_add_object(slot, priv_any_obj, phPrivKey);
 3573|      0|	pkcs15_add_object(slot, pub_any_obj, phPubKey);
 3574|       |
 3575|      0|	priv_prk_obj = (struct pkcs15_prkey_object *) priv_any_obj;
 3576|       |
 3577|      0|	priv_prk_obj->prv_pubkey = (struct pkcs15_pubkey_object *)pub_any_obj;
  ------------------
  |  |  106|      0|#define prv_pubkey		base.related_pubkey
  ------------------
 3578|       |
 3579|       |	/* Duplicate public key so that parameters can be retrieved even if public key object is deleted */
 3580|      0|	rv = sc_pkcs15_dup_pubkey(context, ((struct pkcs15_pubkey_object *)pub_any_obj)->pub_data, &priv_prk_obj->pub_data);
 3581|       |
 3582|      0|kpgen_done:
 3583|      0|	sc_pkcs15_erase_prkey(&keygen_args.prkey_args.key);
 3584|      0|	sc_pkcs15init_unbind(profile);
 3585|      0|	sc_unlock(p11card->card);
 3586|       |
 3587|      0|	return rv;
 3588|      0|}
framework-pkcs15.c:pkcs15_get_random:
 3730|  6.96k|{
 3731|  6.96k|	struct sc_pkcs11_card *p11card = slot->p11card;
 3732|  6.96k|	struct pkcs15_fw_data *fw_data = NULL;
 3733|  6.96k|	int rc;
 3734|       |
 3735|  6.96k|	if (!p11card)
  ------------------
  |  Branch (3735:6): [True: 0, False: 6.96k]
  ------------------
 3736|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GenerateRandom");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3737|  6.96k|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[slot->fw_data_idx];
 3738|  6.96k|	if (!fw_data)
  ------------------
  |  Branch (3738:6): [True: 0, False: 6.96k]
  ------------------
 3739|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GenerateRandom");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3740|  6.96k|	if (!fw_data->p15_card)
  ------------------
  |  Branch (3740:6): [True: 4.36k, False: 2.60k]
  ------------------
 3741|  4.36k|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GenerateRandom");
  ------------------
  |  |   60|  4.36k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3742|       |
 3743|  2.60k|	rc = sc_get_challenge(fw_data->p15_card->card, p, (size_t)len);
 3744|  2.60k|	return sc_to_cryptoki_error(rc, "C_GenerateRandom");
 3745|  6.96k|}
framework-pkcs15.c:pkcs15_cert_release:
 3862|  2.51k|{
 3863|  2.51k|	struct pkcs15_cert_object *cert = (struct pkcs15_cert_object *) obj;
 3864|  2.51k|	struct sc_pkcs15_cert      *cert_data = cert->cert_data;
 3865|       |
 3866|  2.51k|	if (__pkcs15_release_object((struct pkcs15_any_object *) obj) == 0)
  ------------------
  |  Branch (3866:6): [True: 1.25k, False: 1.25k]
  ------------------
 3867|  1.25k|		if (cert_data) /* may never have been read */
  ------------------
  |  Branch (3867:7): [True: 1.05k, False: 205]
  ------------------
 3868|  1.05k|			sc_pkcs15_free_certificate(cert_data);
 3869|  2.51k|}
framework-pkcs15.c:pkcs15_cert_get_attribute:
 3882|  6.58k|{
 3883|  6.58k|	struct sc_pkcs11_card *p11card = NULL;
 3884|  6.58k|	struct pkcs15_cert_object *cert = (struct pkcs15_cert_object*) object;
 3885|  6.58k|	struct pkcs15_fw_data *fw_data = NULL;
 3886|  6.58k|	size_t len;
 3887|       |
 3888|  6.58k|	sc_log(context, "pkcs15_cert_get_attribute() called");
  ------------------
  |  |   71|  6.58k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3889|  6.58k|	p11card = session->slot->p11card;
 3890|  6.58k|	if (!p11card)
  ------------------
  |  Branch (3890:6): [True: 0, False: 6.58k]
  ------------------
 3891|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3892|  6.58k|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 3893|  6.58k|	if (!fw_data)
  ------------------
  |  Branch (3893:6): [True: 0, False: 6.58k]
  ------------------
 3894|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3895|  6.58k|	if (!fw_data->p15_card)
  ------------------
  |  Branch (3895:6): [True: 0, False: 6.58k]
  ------------------
 3896|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3897|       |
 3898|  6.58k|	switch (attr->type) {
 3899|  3.52k|	case CKA_CLASS:
  ------------------
  |  |  137|  3.52k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (3899:2): [True: 3.52k, False: 3.06k]
  ------------------
 3900|  3.52k|		check_attribute_buffer(attr, sizeof(CK_OBJECT_CLASS));
  ------------------
  |  |   56|  3.52k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  7.04k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 1.76k, False: 1.76k]
  |  |  ------------------
  |  |   57|  1.76k|		attr->ulValueLen = size;        \
  |  |   58|  1.76k|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|  1.76k|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|  1.76k|	}                                       \
  |  |   60|  3.52k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.76k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.76k|	attr->ulValueLen = size;
  ------------------
 3901|  1.76k|		*(CK_OBJECT_CLASS*)attr->pValue = CKO_CERTIFICATE;
  ------------------
  |  | 1028|  1.76k|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
 3902|  1.76k|		break;
 3903|      0|	case CKA_TOKEN:
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (3903:2): [True: 0, False: 6.58k]
  ------------------
 3904|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3905|      0|		*(CK_BBOOL*)attr->pValue = TRUE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
 3906|      0|		break;
 3907|  1.62k|	case CKA_PRIVATE:
  ------------------
  |  |  139|  1.62k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (3907:2): [True: 1.62k, False: 4.95k]
  ------------------
 3908|  1.62k|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|  1.62k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  3.25k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 1.62k]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|  1.62k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.62k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.62k|	attr->ulValueLen = size;
  ------------------
 3909|  1.62k|		*(CK_BBOOL*)attr->pValue = (cert->base.p15_object->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |   50|  1.62k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 3910|  1.62k|		break;
 3911|      0|	case CKA_MODIFIABLE:
  ------------------
  |  |  197|      0|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (3911:2): [True: 0, False: 6.58k]
  ------------------
 3912|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3913|      0|		*(CK_BBOOL*)attr->pValue = FALSE;
  ------------------
  |  |   48|      0|#define FALSE 0
  ------------------
 3914|      0|		break;
 3915|      0|	case CKA_LABEL:
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (3915:2): [True: 0, False: 6.58k]
  ------------------
 3916|      0|		if (check_cert_data_read(fw_data, cert) != 0) {
  ------------------
  |  Branch (3916:7): [True: 0, False: 0]
  ------------------
 3917|      0|			attr->ulValueLen = 0;
 3918|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3919|      0|		}
 3920|      0|		len = strnlen(cert->cert_p15obj->label, sizeof cert->cert_p15obj->label);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
              		len = strnlen(cert->cert_p15obj->label, sizeof cert->cert_p15obj->label);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
 3921|      0|		check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3922|      0|		memcpy(attr->pValue, cert->cert_p15obj->label, len);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
 3923|      0|		break;
 3924|      0|	case CKA_CERTIFICATE_TYPE:
  ------------------
  |  |  145|      0|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (3924:2): [True: 0, False: 6.58k]
  ------------------
 3925|      0|		check_attribute_buffer(attr, sizeof(CK_CERTIFICATE_TYPE));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3926|      0|		*(CK_CERTIFICATE_TYPE*)attr->pValue = CKC_X_509;
  ------------------
  |  |  303|      0|#define CKC_X_509 0x00000000UL
  ------------------
 3927|      0|		break;
 3928|  1.43k|	case CKA_ID:
  ------------------
  |  |  161|  1.43k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (3928:2): [True: 1.43k, False: 5.14k]
  ------------------
 3929|       |#ifdef ZERO_CKAID_FOR_CA_CERTS
 3930|       |		if (cert->cert_info->authority) {
 3931|       |			check_attribute_buffer(attr, 1);
 3932|       |			*(unsigned char*)attr->pValue = 0;
 3933|       |			break;
 3934|       |		}
 3935|       |#endif
 3936|  1.43k|		check_attribute_buffer(attr, cert->cert_info->id.len);
  ------------------
  |  |   56|  1.43k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  2.87k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 736, False: 702]
  |  |  ------------------
  |  |   57|    736|		attr->ulValueLen = size;        \
  |  |   58|    736|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|    736|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|    736|	}                                       \
  |  |   60|  1.43k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 702]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    702|	attr->ulValueLen = size;
  ------------------
 3937|    702|		memcpy(attr->pValue, cert->cert_info->id.value, cert->cert_info->id.len);
 3938|    702|		break;
 3939|      0|	case CKA_TRUSTED:
  ------------------
  |  |  151|      0|#define CKA_TRUSTED 0x00000086UL
  ------------------
  |  Branch (3939:2): [True: 0, False: 6.58k]
  ------------------
 3940|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3941|      0|		*(CK_BBOOL*)attr->pValue = cert->cert_info->authority ? TRUE : FALSE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
              		*(CK_BBOOL*)attr->pValue = cert->cert_info->authority ? TRUE : FALSE;
  ------------------
  |  |   48|      0|#define FALSE 0
  ------------------
  |  Branch (3941:30): [True: 0, False: 0]
  ------------------
 3942|      0|		break;
 3943|      0|	case CKA_VALUE:
  ------------------
  |  |  143|      0|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (3943:2): [True: 0, False: 6.58k]
  ------------------
 3944|      0|		if (check_cert_data_read(fw_data, cert) != 0) {
  ------------------
  |  Branch (3944:7): [True: 0, False: 0]
  ------------------
 3945|      0|			attr->ulValueLen = 0;
 3946|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3947|      0|		}
 3948|      0|		check_attribute_buffer(attr, cert->cert_data->data.len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3949|      0|		memcpy(attr->pValue, cert->cert_data->data.value, cert->cert_data->data.len);
 3950|      0|		break;
 3951|      0|	case CKA_SERIAL_NUMBER:
  ------------------
  |  |  147|      0|#define CKA_SERIAL_NUMBER 0x00000082UL
  ------------------
  |  Branch (3951:2): [True: 0, False: 6.58k]
  ------------------
 3952|      0|		if (check_cert_data_read(fw_data, cert) != 0) {
  ------------------
  |  Branch (3952:7): [True: 0, False: 0]
  ------------------
 3953|      0|			attr->ulValueLen = 0;
 3954|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3955|      0|		}
 3956|      0|		check_attribute_buffer(attr, cert->cert_data->serial_len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3957|      0|		memcpy(attr->pValue, cert->cert_data->serial, cert->cert_data->serial_len);
 3958|      0|		break;
 3959|      0|	case CKA_SUBJECT:
  ------------------
  |  |  160|      0|#define CKA_SUBJECT 0x00000101UL
  ------------------
  |  Branch (3959:2): [True: 0, False: 6.58k]
  ------------------
 3960|      0|		if (check_cert_data_read(fw_data, cert) != 0) {
  ------------------
  |  Branch (3960:7): [True: 0, False: 0]
  ------------------
 3961|      0|			attr->ulValueLen = 0;
 3962|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3963|      0|		}
 3964|      0|		check_attribute_buffer(attr, cert->cert_data->subject_len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3965|      0|		memcpy(attr->pValue, cert->cert_data->subject, cert->cert_data->subject_len);
 3966|      0|		return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3967|      0|	case CKA_ISSUER:
  ------------------
  |  |  146|      0|#define CKA_ISSUER 0x00000081UL
  ------------------
  |  Branch (3967:2): [True: 0, False: 6.58k]
  ------------------
 3968|      0|		if (check_cert_data_read(fw_data, cert) != 0) {
  ------------------
  |  Branch (3968:7): [True: 0, False: 0]
  ------------------
 3969|      0|			attr->ulValueLen = 0;
 3970|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3971|      0|		}
 3972|      0|		check_attribute_buffer(attr, cert->cert_data->issuer_len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 3973|      0|		memcpy(attr->pValue, cert->cert_data->issuer, cert->cert_data->issuer_len);
 3974|      0|		return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 3975|      0|	default:
  ------------------
  |  Branch (3975:2): [True: 0, False: 6.58k]
  ------------------
 3976|      0|		return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 3977|  6.58k|	}
 3978|       |
 3979|  4.08k|	return CKR_OK;
  ------------------
  |  | 1086|  4.08k|#define CKR_OK 0x00000000UL
  ------------------
 3980|  6.58k|}
framework-pkcs15.c:check_cert_data_read:
 1026|      4|{
 1027|      4|	struct pkcs15_pubkey_object *obj2;
 1028|      4|	int rv;
 1029|      4|	int private_obj;
 1030|       |
 1031|      4|	if (!cert)
  ------------------
  |  Branch (1031:6): [True: 1, False: 3]
  ------------------
 1032|      1|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      1|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1033|       |
 1034|      3|	if (cert->cert_data)
  ------------------
  |  Branch (1034:6): [True: 1, False: 2]
  ------------------
 1035|      1|		return 0;
 1036|      2|	private_obj = cert->cert_flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   92|      2|#define cert_flags		base.base.flags
  ------------------
              	private_obj = cert->cert_flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      2|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1037|      2|	rv = sc_pkcs15_read_certificate(fw_data->p15_card, cert->cert_info, private_obj, &cert->cert_data);
 1038|      2|	if (rv < 0)
  ------------------
  |  Branch (1038:6): [True: 2, False: 0]
  ------------------
 1039|      2|		return rv;
 1040|       |
 1041|      0|	obj2 = cert->cert_pubkey;
  ------------------
  |  |   94|      0|#define cert_pubkey		base.related_pubkey
  ------------------
 1042|       |	/* make a copy of public key from the cert data */
 1043|      0|	if (!obj2->pub_data)
  ------------------
  |  Branch (1043:6): [True: 0, False: 0]
  ------------------
 1044|      0|		rv = sc_pkcs15_pubkey_from_cert(context, &cert->cert_data->data, &obj2->pub_data);
 1045|       |
 1046|       |	/* Find missing labels for certificate */
 1047|      0|	pkcs15_cert_extract_label(cert);
 1048|       |
 1049|       |	/* now that we have the cert and pub key, lets see if we can bind anything else */
 1050|      0|	pkcs15_bind_related_objects(fw_data);
 1051|       |
 1052|      0|	return rv;
 1053|      2|}
framework-pkcs15.c:pkcs15_cert_cmp_attribute:
 3988|  2.49k|{
 3989|  2.49k|	struct pkcs15_cert_object *cert = (struct pkcs15_cert_object*) object;
 3990|  2.49k|	struct sc_pkcs11_card *p11card = session->slot->p11card;
 3991|  2.49k|	struct pkcs15_fw_data *fw_data = NULL;
 3992|  2.49k|	const unsigned char *data = NULL, *_data = NULL;
 3993|  2.49k|	size_t	len, _len;
 3994|       |
 3995|  2.49k|	sc_log(context, "pkcs15_cert_cmp_attribute() called");
  ------------------
  |  |   71|  2.49k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3996|  2.49k|	if (!p11card)
  ------------------
  |  Branch (3996:6): [True: 0, False: 2.49k]
  ------------------
 3997|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 3998|  2.49k|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 3999|  2.49k|	if (!fw_data)   {
  ------------------
  |  Branch (3999:6): [True: 0, False: 2.49k]
  ------------------
 4000|      0|		sc_log(context, "pkcs15_cert_cmp_attribute() returns SC_ERROR_INTERNAL");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4001|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4002|      0|	}
 4003|  2.49k|	if (!fw_data->p15_card)
  ------------------
  |  Branch (4003:6): [True: 0, False: 2.49k]
  ------------------
 4004|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4005|       |
 4006|  2.49k|	switch (attr->type) {
 4007|       |	/* Check the issuer/subject. Some pkcs11 callers (i.e. netscape) will pass
 4008|       |	 * in the ASN.1 encoded SEQUENCE OF SET,
 4009|       |	 * while OpenSC just keeps the SET in the issuer/subject field. */
 4010|      0|	case CKA_ISSUER:
  ------------------
  |  |  146|      0|#define CKA_ISSUER 0x00000081UL
  ------------------
  |  Branch (4010:2): [True: 0, False: 2.49k]
  ------------------
 4011|      0|		if (check_cert_data_read(fw_data, cert) != 0)
  ------------------
  |  Branch (4011:7): [True: 0, False: 0]
  ------------------
 4012|      0|			break;
 4013|      0|		if (cert->cert_data->issuer_len == 0)
  ------------------
  |  Branch (4013:7): [True: 0, False: 0]
  ------------------
 4014|      0|			break;
 4015|       |
 4016|      0|		data = _data = (u8 *) attr->pValue;
 4017|      0|		len = _len = attr->ulValueLen;
 4018|      0|		if (cert->cert_data->issuer[0] == ASN1_SET_TAG && data[0] == ASN1_SEQ_TAG && len >= 2)
  ------------------
  |  | 3983|      0|#define ASN1_SET_TAG (SC_ASN1_SET | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  163|      0|#define SC_ASN1_SET                     17
  |  |  ------------------
  |  |               #define ASN1_SET_TAG (SC_ASN1_SET | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  |  |  ------------------
  ------------------
              		if (cert->cert_data->issuer[0] == ASN1_SET_TAG && data[0] == ASN1_SEQ_TAG && len >= 2)
  ------------------
  |  | 3984|      0|#define ASN1_SEQ_TAG (SC_ASN1_SEQUENCE | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  162|      0|#define SC_ASN1_SEQUENCE                16
  |  |  ------------------
  |  |               #define ASN1_SEQ_TAG (SC_ASN1_SEQUENCE | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  |  |  ------------------
  ------------------
  |  Branch (4018:7): [True: 0, False: 0]
  |  Branch (4018:53): [True: 0, False: 0]
  |  Branch (4018:80): [True: 0, False: 0]
  ------------------
 4019|      0|			data = sc_asn1_skip_tag(context, &_data, &_len, SC_ASN1_CONS | SC_ASN1_TAG_SEQUENCE, &len);
  ------------------
  |  |  141|      0|#define SC_ASN1_CONS			0x20000000
  ------------------
              			data = sc_asn1_skip_tag(context, &_data, &_len, SC_ASN1_CONS | SC_ASN1_TAG_SEQUENCE, &len);
  ------------------
  |  |  206|      0|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
 4020|       |
 4021|      0|		if (len == cert->cert_data->issuer_len && !memcmp(cert->cert_data->issuer, data, len))   {
  ------------------
  |  Branch (4021:7): [True: 0, False: 0]
  |  Branch (4021:45): [True: 0, False: 0]
  ------------------
 4022|      0|			sc_log(context, "pkcs15_cert_cmp_attribute() returns CKA_ISSUER matched");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4023|      0|			return 1;
 4024|      0|		}
 4025|      0|		break;
 4026|      0|	case CKA_SUBJECT:
  ------------------
  |  |  160|      0|#define CKA_SUBJECT 0x00000101UL
  ------------------
  |  Branch (4026:2): [True: 0, False: 2.49k]
  ------------------
 4027|      0|		if (check_cert_data_read(fw_data, cert) != 0)
  ------------------
  |  Branch (4027:7): [True: 0, False: 0]
  ------------------
 4028|      0|			break;
 4029|      0|		if (cert->cert_data->subject_len == 0)
  ------------------
  |  Branch (4029:7): [True: 0, False: 0]
  ------------------
 4030|      0|			break;
 4031|       |
 4032|      0|		data = _data = (u8 *) attr->pValue;
 4033|      0|		len = _len = attr->ulValueLen;
 4034|      0|		if (cert->cert_data->subject[0] == ASN1_SET_TAG && data[0] == ASN1_SEQ_TAG && len >= 2)
  ------------------
  |  | 3983|      0|#define ASN1_SET_TAG (SC_ASN1_SET | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  163|      0|#define SC_ASN1_SET                     17
  |  |  ------------------
  |  |               #define ASN1_SET_TAG (SC_ASN1_SET | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  |  |  ------------------
  ------------------
              		if (cert->cert_data->subject[0] == ASN1_SET_TAG && data[0] == ASN1_SEQ_TAG && len >= 2)
  ------------------
  |  | 3984|      0|#define ASN1_SEQ_TAG (SC_ASN1_SEQUENCE | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  162|      0|#define SC_ASN1_SEQUENCE                16
  |  |  ------------------
  |  |               #define ASN1_SEQ_TAG (SC_ASN1_SEQUENCE | SC_ASN1_TAG_CONSTRUCTED)
  |  |  ------------------
  |  |  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  |  |  ------------------
  ------------------
  |  Branch (4034:7): [True: 0, False: 0]
  |  Branch (4034:54): [True: 0, False: 0]
  |  Branch (4034:81): [True: 0, False: 0]
  ------------------
 4035|      0|			data = sc_asn1_skip_tag(context, &_data, &_len, SC_ASN1_CONS | SC_ASN1_TAG_SEQUENCE, &len);
  ------------------
  |  |  141|      0|#define SC_ASN1_CONS			0x20000000
  ------------------
              			data = sc_asn1_skip_tag(context, &_data, &_len, SC_ASN1_CONS | SC_ASN1_TAG_SEQUENCE, &len);
  ------------------
  |  |  206|      0|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
 4036|       |
 4037|      0|		if (len == cert->cert_data->subject_len && !memcmp(cert->cert_data->subject, data, len))   {
  ------------------
  |  Branch (4037:7): [True: 0, False: 0]
  |  Branch (4037:46): [True: 0, False: 0]
  ------------------
 4038|      0|			sc_log(context, "pkcs15_cert_cmp_attribute() returns CKA_SUBJECT matched");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4039|      0|			return 1;
 4040|      0|		}
 4041|      0|		break;
 4042|  2.49k|	default:
  ------------------
  |  Branch (4042:2): [True: 2.49k, False: 0]
  ------------------
 4043|  2.49k|		return sc_pkcs11_any_cmp_attribute(session, object, attr);
 4044|  2.49k|	}
 4045|      0|	sc_log(context, "pkcs15_cert_cmp_attribute() returns not matched");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4046|      0|	return 0;
 4047|  2.49k|}
framework-pkcs15.c:pkcs15_prkey_release:
 4070|  6.03k|{
 4071|  6.03k|	struct pkcs15_prkey_object *prkey = (struct pkcs15_prkey_object*) object;
 4072|  6.03k|	struct sc_pkcs15_pubkey *key_data = prkey->pub_data;
 4073|       |
 4074|  6.03k|	if (__pkcs15_release_object((struct pkcs15_any_object *) object) == 0)
  ------------------
  |  Branch (4074:6): [True: 3.40k, False: 2.62k]
  ------------------
 4075|  3.40k|		if (key_data)
  ------------------
  |  Branch (4075:7): [True: 1.01k, False: 2.39k]
  ------------------
 4076|  1.01k|			sc_pkcs15_free_pubkey(key_data);
 4077|  6.03k|}
framework-pkcs15.c:pkcs15_prkey_get_attribute:
 4091|  6.14k|{
 4092|  6.14k|	struct pkcs15_prkey_object *prkey = (struct pkcs15_prkey_object*) object;
 4093|  6.14k|	struct sc_pkcs11_card *p11card = NULL;
 4094|  6.14k|	struct pkcs15_fw_data *fw_data = NULL;
 4095|  6.14k|	struct sc_pkcs15_pubkey *key = NULL;
 4096|  6.14k|	unsigned int usage;
 4097|  6.14k|	size_t len;
 4098|       |
 4099|  6.14k|	sc_log(context, "pkcs15_prkey_get_attribute() called");
  ------------------
  |  |   71|  6.14k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4100|  6.14k|	p11card = session->slot->p11card;
 4101|  6.14k|	if (!p11card)
  ------------------
  |  Branch (4101:6): [True: 0, False: 6.14k]
  ------------------
 4102|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4103|  6.14k|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 4104|  6.14k|	if (!fw_data)
  ------------------
  |  Branch (4104:6): [True: 0, False: 6.14k]
  ------------------
 4105|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4106|  6.14k|	if (!fw_data->p15_card)
  ------------------
  |  Branch (4106:6): [True: 0, False: 6.14k]
  ------------------
 4107|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4108|       |
 4109|       |	/* PKCS#11 requires us to supply CKA_MODULUS for private keys,
 4110|       |	 * although that is not generally available from a smart card
 4111|       |	 * (the key is supposed to be safely locked away after all).
 4112|       |	 *
 4113|       |	 * To work around this, we hope that we either have an associated
 4114|       |	 * public key, or we try to find a certificate with the
 4115|       |	 * corresponding public key.
 4116|       |	 *
 4117|       |	 * Note: We do the same thing for CKA_PUBLIC_EXPONENT as some
 4118|       |	 *       applications assume they can get that from the private
 4119|       |	 *       key, something PKCS#11 doesn't guarantee.
 4120|       |	 */
 4121|  6.14k|	if ((attr->type == CKA_MODULUS) || (attr->type == CKA_PUBLIC_EXPONENT) ||
  ------------------
  |  |  174|  6.14k|#define CKA_MODULUS 0x00000120UL
  ------------------
              	if ((attr->type == CKA_MODULUS) || (attr->type == CKA_PUBLIC_EXPONENT) ||
  ------------------
  |  |  176|  6.14k|#define CKA_PUBLIC_EXPONENT 0x00000122UL
  ------------------
  |  Branch (4121:6): [True: 0, False: 6.14k]
  |  Branch (4121:37): [True: 0, False: 6.14k]
  ------------------
 4122|  6.14k|		((attr->type == CKA_MODULUS_BITS) && (prkey->prv_p15obj->type == SC_PKCS15_TYPE_PRKEY_EC)) ||
  ------------------
  |  |  175|  6.14k|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
              		((attr->type == CKA_MODULUS_BITS) && (prkey->prv_p15obj->type == SC_PKCS15_TYPE_PRKEY_EC)) ||
  ------------------
  |  |  105|    238|#define prv_p15obj		base.p15_object
  ------------------
              		((attr->type == CKA_MODULUS_BITS) && (prkey->prv_p15obj->type == SC_PKCS15_TYPE_PRKEY_EC)) ||
  ------------------
  |  |  421|    238|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (4122:4): [True: 238, False: 5.90k]
  |  Branch (4122:40): [True: 27, False: 211]
  ------------------
 4123|  6.11k|		(attr->type == CKA_EC_PARAMS)) {
  ------------------
  |  |  200|  6.11k|#define CKA_EC_PARAMS 0x00000180UL
  ------------------
  |  Branch (4123:3): [True: 0, False: 6.11k]
  ------------------
 4124|       |		/* First see if we have an associated public key */
 4125|     27|		if (prkey->pub_data) {
  ------------------
  |  Branch (4125:7): [True: 26, False: 1]
  ------------------
 4126|     26|			key = prkey->pub_data;
 4127|     26|		} else {
 4128|       |			/* Try to find public key or certificate with the public key */
 4129|      1|			unsigned int i;
 4130|       |
 4131|     20|			for (i = 0; i < fw_data->num_objects; i++) {
  ------------------
  |  Branch (4131:16): [True: 19, False: 1]
  ------------------
 4132|     19|				struct pkcs15_any_object *obj = fw_data->objects[i];
 4133|     19|				struct pkcs15_cert_object *cert;
 4134|       |
 4135|     19|				if (is_cert(obj))   {
  ------------------
  |  |  122|     19|#define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  119|     19|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 19, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_cert(obj)		(__p15_type(obj) == SC_PKCS15_TYPE_CERT_X509)
  |  |  ------------------
  |  |  |  |  439|     19|#define SC_PKCS15_TYPE_CERT_X509		0x401
  |  |  ------------------
  |  |  |  Branch (122:23): [True: 1, False: 18]
  |  |  ------------------
  ------------------
 4136|      1|					cert = (struct pkcs15_cert_object*) obj;
 4137|       |
 4138|      1|					if (cert->cert_prvkey != prkey)
  ------------------
  |  |   96|      1|#define cert_prvkey		base.related_privkey
  ------------------
  |  Branch (4138:10): [True: 0, False: 1]
  ------------------
 4139|      0|						continue;
 4140|       |
 4141|      1|					if (check_cert_data_read(fw_data, cert) == 0)   {
  ------------------
  |  Branch (4141:10): [True: 1, False: 0]
  ------------------
 4142|      1|						key = cert->cert_pubkey->pub_data;
  ------------------
  |  |   94|      1|#define cert_pubkey		base.related_pubkey
  ------------------
 4143|      1|						sc_log(context, "found friend certificate's public key %p", key);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4144|      1|					}
 4145|      1|				}
 4146|     18|				else if (is_pubkey(obj)) {
  ------------------
  |  |  121|     18|#define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  119|     18|#define __p15_type(obj)		(((obj) && (obj)->p15_object)? ((obj)->p15_object->type) : (unsigned int)-1)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:28): [True: 18, False: 0]
  |  |  |  |  |  Branch (119:37): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  416|     18|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  |  |  ------------------
  |  |               #define is_pubkey(obj)		((__p15_type(obj) & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PUBKEY)
  |  |  ------------------
  |  |  |  |  425|     18|#define SC_PKCS15_TYPE_PUBKEY			0x200
  |  |  ------------------
  |  |  |  Branch (121:25): [True: 1, False: 17]
  |  |  ------------------
  ------------------
 4147|      1|					struct pkcs15_pubkey_object *pubkey = (struct pkcs15_pubkey_object *) obj;
 4148|       |
 4149|      1|					if (!pubkey->pub_data)
  ------------------
  |  Branch (4149:10): [True: 0, False: 1]
  ------------------
 4150|      0|						continue;
 4151|       |
 4152|      1|					if (sc_pkcs15_compare_id(&pubkey->pub_info->id, &prkey->prv_info->id))   {
  ------------------
  |  Branch (4152:10): [True: 1, False: 0]
  ------------------
 4153|      1|						prkey->prv_pubkey = pubkey;
  ------------------
  |  |  106|      1|#define prv_pubkey		base.related_pubkey
  ------------------
 4154|      1|						key = pubkey->pub_data;
 4155|      1|						sc_log(context, "found friend public key %p", key);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4156|      1|					}
 4157|      1|				}
 4158|     19|			}
 4159|      1|		}
 4160|     27|	}
 4161|       |
 4162|  6.14k|	switch (attr->type) {
 4163|  2.42k|	case CKA_CLASS:
  ------------------
  |  |  137|  2.42k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (4163:2): [True: 2.42k, False: 3.71k]
  ------------------
 4164|  2.42k|		check_attribute_buffer(attr, sizeof(CK_OBJECT_CLASS));
  ------------------
  |  |   56|  2.42k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  4.85k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 1.21k, False: 1.21k]
  |  |  ------------------
  |  |   57|  1.21k|		attr->ulValueLen = size;        \
  |  |   58|  1.21k|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|  1.21k|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|  1.21k|	}                                       \
  |  |   60|  2.42k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.21k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.21k|	attr->ulValueLen = size;
  ------------------
 4165|  1.21k|		*(CK_OBJECT_CLASS*)attr->pValue = CKO_PRIVATE_KEY;
  ------------------
  |  | 1030|  1.21k|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
 4166|  1.21k|		break;
 4167|      0|	case CKA_TOKEN:
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (4167:2): [True: 0, False: 6.14k]
  ------------------
 4168|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4169|      0|		*(CK_BBOOL*)attr->pValue = TRUE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
 4170|      0|		break;
 4171|      0|	case CKA_ALWAYS_SENSITIVE:
  ------------------
  |  |  195|      0|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (4171:2): [True: 0, False: 6.14k]
  ------------------
 4172|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4173|      0|		*(CK_BBOOL*)attr->pValue = (prkey->prv_info->access_flags & SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE) != 0;
  ------------------
  |  |  318|      0|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
 4174|      0|		break;
 4175|      0|	case CKA_NEVER_EXTRACTABLE:
  ------------------
  |  |  194|      0|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (4175:2): [True: 0, False: 6.14k]
  ------------------
 4176|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4177|      0|		*(CK_BBOOL*)attr->pValue = (prkey->prv_info->access_flags & SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE) != 0;
  ------------------
  |  |  319|      0|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
 4178|      0|		break;
 4179|      0|	case CKA_SENSITIVE:
  ------------------
  |  |  162|      0|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (4179:2): [True: 0, False: 6.14k]
  ------------------
 4180|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4181|      0|		*(CK_BBOOL*)attr->pValue = (prkey->prv_info->access_flags & SC_PKCS15_PRKEY_ACCESS_SENSITIVE) != 0;
  ------------------
  |  |  316|      0|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
 4182|      0|		break;
 4183|      0|	case CKA_LOCAL:
  ------------------
  |  |  193|      0|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (4183:2): [True: 0, False: 6.14k]
  ------------------
 4184|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4185|      0|		*(CK_BBOOL*)attr->pValue = (prkey->prv_info->access_flags & SC_PKCS15_PRKEY_ACCESS_LOCAL) != 0;
  ------------------
  |  |  320|      0|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
 4186|      0|		break;
 4187|      0|	case CKA_ALWAYS_AUTHENTICATE:
  ------------------
  |  |  202|      0|#define CKA_ALWAYS_AUTHENTICATE 0x00000202UL
  ------------------
  |  Branch (4187:2): [True: 0, False: 6.14k]
  ------------------
 4188|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4189|      0|		if (fw_data->p15_card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (4189:7): [True: 0, False: 0]
  ------------------
 4190|      0|			*(CK_BBOOL*)attr->pValue = CK_FALSE;
  ------------------
  |  |   35|      0|#define CK_FALSE 0
  ------------------
 4191|      0|		} else {
 4192|      0|			*(CK_BBOOL*)attr->pValue = prkey->prv_p15obj->user_consent >= 1 ? CK_TRUE : CK_FALSE;
  ------------------
  |  |  105|      0|#define prv_p15obj		base.p15_object
  ------------------
              			*(CK_BBOOL*)attr->pValue = prkey->prv_p15obj->user_consent >= 1 ? CK_TRUE : CK_FALSE;
  ------------------
  |  |   34|      0|#define CK_TRUE 1
  ------------------
              			*(CK_BBOOL*)attr->pValue = prkey->prv_p15obj->user_consent >= 1 ? CK_TRUE : CK_FALSE;
  ------------------
  |  |   35|      0|#define CK_FALSE 0
  ------------------
  |  Branch (4192:31): [True: 0, False: 0]
  ------------------
 4193|      0|		}
 4194|      0|		break;
 4195|  1.87k|	case CKA_PRIVATE:
  ------------------
  |  |  139|  1.87k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (4195:2): [True: 1.87k, False: 4.27k]
  ------------------
 4196|  1.87k|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|  1.87k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  3.74k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 1.87k]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|  1.87k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.87k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.87k|	attr->ulValueLen = size;
  ------------------
 4197|  1.87k|		*(CK_BBOOL*)attr->pValue = (prkey->prv_p15obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |  105|  1.87k|#define prv_p15obj		base.p15_object
  ------------------
              		*(CK_BBOOL*)attr->pValue = (prkey->prv_p15obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |   50|  1.87k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 4198|  1.87k|		break;
 4199|      0|	case CKA_MODIFIABLE:
  ------------------
  |  |  197|      0|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (4199:2): [True: 0, False: 6.14k]
  ------------------
 4200|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4201|      0|		*(CK_BBOOL*)attr->pValue = (prkey->prv_p15obj->flags & SC_PKCS15_CO_FLAG_MODIFIABLE) != 0;
  ------------------
  |  |  105|      0|#define prv_p15obj		base.p15_object
  ------------------
              		*(CK_BBOOL*)attr->pValue = (prkey->prv_p15obj->flags & SC_PKCS15_CO_FLAG_MODIFIABLE) != 0;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
 4202|      0|		break;
 4203|      0|	case CKA_EXTRACTABLE:
  ------------------
  |  |  192|      0|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (4203:2): [True: 0, False: 6.14k]
  ------------------
 4204|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4205|      0|		*(CK_BBOOL *)attr->pValue = (prkey->prv_info->access_flags & SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE) != 0;
  ------------------
  |  |  317|      0|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
 4206|      0|		break;
 4207|      0|	case CKA_LABEL:
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (4207:2): [True: 0, False: 6.14k]
  ------------------
 4208|      0|		len = strnlen(prkey->prv_p15obj->label, sizeof prkey->prv_p15obj->label);
  ------------------
  |  |  105|      0|#define prv_p15obj		base.p15_object
  ------------------
              		len = strnlen(prkey->prv_p15obj->label, sizeof prkey->prv_p15obj->label);
  ------------------
  |  |  105|      0|#define prv_p15obj		base.p15_object
  ------------------
 4209|      0|		check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4210|      0|		memcpy(attr->pValue, prkey->prv_p15obj->label, len);
  ------------------
  |  |  105|      0|#define prv_p15obj		base.p15_object
  ------------------
 4211|      0|		break;
 4212|    760|	case CKA_KEY_TYPE:
  ------------------
  |  |  159|    760|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (4212:2): [True: 760, False: 5.38k]
  ------------------
 4213|  1.52k|		check_attribute_buffer(attr, sizeof(CK_KEY_TYPE));
  ------------------
  |  |   56|    760|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  1.52k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 760]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|    760|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 760]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    760|	attr->ulValueLen = size;
  ------------------
 4214|  1.52k|		switch (prkey->prv_p15obj->type) {
  ------------------
  |  |  105|    760|#define prv_p15obj		base.p15_object
  ------------------
 4215|    689|			case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    689|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (4215:4): [True: 689, False: 71]
  ------------------
 4216|    689|				*(CK_KEY_TYPE*)attr->pValue = CKK_RSA;
  ------------------
  |  |  464|    689|#define CKK_RSA 0x00000000UL
  ------------------
 4217|    689|				break;
 4218|      0|			case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (4218:4): [True: 0, False: 760]
  ------------------
 4219|      0|				*(CK_KEY_TYPE*)attr->pValue = CKK_GOSTR3410;
  ------------------
  |  |  502|      0|#define CKK_GOSTR3410 0x00000030UL
  ------------------
 4220|      0|				break;
 4221|      0|			case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|      0|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (4221:4): [True: 0, False: 760]
  ------------------
 4222|      0|				*(CK_KEY_TYPE*)attr->pValue = CKK_EC_EDWARDS;
  ------------------
  |  |  518|      0|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
 4223|      0|				break;
 4224|      0|			case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|      0|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (4224:4): [True: 0, False: 760]
  ------------------
 4225|      0|				*(CK_KEY_TYPE*)attr->pValue = CKK_EC_MONTGOMERY;
  ------------------
  |  |  519|      0|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
 4226|      0|				break;
 4227|     71|			case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     71|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (4227:4): [True: 71, False: 689]
  ------------------
 4228|     71|				*(CK_KEY_TYPE*)attr->pValue = CKK_EC;
  ------------------
  |  |  467|     71|#define CKK_EC 0x00000003UL
  ------------------
 4229|     71|				break;
 4230|      0|			default:
  ------------------
  |  Branch (4230:4): [True: 0, False: 760]
  ------------------
 4231|      0|				return CKR_GENERAL_ERROR; /* Internal error*/
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
 4232|  1.52k|		}
 4233|    760|		break;
 4234|    760|	case CKA_ID:
  ------------------
  |  |  161|     84|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (4234:2): [True: 84, False: 6.06k]
  ------------------
 4235|     84|		check_attribute_buffer(attr, prkey->prv_info->id.len);
  ------------------
  |  |   56|     84|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|    168|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 62, False: 22]
  |  |  ------------------
  |  |   57|     62|		attr->ulValueLen = size;        \
  |  |   58|     62|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|     62|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|     62|	}                                       \
  |  |   60|     84|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 22]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|     22|	attr->ulValueLen = size;
  ------------------
 4236|     22|		memcpy(attr->pValue, prkey->prv_info->id.value, prkey->prv_info->id.len);
 4237|     22|		break;
 4238|      0|	case CKA_KEY_GEN_MECHANISM:
  ------------------
  |  |  196|      0|#define CKA_KEY_GEN_MECHANISM 0x00000166UL
  ------------------
  |  Branch (4238:2): [True: 0, False: 6.14k]
  ------------------
 4239|      0|		check_attribute_buffer(attr, sizeof(CK_MECHANISM_TYPE));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 4240|      0|		*(CK_MECHANISM_TYPE*)attr->pValue = CK_UNAVAILABLE_INFORMATION;
  ------------------
  |  |   32|      0|#define CK_UNAVAILABLE_INFORMATION ~0UL
  ------------------
 4241|      0|		break;
 4242|    355|	case CKA_DECRYPT:
  ------------------
  |  |  164|    355|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (4242:2): [True: 355, False: 5.79k]
  ------------------
 4243|    620|	case CKA_SIGN:
  ------------------
  |  |  167|    620|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (4243:2): [True: 265, False: 5.88k]
  ------------------
 4244|    620|	case CKA_SIGN_RECOVER:
  ------------------
  |  |  168|    620|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (4244:2): [True: 0, False: 6.14k]
  ------------------
 4245|    744|	case CKA_UNWRAP:
  ------------------
  |  |  166|    744|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (4245:2): [True: 124, False: 6.02k]
  ------------------
 4246|    762|	case CKA_DERIVE:
  ------------------
  |  |  171|    762|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (4246:2): [True: 18, False: 6.12k]
  ------------------
 4247|    762|	case CKA_OPENSC_NON_REPUDIATION:
  ------------------
  |  |   19|    762|#define CKA_OPENSC_NON_REPUDIATION      (CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 1UL)
  |  |  ------------------
  |  |  |  |  289|    762|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_OPENSC_NON_REPUDIATION      (CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 1UL)
  |  |  ------------------
  |  |  |  |   12|    762|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
  |  Branch (4247:2): [True: 0, False: 6.14k]
  ------------------
 4248|       |		/* TODO seems to be obsolete */
 4249|       |		/* Combine the usage bits of all split keys */
 4250|  1.82k|		for (usage = 0; prkey; prkey = prkey->prv_next)
  ------------------
  |  |  107|  1.06k|#define prv_next		base.related_privkey
  ------------------
  |  Branch (4250:19): [True: 1.06k, False: 762]
  ------------------
 4251|  1.06k|			usage |= prkey->prv_info->usage;
 4252|    762|		return get_usage_bit(usage, attr);
 4253|      0|	case CKA_MODULUS:
  ------------------
  |  |  174|      0|#define CKA_MODULUS 0x00000120UL
  ------------------
  |  Branch (4253:2): [True: 0, False: 6.14k]
  ------------------
 4254|      0|		return get_modulus(key, attr);
 4255|    238|	case CKA_MODULUS_BITS:
  ------------------
  |  |  175|    238|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
  |  Branch (4255:2): [True: 238, False: 5.90k]
  ------------------
 4256|    476|		check_attribute_buffer(attr, sizeof(CK_ULONG));
  ------------------
  |  |   56|    238|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|    476|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 238]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|    238|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 238]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    238|	attr->ulValueLen = size;
  ------------------
 4257|    476|		switch (prkey->prv_p15obj->type) {
  ------------------
  |  |  105|    238|#define prv_p15obj		base.p15_object
  ------------------
 4258|      0|			case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|      0|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (4258:4): [True: 0, False: 238]
  ------------------
 4259|      0|			case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|      0|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (4259:4): [True: 0, False: 238]
  ------------------
 4260|       |				/* TODO where to get field length ? */
 4261|      0|				*(CK_ULONG *) attr->pValue = 255;
 4262|      0|				return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 4263|     27|			case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     27|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (4263:4): [True: 27, False: 211]
  ------------------
 4264|     27|				if (key) {
  ------------------
  |  Branch (4264:9): [True: 27, False: 0]
  ------------------
 4265|     27|					if (key->u.ec.params.field_length > 0)
  ------------------
  |  Branch (4265:10): [True: 1, False: 26]
  ------------------
 4266|      1|						*(CK_ULONG *) attr->pValue = key->u.ec.params.field_length;
 4267|     26|					else
 4268|     26|						*(CK_ULONG *) attr->pValue = (key->u.ec.ecpointQ.len - 1) / 2 *8;
 4269|     27|				}
 4270|     27|				return CKR_OK;
  ------------------
  |  | 1086|     27|#define CKR_OK 0x00000000UL
  ------------------
 4271|    211|			default:
  ------------------
  |  Branch (4271:4): [True: 211, False: 27]
  ------------------
 4272|    211|				*(CK_ULONG *) attr->pValue = prkey->prv_info->modulus_length;
 4273|    211|				return CKR_OK;
  ------------------
  |  | 1086|    211|#define CKR_OK 0x00000000UL
  ------------------
 4274|    476|		}
 4275|      0|	case CKA_PUBLIC_EXPONENT:
  ------------------
  |  |  176|      0|#define CKA_PUBLIC_EXPONENT 0x00000122UL
  ------------------
  |  Branch (4275:2): [True: 0, False: 6.14k]
  ------------------
 4276|      0|		return get_public_exponent(key, attr);
 4277|      0|	case CKA_PRIVATE_EXPONENT:
  ------------------
  |  |  177|      0|#define CKA_PRIVATE_EXPONENT 0x00000123UL
  ------------------
  |  Branch (4277:2): [True: 0, False: 6.14k]
  ------------------
 4278|      0|	case CKA_PRIME_1:
  ------------------
  |  |  178|      0|#define CKA_PRIME_1 0x00000124UL
  ------------------
  |  Branch (4278:2): [True: 0, False: 6.14k]
  ------------------
 4279|      0|	case CKA_PRIME_2:
  ------------------
  |  |  179|      0|#define CKA_PRIME_2 0x00000125UL
  ------------------
  |  Branch (4279:2): [True: 0, False: 6.14k]
  ------------------
 4280|      0|	case CKA_EXPONENT_1:
  ------------------
  |  |  180|      0|#define CKA_EXPONENT_1 0x00000126UL
  ------------------
  |  Branch (4280:2): [True: 0, False: 6.14k]
  ------------------
 4281|      0|	case CKA_EXPONENT_2:
  ------------------
  |  |  181|      0|#define CKA_EXPONENT_2 0x00000127UL
  ------------------
  |  Branch (4281:2): [True: 0, False: 6.14k]
  ------------------
 4282|      0|	case CKA_COEFFICIENT:
  ------------------
  |  |  182|      0|#define CKA_COEFFICIENT 0x00000128UL
  ------------------
  |  Branch (4282:2): [True: 0, False: 6.14k]
  ------------------
 4283|      0|		return CKR_ATTRIBUTE_SENSITIVE;
  ------------------
  |  | 1097|      0|#define CKR_ATTRIBUTE_SENSITIVE 0x00000011UL
  ------------------
 4284|      0|	case CKA_SUBJECT:
  ------------------
  |  |  160|      0|#define CKA_SUBJECT 0x00000101UL
  ------------------
  |  Branch (4284:2): [True: 0, False: 6.14k]
  ------------------
 4285|      0|	case CKA_START_DATE:
  ------------------
  |  |  172|      0|#define CKA_START_DATE 0x00000110UL
  ------------------
  |  Branch (4285:2): [True: 0, False: 6.14k]
  ------------------
 4286|      0|	case CKA_END_DATE:
  ------------------
  |  |  173|      0|#define CKA_END_DATE 0x00000111UL
  ------------------
  |  Branch (4286:2): [True: 0, False: 6.14k]
  ------------------
 4287|      0|		attr->ulValueLen = 0;
 4288|      0|		return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 4289|      0|	case CKA_GOSTR3410_PARAMS:
  ------------------
  |  |  218|      0|#define CKA_GOSTR3410_PARAMS 0x00000250UL
  ------------------
  |  Branch (4289:2): [True: 0, False: 6.14k]
  ------------------
 4290|      0|		if (prkey->prv_info && prkey->prv_info->params.len)
  ------------------
  |  Branch (4290:7): [True: 0, False: 0]
  |  Branch (4290:26): [True: 0, False: 0]
  ------------------
 4291|      0|			return get_gostr3410_params(prkey->prv_info->params.data,
 4292|      0|					prkey->prv_info->params.len, attr);
 4293|      0|		else
 4294|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 4295|      0|	case CKA_EC_PARAMS:
  ------------------
  |  |  200|      0|#define CKA_EC_PARAMS 0x00000180UL
  ------------------
  |  Branch (4295:2): [True: 0, False: 6.14k]
  ------------------
 4296|      0|		return get_ec_pubkey_params(key, attr); /* get from pubkey for now */
 4297|      0|	default:
  ------------------
  |  Branch (4297:2): [True: 0, False: 6.14k]
  ------------------
 4298|      0|		return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 4299|  6.14k|	}
 4300|       |
 4301|  3.86k|	return CKR_OK;
  ------------------
  |  | 1086|  3.86k|#define CKR_OK 0x00000000UL
  ------------------
 4302|  6.14k|}
framework-pkcs15.c:get_usage_bit:
 6151|    762|{
 6152|    762|	static struct {
 6153|    762|		CK_ATTRIBUTE_TYPE type;
 6154|    762|		unsigned int	flag;
 6155|    762|	} flag_mapping[] = {
 6156|    762|		{ CKA_ENCRYPT,		SC_PKCS15_PRKEY_USAGE_ENCRYPT },
  ------------------
  |  |  163|    762|#define CKA_ENCRYPT 0x00000104UL
  ------------------
              		{ CKA_ENCRYPT,		SC_PKCS15_PRKEY_USAGE_ENCRYPT },
  ------------------
  |  |  305|    762|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
 6157|    762|		{ CKA_DECRYPT,		SC_PKCS15_PRKEY_USAGE_DECRYPT },
  ------------------
  |  |  164|    762|#define CKA_DECRYPT 0x00000105UL
  ------------------
              		{ CKA_DECRYPT,		SC_PKCS15_PRKEY_USAGE_DECRYPT },
  ------------------
  |  |  306|    762|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
 6158|    762|		{ CKA_SIGN,		SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_NONREPUDIATION },
  ------------------
  |  |  167|    762|#define CKA_SIGN 0x00000108UL
  ------------------
              		{ CKA_SIGN,		SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_NONREPUDIATION },
  ------------------
  |  |  307|    762|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		{ CKA_SIGN,		SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_NONREPUDIATION },
  ------------------
  |  |  314|    762|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
 6159|    762|		{ CKA_SIGN_RECOVER,	SC_PKCS15_PRKEY_USAGE_SIGNRECOVER },
  ------------------
  |  |  168|    762|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
              		{ CKA_SIGN_RECOVER,	SC_PKCS15_PRKEY_USAGE_SIGNRECOVER },
  ------------------
  |  |  308|    762|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
 6160|    762|		{ CKA_WRAP,		SC_PKCS15_PRKEY_USAGE_WRAP },
  ------------------
  |  |  165|    762|#define CKA_WRAP 0x00000106UL
  ------------------
              		{ CKA_WRAP,		SC_PKCS15_PRKEY_USAGE_WRAP },
  ------------------
  |  |  309|    762|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
 6161|    762|		{ CKA_UNWRAP,		SC_PKCS15_PRKEY_USAGE_UNWRAP },
  ------------------
  |  |  166|    762|#define CKA_UNWRAP 0x00000107UL
  ------------------
              		{ CKA_UNWRAP,		SC_PKCS15_PRKEY_USAGE_UNWRAP },
  ------------------
  |  |  310|    762|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
 6162|    762|		{ CKA_VERIFY,		SC_PKCS15_PRKEY_USAGE_VERIFY },
  ------------------
  |  |  169|    762|#define CKA_VERIFY 0x0000010AUL
  ------------------
              		{ CKA_VERIFY,		SC_PKCS15_PRKEY_USAGE_VERIFY },
  ------------------
  |  |  311|    762|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
 6163|    762|		{ CKA_VERIFY_RECOVER,	SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER },
  ------------------
  |  |  170|    762|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
              		{ CKA_VERIFY_RECOVER,	SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER },
  ------------------
  |  |  312|    762|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
 6164|    762|		{ CKA_DERIVE,		SC_PKCS15_PRKEY_USAGE_DERIVE },
  ------------------
  |  |  171|    762|#define CKA_DERIVE 0x0000010CUL
  ------------------
              		{ CKA_DERIVE,		SC_PKCS15_PRKEY_USAGE_DERIVE },
  ------------------
  |  |  313|    762|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
 6165|    762|		{ CKA_OPENSC_NON_REPUDIATION, SC_PKCS15_PRKEY_USAGE_NONREPUDIATION },
  ------------------
  |  |   19|    762|#define CKA_OPENSC_NON_REPUDIATION      (CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 1UL)
  |  |  ------------------
  |  |  |  |  289|    762|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_OPENSC_NON_REPUDIATION      (CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 1UL)
  |  |  ------------------
  |  |  |  |   12|    762|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
              		{ CKA_OPENSC_NON_REPUDIATION, SC_PKCS15_PRKEY_USAGE_NONREPUDIATION },
  ------------------
  |  |  314|    762|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
 6166|    762|		{ 0, 0 }
 6167|    762|	};
 6168|    762|	unsigned int mask = 0, j;
 6169|       |
 6170|  2.41k|	for (j = 0; (mask = flag_mapping[j].flag) != 0; j++) {
  ------------------
  |  Branch (6170:14): [True: 2.41k, False: 0]
  ------------------
 6171|  2.41k|		if (flag_mapping[j].type == attr->type)
  ------------------
  |  Branch (6171:7): [True: 762, False: 1.64k]
  ------------------
 6172|    762|			break;
 6173|  2.41k|	}
 6174|    762|	if (mask == 0)
  ------------------
  |  Branch (6174:6): [True: 0, False: 762]
  ------------------
 6175|      0|		return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 6176|       |
 6177|    762|	check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|    762|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  1.52k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 762]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|    762|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 762]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    762|	attr->ulValueLen = size;
  ------------------
 6178|    762|	*(CK_BBOOL*)attr->pValue = (usage & mask)? TRUE : FALSE;
  ------------------
  |  |   51|    522|#define TRUE 1
  ------------------
              	*(CK_BBOOL*)attr->pValue = (usage & mask)? TRUE : FALSE;
  ------------------
  |  |   48|  1.00k|#define FALSE 0
  ------------------
  |  Branch (6178:29): [True: 522, False: 240]
  ------------------
 6179|       |
 6180|    762|	return CKR_OK;
  ------------------
  |  | 1086|    762|#define CKR_OK 0x00000000UL
  ------------------
 6181|  1.52k|}
framework-pkcs15.c:pkcs15_prkey_sign:
 4353|    238|{
 4354|    238|	struct pkcs15_prkey_object *prkey = (struct pkcs15_prkey_object *) obj;
 4355|    238|	struct sc_pkcs11_card *p11card = session->slot->p11card;
 4356|    238|	struct pkcs15_fw_data *fw_data = NULL;
 4357|    238|	CK_RV rv;
 4358|    238|	int flags = 0, rc;
 4359|    238|	unsigned sign_flags = SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER
  ------------------
  |  |  307|    238|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	unsigned sign_flags = SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER
  ------------------
  |  |  308|    238|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
 4360|    238|			| SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|    238|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
 4361|       |
 4362|    238|	sc_log(context, "Initiating signing operation, mechanism 0x%lx.",
  ------------------
  |  |   71|    238|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4363|    238|		   pMechanism->mechanism);
 4364|    238|	if (!p11card)
  ------------------
  |  Branch (4364:6): [True: 0, False: 238]
  ------------------
 4365|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Sign");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4366|    238|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 4367|    238|	if (!fw_data)
  ------------------
  |  Branch (4367:6): [True: 0, False: 238]
  ------------------
 4368|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_Sign");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4369|    238|	if (!fw_data->p15_card)
  ------------------
  |  Branch (4369:6): [True: 0, False: 238]
  ------------------
 4370|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Sign");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4371|       |
 4372|       |	/* See which of the alternative keys supports signing */
 4373|    250|	while (prkey && !(prkey->prv_info->usage & sign_flags))
  ------------------
  |  Branch (4373:9): [True: 250, False: 0]
  |  Branch (4373:18): [True: 12, False: 238]
  ------------------
 4374|     12|		prkey = prkey->prv_next;
  ------------------
  |  |  107|    250|#define prv_next		base.related_privkey
  ------------------
 4375|       |
 4376|    238|	if (prkey == NULL)
  ------------------
  |  Branch (4376:6): [True: 0, False: 238]
  ------------------
 4377|      0|		return CKR_KEY_FUNCTION_NOT_PERMITTED;
  ------------------
  |  | 1119|      0|#define CKR_KEY_FUNCTION_NOT_PERMITTED 0x00000068UL
  ------------------
 4378|       |
 4379|    238|	switch (pMechanism->mechanism) {
 4380|     74|	case CKM_RSA_PKCS:
  ------------------
  |  |  539|     74|#define CKM_RSA_PKCS 0x00000001UL
  ------------------
  |  Branch (4380:2): [True: 74, False: 164]
  ------------------
 4381|     74|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  109|     74|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     74|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 4382|     74|		break;
 4383|     66|	case CKM_MD5_RSA_PKCS:
  ------------------
  |  |  543|     66|#define CKM_MD5_RSA_PKCS 0x00000005UL
  ------------------
  |  Branch (4383:2): [True: 66, False: 172]
  ------------------
 4384|     66|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_MD5;
  ------------------
  |  |  109|     66|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_MD5;
  ------------------
  |  |  135|     66|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
 4385|     66|		break;
 4386|     14|	case CKM_SHA1_RSA_PKCS:
  ------------------
  |  |  544|     14|#define CKM_SHA1_RSA_PKCS 0x00000006UL
  ------------------
  |  Branch (4386:2): [True: 14, False: 224]
  ------------------
 4387|     14|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  109|     14|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|     14|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
 4388|     14|		break;
 4389|     11|	case CKM_SHA224_RSA_PKCS:
  ------------------
  |  |  604|     11|#define CKM_SHA224_RSA_PKCS 0x00000046UL
  ------------------
  |  Branch (4389:2): [True: 11, False: 227]
  ------------------
 4390|     11|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA224;
  ------------------
  |  |  109|     11|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA224;
  ------------------
  |  |  141|     11|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
 4391|     11|		break;
 4392|     13|	case CKM_SHA256_RSA_PKCS:
  ------------------
  |  |  598|     13|#define CKM_SHA256_RSA_PKCS 0x00000040UL
  ------------------
  |  Branch (4392:2): [True: 13, False: 225]
  ------------------
 4393|     13|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  109|     13|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|     13|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
 4394|     13|		break;
 4395|      5|	case CKM_SHA384_RSA_PKCS:
  ------------------
  |  |  599|      5|#define CKM_SHA384_RSA_PKCS 0x00000041UL
  ------------------
  |  Branch (4395:2): [True: 5, False: 233]
  ------------------
 4396|      5|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA384;
  ------------------
  |  |  109|      5|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA384;
  ------------------
  |  |  139|      5|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
 4397|      5|		break;
 4398|      3|	case CKM_SHA512_RSA_PKCS:
  ------------------
  |  |  600|      3|#define CKM_SHA512_RSA_PKCS 0x00000042UL
  ------------------
  |  Branch (4398:2): [True: 3, False: 235]
  ------------------
 4399|      3|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA512;
  ------------------
  |  |  109|      3|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_SHA512;
  ------------------
  |  |  140|      3|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 4400|      3|		break;
 4401|     12|	case CKM_RIPEMD160_RSA_PKCS:
  ------------------
  |  |  546|     12|#define CKM_RIPEMD160_RSA_PKCS 0x00000008UL
  ------------------
  |  Branch (4401:2): [True: 12, False: 226]
  ------------------
 4402|     12|		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_RIPEMD160;
  ------------------
  |  |  109|     12|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_RIPEMD160;
  ------------------
  |  |  137|     12|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
 4403|     12|		break;
 4404|     10|	case CKM_RSA_X_509:
  ------------------
  |  |  541|     10|#define CKM_RSA_X_509 0x00000003UL
  ------------------
  |  Branch (4404:2): [True: 10, False: 228]
  ------------------
 4405|     10|		flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|     10|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 4406|     10|		break;
 4407|      0|	case CKM_RSA_PKCS_PSS:
  ------------------
  |  |  551|      0|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
  |  Branch (4407:2): [True: 0, False: 238]
  ------------------
 4408|      0|		flags = SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
 4409|       |		/* The hash was done outside of the module */
 4410|      0|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 4411|       |		/* Omitted parameter can use MGF1-SHA1 ? */
 4412|      0|		if (pMechanism->pParameter == NULL) {
  ------------------
  |  Branch (4412:7): [True: 0, False: 0]
  ------------------
 4413|      0|			flags |= SC_ALGORITHM_MGF1_SHA1;
  ------------------
  |  |  145|      0|#define SC_ALGORITHM_MGF1_SHA1		0x00100000
  ------------------
 4414|      0|			if (ulDataLen != SHA_DIGEST_LENGTH)
  ------------------
  |  Branch (4414:8): [True: 0, False: 0]
  ------------------
 4415|      0|				return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4416|      0|			break;
 4417|      0|		}
 4418|       |
 4419|       |		/* Check the data length matches the selected hash */
 4420|      0|		rv = pkcs15_prkey_check_pss_param(pMechanism, (int)ulDataLen);
 4421|      0|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (4421:7): [True: 0, False: 0]
  ------------------
 4422|      0|			sc_log(context, "Invalid data length for the selected "
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4423|      0|			    "PSS parameters");
 4424|      0|			return rv;
 4425|      0|		}
 4426|       |
 4427|       |		/* The MGF parameter was already verified in SignInit() */
 4428|      0|		flags |=  mgf2flags(((CK_RSA_PKCS_PSS_PARAMS*)pMechanism->pParameter)->mgf);
 4429|       |
 4430|       |		/* Assuming salt is the size of hash */
 4431|      0|		break;
 4432|      0|	case CKM_SHA1_RSA_PKCS_PSS:
  ------------------
  |  |  552|      0|#define CKM_SHA1_RSA_PKCS_PSS 0x0000000EUL
  ------------------
  |  Branch (4432:2): [True: 0, False: 238]
  ------------------
 4433|      0|	case CKM_SHA224_RSA_PKCS_PSS:
  ------------------
  |  |  605|      0|#define CKM_SHA224_RSA_PKCS_PSS 0x00000047UL
  ------------------
  |  Branch (4433:2): [True: 0, False: 238]
  ------------------
 4434|      0|	case CKM_SHA256_RSA_PKCS_PSS:
  ------------------
  |  |  601|      0|#define CKM_SHA256_RSA_PKCS_PSS 0x00000043UL
  ------------------
  |  Branch (4434:2): [True: 0, False: 238]
  ------------------
 4435|      0|	case CKM_SHA384_RSA_PKCS_PSS:
  ------------------
  |  |  602|      0|#define CKM_SHA384_RSA_PKCS_PSS 0x00000044UL
  ------------------
  |  Branch (4435:2): [True: 0, False: 238]
  ------------------
 4436|      0|	case CKM_SHA512_RSA_PKCS_PSS:
  ------------------
  |  |  603|      0|#define CKM_SHA512_RSA_PKCS_PSS 0x00000045UL
  ------------------
  |  Branch (4436:2): [True: 0, False: 238]
  ------------------
 4437|      0|		flags = SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
 4438|       |		/* Omitted parameter can use MGF1-SHA1 and SHA1 hash ? */
 4439|      0|		if (pMechanism->pParameter == NULL) {
  ------------------
  |  Branch (4439:7): [True: 0, False: 0]
  ------------------
 4440|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
 4441|      0|			flags |= SC_ALGORITHM_MGF1_SHA1;
  ------------------
  |  |  145|      0|#define SC_ALGORITHM_MGF1_SHA1		0x00100000
  ------------------
 4442|      0|			break;
 4443|      0|		}
 4444|       |
 4445|      0|		switch (((CK_RSA_PKCS_PSS_PARAMS*)pMechanism->pParameter)->hashAlg) {
 4446|      0|		case CKM_SHA_1:
  ------------------
  |  |  667|      0|#define CKM_SHA_1 0x00000220UL
  ------------------
  |  Branch (4446:3): [True: 0, False: 0]
  ------------------
 4447|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
 4448|      0|			break;
 4449|      0|		case CKM_SHA224:
  ------------------
  |  |  679|      0|#define CKM_SHA224 0x00000255UL
  ------------------
  |  Branch (4449:3): [True: 0, False: 0]
  ------------------
 4450|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA224;
  ------------------
  |  |  141|      0|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
 4451|      0|			break;
 4452|      0|		case CKM_SHA256:
  ------------------
  |  |  676|      0|#define CKM_SHA256 0x00000250UL
  ------------------
  |  Branch (4452:3): [True: 0, False: 0]
  ------------------
 4453|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
 4454|      0|			break;
 4455|      0|		case CKM_SHA384:
  ------------------
  |  |  682|      0|#define CKM_SHA384 0x00000260UL
  ------------------
  |  Branch (4455:3): [True: 0, False: 0]
  ------------------
 4456|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA384;
  ------------------
  |  |  139|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
 4457|      0|			break;
 4458|      0|		case CKM_SHA512:
  ------------------
  |  |  685|      0|#define CKM_SHA512 0x00000270UL
  ------------------
  |  Branch (4458:3): [True: 0, False: 0]
  ------------------
 4459|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA512;
  ------------------
  |  |  140|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 4460|      0|			break;
 4461|      0|		default:
  ------------------
  |  Branch (4461:3): [True: 0, False: 0]
  ------------------
 4462|      0|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4463|      0|		}
 4464|       |
 4465|       |		/* The MGF parameter was already verified in SignInit() */
 4466|      0|		flags |= mgf2flags(((CK_RSA_PKCS_PSS_PARAMS*)pMechanism->pParameter)->mgf);
 4467|       |
 4468|      0|		break;
 4469|      0|	case CKM_GOSTR3410:
  ------------------
  |  |  909|      0|#define CKM_GOSTR3410 0x00001201UL
  ------------------
  |  Branch (4469:2): [True: 0, False: 238]
  ------------------
 4470|      0|		flags = SC_ALGORITHM_GOSTR3410_HASH_NONE;
  ------------------
  |  |  157|      0|#define SC_ALGORITHM_GOSTR3410_HASH_NONE	SC_ALGORITHM_GOSTR3410_RAW /*XXX*/
  |  |  ------------------
  |  |  |  |  156|      0|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  |  |  ------------------
  ------------------
 4471|      0|		break;
 4472|      0|	case CKM_GOSTR3410_WITH_GOSTR3411:
  ------------------
  |  |  910|      0|#define CKM_GOSTR3410_WITH_GOSTR3411 0x00001202UL
  ------------------
  |  Branch (4472:2): [True: 0, False: 238]
  ------------------
 4473|      0|		flags = SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411;
  ------------------
  |  |  158|      0|#define SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411	0x00080000
  ------------------
 4474|      0|		break;
 4475|      0|	case CKM_EDDSA:
  ------------------
  |  |  990|      0|#define CKM_EDDSA 0x00001057UL
  ------------------
  |  Branch (4475:2): [True: 0, False: 238]
  ------------------
 4476|      0|		flags = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|      0|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 4477|      0|		break;
 4478|      0|	case CKM_XEDDSA:
  ------------------
  |  |  979|      0|#define CKM_XEDDSA 0x00004029UL
  ------------------
  |  Branch (4478:2): [True: 0, False: 238]
  ------------------
 4479|      0|		flags = SC_ALGORITHM_XEDDSA_RAW;
  ------------------
  |  |  189|      0|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
 4480|      0|		break;
 4481|      4|	case CKM_ECDSA:
  ------------------
  |  |  860|      4|#define CKM_ECDSA 0x00001041UL
  ------------------
  |  Branch (4481:2): [True: 4, False: 234]
  ------------------
 4482|      4|		flags = SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|      4|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|      4|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 4483|      4|		break;
 4484|      1|	case CKM_ECDSA_SHA1:
  ------------------
  |  |  861|      1|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
  |  Branch (4484:2): [True: 1, False: 237]
  ------------------
 4485|      1|		flags = SC_ALGORITHM_ECDSA_HASH_SHA1;
  ------------------
  |  |  176|      1|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|      1|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 4486|      1|		break;
 4487|      1|	case CKM_ECDSA_SHA224:
  ------------------
  |  |  862|      1|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
  |  Branch (4487:2): [True: 1, False: 237]
  ------------------
 4488|      1|		flags = SC_ALGORITHM_ECDSA_HASH_SHA224;
  ------------------
  |  |  177|      1|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|      1|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 4489|      1|		break;
 4490|      4|	case CKM_ECDSA_SHA256:
  ------------------
  |  |  863|      4|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
  |  Branch (4490:2): [True: 4, False: 234]
  ------------------
 4491|      4|		flags = SC_ALGORITHM_ECDSA_HASH_SHA256;
  ------------------
  |  |  178|      4|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|      4|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 4492|      4|		break;
 4493|      1|	case CKM_ECDSA_SHA384:
  ------------------
  |  |  864|      1|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
  |  Branch (4493:2): [True: 1, False: 237]
  ------------------
 4494|      1|		flags = SC_ALGORITHM_ECDSA_HASH_SHA384;
  ------------------
  |  |  179|      1|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|      1|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 4495|      1|		break;
 4496|     16|	case CKM_ECDSA_SHA512:
  ------------------
  |  |  865|     16|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
  |  Branch (4496:2): [True: 16, False: 222]
  ------------------
 4497|     16|		flags = SC_ALGORITHM_ECDSA_HASH_SHA512;
  ------------------
  |  |  180|     16|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|     16|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 4498|     16|		break;
 4499|      3|	default:
  ------------------
  |  Branch (4499:2): [True: 3, False: 235]
  ------------------
 4500|      3|		sc_log(context, "DEE - need EC for %lu", pMechanism->mechanism);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4501|      3|		return CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|      3|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
 4502|    238|	}
 4503|       |
 4504|    235|	rc = sc_lock(p11card->card);
 4505|    235|	if (rc < 0)
  ------------------
  |  Branch (4505:6): [True: 0, False: 235]
  ------------------
 4506|      0|		return sc_to_cryptoki_error(rc, "C_Sign");
 4507|       |
 4508|    235|	sc_log(context,
  ------------------
  |  |   71|    235|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4509|    235|	       "Selected flags %X. Now computing signature for %lu bytes. %lu bytes reserved.",
 4510|    235|	       flags, ulDataLen, *pulDataLen);
 4511|    235|	rc = sc_pkcs15_compute_signature(fw_data->p15_card, prkey->prv_p15obj, flags,
  ------------------
  |  |  105|    235|#define prv_p15obj		base.p15_object
  ------------------
 4512|    235|			pData, ulDataLen, pSignature, *pulDataLen, pMechanism);
 4513|       |
 4514|    235|	sc_unlock(p11card->card);
 4515|       |
 4516|    235|	sc_log(context, "Sign complete. Result %d.", rc);
  ------------------
  |  |   71|    235|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4517|       |
 4518|    235|	if (rc > 0) {
  ------------------
  |  Branch (4518:6): [True: 47, False: 188]
  ------------------
 4519|     47|		*pulDataLen = rc;
 4520|     47|		return CKR_OK;
  ------------------
  |  | 1086|     47|#define CKR_OK 0x00000000UL
  ------------------
 4521|     47|	}
 4522|       |
 4523|    188|	return sc_to_cryptoki_error(rc, "C_Sign");
 4524|    235|}
framework-pkcs15.c:pkcs15_prkey_decrypt:
 4597|    376|{
 4598|    376|	struct sc_pkcs11_card *p11card = session->slot->p11card;
 4599|    376|	struct pkcs15_fw_data *fw_data = NULL;
 4600|    376|	struct pkcs15_prkey_object *prkey;
 4601|    376|	unsigned char decrypted[512]; /* FIXME: Will not work for keys above 4096 bits */
 4602|    376|	int rv, flags = 0;
 4603|    376|	CK_ULONG mask, good, rv_pkcs11;
 4604|       |
 4605|    376|	if (pulDataLen == NULL) {
  ------------------
  |  Branch (4605:6): [True: 187, False: 189]
  ------------------
 4606|       |		/* This is call from the C_DecyptInit function */
 4607|    187|		sc_log(context, "C_DecryptInit...");
  ------------------
  |  |   71|    187|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4608|    187|		return CKR_OK;
  ------------------
  |  | 1086|    187|#define CKR_OK 0x00000000UL
  ------------------
 4609|    187|	}
 4610|    189|	if (pEncryptedData == NULL && ulEncryptedDataLen == 0) {
  ------------------
  |  Branch (4610:6): [True: 3, False: 186]
  |  Branch (4610:32): [True: 3, False: 0]
  ------------------
 4611|       |		/* This is call from the C_DecryptFinalize function */
 4612|      3|		sc_log(context, "C_DecryptFinalize...");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4613|      3|		*pulDataLen = 0;
 4614|      3|		return CKR_OK;
  ------------------
  |  | 1086|      3|#define CKR_OK 0x00000000UL
  ------------------
 4615|      3|	}
 4616|       |	/* DecryptUpdate: we assume this code is called only once per session, either
 4617|       |	 * from the C_Decrypt function or from an application using the C_DecryptUpdate call
 4618|       |	 */
 4619|       |
 4620|    186|	sc_log(context, "Initiating decryption.");
  ------------------
  |  |   71|    186|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4621|       |
 4622|    186|	if (!p11card)
  ------------------
  |  Branch (4622:6): [True: 0, False: 186]
  ------------------
 4623|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Decrypt");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4624|    186|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 4625|    186|	if (!fw_data)
  ------------------
  |  Branch (4625:6): [True: 0, False: 186]
  ------------------
 4626|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_Decrypt");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4627|    186|	if (!fw_data->p15_card)
  ------------------
  |  Branch (4627:6): [True: 0, False: 186]
  ------------------
 4628|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_Decrypt");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4629|       |
 4630|       |	/* See which of the alternative keys supports decrypt */
 4631|    186|	prkey = (struct pkcs15_prkey_object *) obj;
 4632|    213|	while (prkey  && !(prkey->prv_info->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|    213|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	while (prkey  && !(prkey->prv_info->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|    213|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (4632:9): [True: 213, False: 0]
  |  Branch (4632:19): [True: 27, False: 186]
  ------------------
 4633|     27|		prkey = prkey->prv_next;
  ------------------
  |  |  107|    213|#define prv_next		base.related_privkey
  ------------------
 4634|    186|	if (prkey == NULL)
  ------------------
  |  Branch (4634:6): [True: 0, False: 186]
  ------------------
 4635|      0|		return CKR_KEY_FUNCTION_NOT_PERMITTED;
  ------------------
  |  | 1119|      0|#define CKR_KEY_FUNCTION_NOT_PERMITTED 0x00000068UL
  ------------------
 4636|       |
 4637|       |	/* Select the proper padding mechanism */
 4638|    186|	switch (pMechanism->mechanism) {
 4639|    181|	case CKM_RSA_PKCS:
  ------------------
  |  |  539|    181|#define CKM_RSA_PKCS 0x00000001UL
  ------------------
  |  Branch (4639:2): [True: 181, False: 5]
  ------------------
 4640|    181|		flags |= SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|    181|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 4641|    181|		break;
 4642|      4|	case CKM_RSA_X_509:
  ------------------
  |  |  541|      4|#define CKM_RSA_X_509 0x00000003UL
  ------------------
  |  Branch (4642:2): [True: 4, False: 182]
  ------------------
 4643|      4|		flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|      4|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 4644|      4|		break;
 4645|      0|	case CKM_RSA_PKCS_OAEP:
  ------------------
  |  |  547|      0|#define CKM_RSA_PKCS_OAEP 0x00000009UL
  ------------------
  |  Branch (4645:2): [True: 0, False: 186]
  ------------------
 4646|      0|		flags |= SC_ALGORITHM_RSA_PAD_OAEP;
  ------------------
  |  |  108|      0|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
 4647|       |
 4648|       |		/* Omitted parameter can use MGF1-SHA1 and SHA1 hash ? */
 4649|      0|		if (pMechanism->pParameter == NULL) {
  ------------------
  |  Branch (4649:7): [True: 0, False: 0]
  ------------------
 4650|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
 4651|      0|			flags |= SC_ALGORITHM_MGF1_SHA1;
  ------------------
  |  |  145|      0|#define SC_ALGORITHM_MGF1_SHA1		0x00100000
  ------------------
 4652|      0|			break;
 4653|      0|		}
 4654|       |
 4655|      0|		switch (((CK_RSA_PKCS_OAEP_PARAMS*)pMechanism->pParameter)->hashAlg) {
 4656|      0|		case CKM_SHA_1:
  ------------------
  |  |  667|      0|#define CKM_SHA_1 0x00000220UL
  ------------------
  |  Branch (4656:3): [True: 0, False: 0]
  ------------------
 4657|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
 4658|      0|			break;
 4659|      0|		case CKM_SHA224:
  ------------------
  |  |  679|      0|#define CKM_SHA224 0x00000255UL
  ------------------
  |  Branch (4659:3): [True: 0, False: 0]
  ------------------
 4660|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA224;
  ------------------
  |  |  141|      0|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
 4661|      0|			break;
 4662|      0|		case CKM_SHA256:
  ------------------
  |  |  676|      0|#define CKM_SHA256 0x00000250UL
  ------------------
  |  Branch (4662:3): [True: 0, False: 0]
  ------------------
 4663|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
 4664|      0|			break;
 4665|      0|		case CKM_SHA384:
  ------------------
  |  |  682|      0|#define CKM_SHA384 0x00000260UL
  ------------------
  |  Branch (4665:3): [True: 0, False: 0]
  ------------------
 4666|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA384;
  ------------------
  |  |  139|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
 4667|      0|			break;
 4668|      0|		case CKM_SHA512:
  ------------------
  |  |  685|      0|#define CKM_SHA512 0x00000270UL
  ------------------
  |  Branch (4668:3): [True: 0, False: 0]
  ------------------
 4669|      0|			flags |= SC_ALGORITHM_RSA_HASH_SHA512;
  ------------------
  |  |  140|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 4670|      0|			break;
 4671|      0|		default:
  ------------------
  |  Branch (4671:3): [True: 0, False: 0]
  ------------------
 4672|      0|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4673|      0|		}
 4674|       |
 4675|       |		/* The MGF parameter was already verified in SignInit() */
 4676|      0|		flags |= mgf2flags(((CK_RSA_PKCS_OAEP_PARAMS*)pMechanism->pParameter)->mgf);
 4677|      0|		break;
 4678|      1|	default:
  ------------------
  |  Branch (4678:2): [True: 1, False: 185]
  ------------------
 4679|      1|		return CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|      1|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
 4680|    186|	}
 4681|       |
 4682|    185|	rv = sc_lock(p11card->card);
 4683|    185|	if (rv < 0)
  ------------------
  |  Branch (4683:6): [True: 0, False: 185]
  ------------------
 4684|      0|		return sc_to_cryptoki_error(rv, "C_Decrypt");
 4685|       |
 4686|    185|	rv = sc_pkcs15_decipher(fw_data->p15_card, prkey->prv_p15obj, flags,
  ------------------
  |  |  105|    185|#define prv_p15obj		base.p15_object
  ------------------
 4687|    185|			pEncryptedData, ulEncryptedDataLen, decrypted, sizeof(decrypted), pMechanism);
 4688|       |
 4689|    185|	sc_unlock(p11card->card);
 4690|       |
 4691|    185|	sc_log(context, "Decryption complete.");
  ------------------
  |  |   71|    185|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4692|       |
 4693|       |	/* Handle following code in constant-time
 4694|       |	 * to prevent Marvin attack for PKCS#1 v1.5 padding. */
 4695|       |
 4696|       |	/* only padding error must be handled in constant-time way,
 4697|       |	 * other error can be returned straight away */
 4698|    185|	if ((~constant_time_eq_s((size_t)rv, (size_t)SC_ERROR_WRONG_PADDING) & constant_time_lt_s(sizeof(decrypted), (size_t)rv)))
  ------------------
  |  |   93|    185|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
  |  Branch (4698:6): [True: 118, False: 67]
  ------------------
 4699|    118|		return sc_to_cryptoki_error(rv, "C_Decrypt");
 4700|       |
 4701|       |	/* check rv for padding error */
 4702|     67|	good = ~constant_time_eq_i(rv, SC_ERROR_WRONG_PADDING);
  ------------------
  |  |   93|     67|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
 4703|     67|	rv_pkcs11 = sc_to_cryptoki_error(SC_ERROR_WRONG_PADDING, "C_Decrypt");
  ------------------
  |  |   93|     67|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
 4704|     67|	rv_pkcs11 = constant_time_select_s(good, CKR_OK, rv_pkcs11);
  ------------------
  |  | 1086|     67|#define CKR_OK 0x00000000UL
  ------------------
 4705|       |
 4706|     67|	if (pData == NULL_PTR) {
  ------------------
  |  |   27|     67|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (4706:6): [True: 0, False: 67]
  ------------------
 4707|       |		/* set length only if no error */
 4708|      0|		*pulDataLen = constant_time_select_s(good, rv, *pulDataLen);
 4709|       |		/* return error only if original rv < 0 */
 4710|      0|		return rv_pkcs11;
 4711|      0|	}
 4712|       |
 4713|       |	/* check whether *pulDataLen < rv and set return value for small output buffer */
 4714|     67|	mask = good & constant_time_lt_s(*pulDataLen, rv);
 4715|     67|	rv_pkcs11 = constant_time_select_s(mask, CKR_BUFFER_TOO_SMALL, rv_pkcs11);
  ------------------
  |  | 1165|     67|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
 4716|     67|	good &= ~mask;
 4717|       |
 4718|       |	/* move everything from decrypted into out buffer constant-time, if rv is ok */
 4719|  68.6k|	for (CK_ULONG i = 0; i < *pulDataLen; i++) { /* iterate over whole pData to not disclose real depadded length */
  ------------------
  |  Branch (4719:23): [True: 68.6k, False: 67]
  ------------------
 4720|  68.6k|		CK_ULONG msg_index;
 4721|  68.6k|		mask = good & constant_time_lt_s(i, sizeof(decrypted));		    /* i should be in the bounds of decrypted */
 4722|  68.6k|		mask &= constant_time_lt_s(i, constant_time_select_s(good, rv, 0)); /* check that is in bounds of depadded message */
 4723|  68.6k|		msg_index = constant_time_select_s(mask, i, 0);
 4724|  68.6k|		pData[i] = constant_time_select_8(mask, decrypted[msg_index], pData[i]);
 4725|  68.6k|	}
 4726|     67|	*pulDataLen = constant_time_select_s(good, rv, *pulDataLen);
 4727|       |	/* do not log error code to prevent side channel attack */
 4728|     67|	return rv_pkcs11;
 4729|     67|}
framework-pkcs15.c:pkcs15_prkey_can_do:
 4808|    431|{
 4809|    431|	struct sc_pkcs11_card *p11card = session->slot->p11card;
 4810|    431|	struct pkcs15_fw_data *fw_data = NULL;
 4811|    431|	struct pkcs15_prkey_object *prkey = (struct pkcs15_prkey_object *) obj;
 4812|    431|	struct sc_pkcs15_prkey_info *pkinfo = NULL;
 4813|    431|	struct sc_supported_algo_info *token_algos = NULL;
 4814|    431|	int ii, jj;
 4815|       |
 4816|    431|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|    431|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    431|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    431|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    431|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 431]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4817|    431|	sc_log(context, "check hardware capabilities: CK_MECHANISM_TYPE=0x%lx (CKM) and CKF_xxx=0x%x", mech_type, flags);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4818|       |
 4819|    431|	if (!prkey || !prkey->prv_info)
  ------------------
  |  Branch (4819:6): [True: 0, False: 431]
  |  Branch (4819:16): [True: 0, False: 431]
  ------------------
 4820|    431|		LOG_FUNC_RETURN(context, CKR_KEY_FUNCTION_NOT_PERMITTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4821|       |
 4822|    431|	pkinfo = prkey->prv_info;
 4823|       |	/* Return if there are no usage algorithms specified for this key. */
 4824|    431|	if (!pkinfo->algo_refs[0])
  ------------------
  |  Branch (4824:6): [True: 431, False: 0]
  ------------------
 4825|    431|		LOG_FUNC_RETURN(context, CKR_FUNCTION_NOT_SUPPORTED);
  ------------------
  |  |  164|    431|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    431|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    431|	int _ret = r; \
  |  |  |  |  155|    431|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 431]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    431|	} else { \
  |  |  |  |  159|    431|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    431|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    431|	} \
  |  |  |  |  162|    431|	return _ret; \
  |  |  |  |  163|    431|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4826|       |
 4827|      0|	if (!p11card)
  ------------------
  |  Branch (4827:6): [True: 0, False: 0]
  ------------------
 4828|      0|		LOG_FUNC_RETURN(context, CKR_FUNCTION_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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4829|      0|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 4830|      0|	if (!fw_data->p15_card)
  ------------------
  |  Branch (4830:6): [True: 0, False: 0]
  ------------------
 4831|      0|		LOG_FUNC_RETURN(context, CKR_FUNCTION_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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4832|      0|	token_algos = &fw_data->p15_card->tokeninfo->supported_algos[0];
 4833|       |
 4834|      0|	for (ii=0;ii<SC_MAX_SUPPORTED_ALGORITHMS && pkinfo->algo_refs[ii];ii++)   {
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (4834:12): [True: 0, False: 0]
  |  Branch (4834:46): [True: 0, False: 0]
  ------------------
 4835|       |		/* Look for algorithm supported by token referenced in the list of key's algorithms */
 4836|      0|		for (jj=0;jj<SC_MAX_SUPPORTED_ALGORITHMS && (token_algos + jj)->reference; jj++)
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (4836:13): [True: 0, False: 0]
  |  Branch (4836:47): [True: 0, False: 0]
  ------------------
 4837|      0|			if (pkinfo->algo_refs[ii] == (token_algos + jj)->reference)
  ------------------
  |  Branch (4837:8): [True: 0, False: 0]
  ------------------
 4838|      0|				break;
 4839|      0|		if ((jj == SC_MAX_SUPPORTED_ALGORITHMS) || !(token_algos + jj)->reference)
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (4839:7): [True: 0, False: 0]
  |  Branch (4839:46): [True: 0, False: 0]
  ------------------
 4840|      0|			LOG_FUNC_RETURN(context, CKR_GENERAL_ERROR);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4841|       |
 4842|      0|		if ((token_algos + jj)->mechanism != mech_type)
  ------------------
  |  Branch (4842:7): [True: 0, False: 0]
  ------------------
 4843|      0|			continue;
 4844|       |
 4845|      0|		if (flags == CKF_SIGN)
  ------------------
  |  |  363|      0|#define CKF_SIGN 0x00000800UL
  ------------------
  |  Branch (4845:7): [True: 0, False: 0]
  ------------------
 4846|      0|			if ((token_algos + jj)->operations & SC_PKCS15_ALGO_OP_COMPUTE_SIGNATURE)
  ------------------
  |  |  138|      0|#define SC_PKCS15_ALGO_OP_COMPUTE_SIGNATURE	0x02
  ------------------
  |  Branch (4846:8): [True: 0, False: 0]
  ------------------
 4847|      0|				break;
 4848|       |
 4849|      0|		if (flags == CKF_DECRYPT)
  ------------------
  |  |  361|      0|#define CKF_DECRYPT 0x00000200UL
  ------------------
  |  Branch (4849:7): [True: 0, False: 0]
  ------------------
 4850|      0|			if ((token_algos + jj)->operations & SC_PKCS15_ALGO_OP_DECIPHER)
  ------------------
  |  |  142|      0|#define SC_PKCS15_ALGO_OP_DECIPHER		0x20
  ------------------
  |  Branch (4850:8): [True: 0, False: 0]
  ------------------
 4851|      0|				break;
 4852|      0|	}
 4853|       |
 4854|      0|	if (ii == SC_MAX_SUPPORTED_ALGORITHMS || !pkinfo->algo_refs[ii])
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (4854:6): [True: 0, False: 0]
  |  Branch (4854:43): [True: 0, False: 0]
  ------------------
 4855|      0|		LOG_FUNC_RETURN(context, CKR_MECHANISM_INVALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4856|       |
 4857|      0|	LOG_FUNC_RETURN(context, CKR_OK);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4858|      0|}
framework-pkcs15.c:pkcs15_prkey_init_params:
 4864|    431|{
 4865|    431|	const CK_RSA_PKCS_PSS_PARAMS *pss_params;
 4866|    431|	unsigned int expected_hash = 0, i;
 4867|    431|	const unsigned int hashes[5] = { CKM_SHA_1, CKM_SHA256,
  ------------------
  |  |  667|    431|#define CKM_SHA_1 0x00000220UL
  ------------------
              	const unsigned int hashes[5] = { CKM_SHA_1, CKM_SHA256,
  ------------------
  |  |  676|    431|#define CKM_SHA256 0x00000250UL
  ------------------
 4868|    431|		CKM_SHA384, CKM_SHA512, CKM_SHA224 };
  ------------------
  |  |  682|    431|#define CKM_SHA384 0x00000260UL
  ------------------
              		CKM_SHA384, CKM_SHA512, CKM_SHA224 };
  ------------------
  |  |  685|    431|#define CKM_SHA512 0x00000270UL
  ------------------
              		CKM_SHA384, CKM_SHA512, CKM_SHA224 };
  ------------------
  |  |  679|    431|#define CKM_SHA224 0x00000255UL
  ------------------
 4869|    431|	const CK_RSA_PKCS_OAEP_PARAMS *oaep_params;
 4870|       |
 4871|    431|	switch (pMechanism->mechanism) {
  ------------------
  |  Branch (4871:10): [True: 7, False: 424]
  ------------------
 4872|      1|	case CKM_RSA_PKCS_PSS:
  ------------------
  |  |  551|      1|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
  |  Branch (4872:2): [True: 1, False: 430]
  ------------------
 4873|      2|	case CKM_SHA1_RSA_PKCS_PSS:
  ------------------
  |  |  552|      2|#define CKM_SHA1_RSA_PKCS_PSS 0x0000000EUL
  ------------------
  |  Branch (4873:2): [True: 1, False: 430]
  ------------------
 4874|      3|	case CKM_SHA224_RSA_PKCS_PSS:
  ------------------
  |  |  605|      3|#define CKM_SHA224_RSA_PKCS_PSS 0x00000047UL
  ------------------
  |  Branch (4874:2): [True: 1, False: 430]
  ------------------
 4875|      4|	case CKM_SHA256_RSA_PKCS_PSS:
  ------------------
  |  |  601|      4|#define CKM_SHA256_RSA_PKCS_PSS 0x00000043UL
  ------------------
  |  Branch (4875:2): [True: 1, False: 430]
  ------------------
 4876|      5|	case CKM_SHA384_RSA_PKCS_PSS:
  ------------------
  |  |  602|      5|#define CKM_SHA384_RSA_PKCS_PSS 0x00000044UL
  ------------------
  |  Branch (4876:2): [True: 1, False: 430]
  ------------------
 4877|      6|	case CKM_SHA512_RSA_PKCS_PSS:
  ------------------
  |  |  603|      6|#define CKM_SHA512_RSA_PKCS_PSS 0x00000045UL
  ------------------
  |  Branch (4877:2): [True: 1, False: 430]
  ------------------
 4878|      6|		if (!pMechanism->pParameter ||
  ------------------
  |  Branch (4878:7): [True: 6, False: 0]
  ------------------
 4879|      0|			pMechanism->ulParameterLen != sizeof(CK_RSA_PKCS_PSS_PARAMS))
  ------------------
  |  Branch (4879:4): [True: 0, False: 0]
  ------------------
 4880|      6|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      6|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4881|       |
 4882|      0|		pss_params = (CK_RSA_PKCS_PSS_PARAMS*)pMechanism->pParameter;
 4883|      0|		if (pss_params->mgf < CKG_MGF1_SHA1 || pss_params->mgf > CKG_MGF1_SHA224)
  ------------------
  |  |  442|      0|#define CKG_MGF1_SHA1 0x00000001UL
  ------------------
              		if (pss_params->mgf < CKG_MGF1_SHA1 || pss_params->mgf > CKG_MGF1_SHA224)
  ------------------
  |  |  446|      0|#define CKG_MGF1_SHA224 0x00000005UL
  ------------------
  |  Branch (4883:7): [True: 0, False: 0]
  |  Branch (4883:42): [True: 0, False: 0]
  ------------------
 4884|      0|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4885|       |
 4886|       |		/* The hashAlg field can have any value for CKM_RSA_PKCS_PSS and must be
 4887|       |		 * used again in the PSS padding; for the other mechanisms it strictly
 4888|       |		 * must match the padding declared in the mechanism.
 4889|       |		 */
 4890|      0|		if (pMechanism->mechanism == CKM_SHA1_RSA_PKCS_PSS) {
  ------------------
  |  |  552|      0|#define CKM_SHA1_RSA_PKCS_PSS 0x0000000EUL
  ------------------
  |  Branch (4890:7): [True: 0, False: 0]
  ------------------
 4891|      0|			expected_hash = CKM_SHA_1;
  ------------------
  |  |  667|      0|#define CKM_SHA_1 0x00000220UL
  ------------------
 4892|      0|		} else if (pMechanism->mechanism == CKM_SHA224_RSA_PKCS_PSS) {
  ------------------
  |  |  605|      0|#define CKM_SHA224_RSA_PKCS_PSS 0x00000047UL
  ------------------
  |  Branch (4892:14): [True: 0, False: 0]
  ------------------
 4893|      0|			expected_hash = CKM_SHA224;
  ------------------
  |  |  679|      0|#define CKM_SHA224 0x00000255UL
  ------------------
 4894|      0|		} else if (pMechanism->mechanism == CKM_SHA256_RSA_PKCS_PSS) {
  ------------------
  |  |  601|      0|#define CKM_SHA256_RSA_PKCS_PSS 0x00000043UL
  ------------------
  |  Branch (4894:14): [True: 0, False: 0]
  ------------------
 4895|      0|			expected_hash = CKM_SHA256;
  ------------------
  |  |  676|      0|#define CKM_SHA256 0x00000250UL
  ------------------
 4896|      0|		} else if (pMechanism->mechanism == CKM_SHA384_RSA_PKCS_PSS) {
  ------------------
  |  |  602|      0|#define CKM_SHA384_RSA_PKCS_PSS 0x00000044UL
  ------------------
  |  Branch (4896:14): [True: 0, False: 0]
  ------------------
 4897|      0|			expected_hash = CKM_SHA384;
  ------------------
  |  |  682|      0|#define CKM_SHA384 0x00000260UL
  ------------------
 4898|      0|		} else if (pMechanism->mechanism == CKM_SHA512_RSA_PKCS_PSS) {
  ------------------
  |  |  603|      0|#define CKM_SHA512_RSA_PKCS_PSS 0x00000045UL
  ------------------
  |  Branch (4898:14): [True: 0, False: 0]
  ------------------
 4899|      0|			expected_hash = CKM_SHA512;
  ------------------
  |  |  685|      0|#define CKM_SHA512 0x00000270UL
  ------------------
 4900|      0|		} else if (pMechanism->mechanism == CKM_RSA_PKCS_PSS) {
  ------------------
  |  |  551|      0|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
  |  Branch (4900:14): [True: 0, False: 0]
  ------------------
 4901|      0|			for (i = 0; i < 5; ++i) {
  ------------------
  |  Branch (4901:16): [True: 0, False: 0]
  ------------------
 4902|      0|				if (hashes[i] == pss_params->hashAlg) {
  ------------------
  |  Branch (4902:9): [True: 0, False: 0]
  ------------------
 4903|      0|					expected_hash = hashes[i];
 4904|      0|				}
 4905|      0|			}
 4906|      0|		}
 4907|       |
 4908|      0|		if (expected_hash != pss_params->hashAlg)
  ------------------
  |  Branch (4908:7): [True: 0, False: 0]
  ------------------
 4909|      0|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4910|       |
 4911|      0|		break;
 4912|      1|	case CKM_RSA_PKCS_OAEP:
  ------------------
  |  |  547|      1|#define CKM_RSA_PKCS_OAEP 0x00000009UL
  ------------------
  |  Branch (4912:2): [True: 1, False: 430]
  ------------------
 4913|      1|		if (!pMechanism->pParameter ||
  ------------------
  |  Branch (4913:7): [True: 1, False: 0]
  ------------------
 4914|      0|			pMechanism->ulParameterLen != sizeof(CK_RSA_PKCS_OAEP_PARAMS))
  ------------------
  |  Branch (4914:4): [True: 0, False: 0]
  ------------------
 4915|      1|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      1|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4916|       |
 4917|      0|		oaep_params = (CK_RSA_PKCS_OAEP_PARAMS*)pMechanism->pParameter;
 4918|      0|		switch (oaep_params->mgf) {
 4919|      0|		case CKG_MGF1_SHA1:
  ------------------
  |  |  442|      0|#define CKG_MGF1_SHA1 0x00000001UL
  ------------------
  |  Branch (4919:3): [True: 0, False: 0]
  ------------------
 4920|      0|		case CKG_MGF1_SHA224:
  ------------------
  |  |  446|      0|#define CKG_MGF1_SHA224 0x00000005UL
  ------------------
  |  Branch (4920:3): [True: 0, False: 0]
  ------------------
 4921|      0|		case CKG_MGF1_SHA256:
  ------------------
  |  |  443|      0|#define CKG_MGF1_SHA256 0x00000002UL
  ------------------
  |  Branch (4921:3): [True: 0, False: 0]
  ------------------
 4922|      0|		case CKG_MGF1_SHA384:
  ------------------
  |  |  444|      0|#define CKG_MGF1_SHA384 0x00000003UL
  ------------------
  |  Branch (4922:3): [True: 0, False: 0]
  ------------------
 4923|      0|		case CKG_MGF1_SHA512:
  ------------------
  |  |  445|      0|#define CKG_MGF1_SHA512 0x00000004UL
  ------------------
  |  Branch (4923:3): [True: 0, False: 0]
  ------------------
 4924|       |			/* OK */
 4925|      0|			break;
 4926|      0|		default:
  ------------------
  |  Branch (4926:3): [True: 0, False: 0]
  ------------------
 4927|      0|			return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
 4928|      0|		}
 4929|       |		/* TODO is there something more to check */
 4930|      0|		break;
 4931|    431|	}
 4932|    424|	return CKR_OK;
  ------------------
  |  | 1086|    424|#define CKR_OK 0x00000000UL
  ------------------
 4933|    431|}
framework-pkcs15.c:pkcs15_pubkey_release:
 4958|  2.65k|{
 4959|  2.65k|	struct pkcs15_pubkey_object *pubkey = (struct pkcs15_pubkey_object*) object;
 4960|  2.65k|	struct sc_pkcs15_pubkey *key_data = pubkey->pub_data;
 4961|       |
 4962|  2.65k|	if (__pkcs15_release_object((struct pkcs15_any_object *) object) == 0)
  ------------------
  |  Branch (4962:6): [True: 1.34k, False: 1.31k]
  ------------------
 4963|  1.34k|		if (key_data)
  ------------------
  |  Branch (4963:7): [True: 1.05k, False: 292]
  ------------------
 4964|  1.05k|			sc_pkcs15_free_pubkey(key_data);
 4965|  2.65k|}
framework-pkcs15.c:pkcs15_pubkey_get_attribute:
 4979|  6.82k|{
 4980|  6.82k|	struct sc_pkcs11_card *p11card = NULL;
 4981|  6.82k|	struct pkcs15_pubkey_object *pubkey = (struct pkcs15_pubkey_object*) object;
 4982|  6.82k|	struct pkcs15_cert_object *cert = NULL;
 4983|  6.82k|	struct pkcs15_fw_data *fw_data = NULL;
 4984|  6.82k|	size_t len;
 4985|       |
 4986|  6.82k|	sc_log(context, "pkcs15_pubkey_get_attribute() called");
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
 4987|       |
 4988|  6.82k|	p11card = session->slot->p11card;
 4989|  6.82k|	cert = pubkey->pub_genfrom;
  ------------------
  |  |  117|  6.82k|#define pub_genfrom		base.related_cert
  ------------------
 4990|       |
 4991|  6.82k|	if (!p11card)
  ------------------
  |  Branch (4991:6): [True: 0, False: 6.82k]
  ------------------
 4992|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4993|  6.82k|	fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
 4994|  6.82k|	if (!fw_data)
  ------------------
  |  Branch (4994:6): [True: 0, False: 6.82k]
  ------------------
 4995|      0|		return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4996|  6.82k|	if (!fw_data->p15_card)
  ------------------
  |  Branch (4996:6): [True: 0, False: 6.82k]
  ------------------
 4997|      0|		return sc_to_cryptoki_error(SC_ERROR_INVALID_CARD, "C_GetAttributeValue");
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4998|       |
 4999|       |	/* We may need to get these from cert */
 5000|  6.82k|	switch (attr->type) {
  ------------------
  |  Branch (5000:10): [True: 96, False: 6.72k]
  ------------------
 5001|      0|		case CKA_MODULUS:
  ------------------
  |  |  174|      0|#define CKA_MODULUS 0x00000120UL
  ------------------
  |  Branch (5001:3): [True: 0, False: 6.82k]
  ------------------
 5002|      0|		case CKA_MODULUS_BITS:
  ------------------
  |  |  175|      0|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
  |  Branch (5002:3): [True: 0, False: 6.82k]
  ------------------
 5003|      0|		case CKA_VALUE:
  ------------------
  |  |  143|      0|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (5003:3): [True: 0, False: 6.82k]
  ------------------
 5004|     96|		case CKA_SPKI:
  ------------------
  |  |   21|     96|#define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |  289|     96|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |   12|     96|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
  |  Branch (5004:3): [True: 96, False: 6.72k]
  ------------------
 5005|     96|		case CKA_PUBLIC_KEY_INFO:
  ------------------
  |  |  183|     96|#define CKA_PUBLIC_KEY_INFO 0x00000129UL
  ------------------
  |  Branch (5005:3): [True: 0, False: 6.82k]
  ------------------
 5006|     96|		case CKA_PUBLIC_EXPONENT:
  ------------------
  |  |  176|     96|#define CKA_PUBLIC_EXPONENT 0x00000122UL
  ------------------
  |  Branch (5006:3): [True: 0, False: 6.82k]
  ------------------
 5007|     96|		case CKA_EC_PARAMS:
  ------------------
  |  |  200|     96|#define CKA_EC_PARAMS 0x00000180UL
  ------------------
  |  Branch (5007:3): [True: 0, False: 6.82k]
  ------------------
 5008|     96|		case CKA_EC_POINT:
  ------------------
  |  |  201|     96|#define CKA_EC_POINT 0x00000181UL
  ------------------
  |  Branch (5008:3): [True: 0, False: 6.82k]
  ------------------
 5009|     96|			if (pubkey->pub_data == NULL)
  ------------------
  |  Branch (5009:8): [True: 3, False: 93]
  ------------------
 5010|      3|				if (SC_SUCCESS != check_cert_data_read(fw_data, cert))
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (5010:9): [True: 3, False: 0]
  ------------------
 5011|      3|					return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "check_cert_data_read");
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 5012|     93|			break;
 5013|  6.82k|	}
 5014|       |
 5015|  6.82k|	switch (attr->type) {
 5016|  3.54k|	case CKA_CLASS:
  ------------------
  |  |  137|  3.54k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (5016:2): [True: 3.54k, False: 3.28k]
  ------------------
 5017|  3.54k|		check_attribute_buffer(attr, sizeof(CK_OBJECT_CLASS));
  ------------------
  |  |   56|  3.54k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  7.08k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 1.77k, False: 1.77k]
  |  |  ------------------
  |  |   57|  1.77k|		attr->ulValueLen = size;        \
  |  |   58|  1.77k|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|  1.77k|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|  1.77k|	}                                       \
  |  |   60|  3.54k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.77k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.77k|	attr->ulValueLen = size;
  ------------------
 5018|  1.77k|		*(CK_OBJECT_CLASS*)attr->pValue = CKO_PUBLIC_KEY;
  ------------------
  |  | 1029|  1.77k|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
 5019|  1.77k|		break;
 5020|      0|	case CKA_TOKEN:
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (5020:2): [True: 0, False: 6.82k]
  ------------------
 5021|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5022|      0|		*(CK_BBOOL*)attr->pValue = TRUE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
 5023|      0|		break;
 5024|      0|	case CKA_SENSITIVE:
  ------------------
  |  |  162|      0|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (5024:2): [True: 0, False: 6.82k]
  ------------------
 5025|       |		/* By PKCS#11 v2.20 public key cannot have SENSITIVE attr TRUE */
 5026|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5027|      0|		*(CK_BBOOL*)attr->pValue = FALSE;
  ------------------
  |  |   48|      0|#define FALSE 0
  ------------------
 5028|      0|		break;
 5029|      0|	case CKA_LOCAL:
  ------------------
  |  |  193|      0|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (5029:2): [True: 0, False: 6.82k]
  ------------------
 5030|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5031|      0|		if (pubkey->pub_info)
  ------------------
  |  Branch (5031:7): [True: 0, False: 0]
  ------------------
 5032|      0|			*(CK_BBOOL*)attr->pValue = (pubkey->pub_info->access_flags & SC_PKCS15_PRKEY_ACCESS_LOCAL) != 0;
  ------------------
  |  |  320|      0|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
 5033|      0|		else /* no pub_info structure, falling back to TRUE */
 5034|      0|			*(CK_BBOOL*)attr->pValue = TRUE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
 5035|      0|		break;
 5036|  1.62k|	case CKA_PRIVATE:
  ------------------
  |  |  139|  1.62k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (5036:2): [True: 1.62k, False: 5.19k]
  ------------------
 5037|  3.25k|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|  1.62k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  3.25k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 1.62k]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|  1.62k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.62k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.62k|	attr->ulValueLen = size;
  ------------------
 5038|  3.25k|		if (pubkey->pub_p15obj)
  ------------------
  |  |  116|  1.62k|#define pub_p15obj		base.p15_object
  ------------------
  |  Branch (5038:7): [True: 1.48k, False: 141]
  ------------------
 5039|  1.48k|			*(CK_BBOOL*)attr->pValue = (pubkey->pub_p15obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |  116|  1.48k|#define pub_p15obj		base.p15_object
  ------------------
              			*(CK_BBOOL*)attr->pValue = (pubkey->pub_p15obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |   50|  1.48k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 5040|    141|		else if (cert && cert->cert_p15obj)
  ------------------
  |  |   93|    141|#define cert_p15obj		base.p15_object
  ------------------
  |  Branch (5040:12): [True: 141, False: 0]
  |  Branch (5040:20): [True: 141, False: 0]
  ------------------
 5041|    141|			*(CK_BBOOL*)attr->pValue = (cert->pub_p15obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |  116|    141|#define pub_p15obj		base.p15_object
  ------------------
              			*(CK_BBOOL*)attr->pValue = (cert->pub_p15obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |   50|    141|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 5042|      0|		else
 5043|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5044|  1.62k|		break;
 5045|  1.62k|	case CKA_MODIFIABLE:
  ------------------
  |  |  197|      0|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (5045:2): [True: 0, False: 6.82k]
  ------------------
 5046|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5047|      0|		if (pubkey->pub_p15obj)
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
  |  Branch (5047:7): [True: 0, False: 0]
  ------------------
 5048|      0|			*(CK_BBOOL*)attr->pValue = (pubkey->pub_p15obj->flags & SC_PKCS15_CO_FLAG_MODIFIABLE) != 0;
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
              			*(CK_BBOOL*)attr->pValue = (pubkey->pub_p15obj->flags & SC_PKCS15_CO_FLAG_MODIFIABLE) != 0;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
 5049|      0|		else if (cert && cert->cert_p15obj)
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
  |  Branch (5049:12): [True: 0, False: 0]
  |  Branch (5049:20): [True: 0, False: 0]
  ------------------
 5050|      0|			*(CK_BBOOL*)attr->pValue = (cert->pub_p15obj->flags & SC_PKCS15_CO_FLAG_MODIFIABLE) != 0;
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
              			*(CK_BBOOL*)attr->pValue = (cert->pub_p15obj->flags & SC_PKCS15_CO_FLAG_MODIFIABLE) != 0;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
 5051|      0|		else
 5052|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5053|      0|		break;
 5054|      0|	case CKA_EXTRACTABLE:
  ------------------
  |  |  192|      0|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (5054:2): [True: 0, False: 6.82k]
  ------------------
 5055|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5056|      0|		if (pubkey->pub_info)
  ------------------
  |  Branch (5056:7): [True: 0, False: 0]
  ------------------
 5057|      0|			*(CK_BBOOL*)attr->pValue = (pubkey->pub_info->access_flags & SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE) != 0;
  ------------------
  |  |  317|      0|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
 5058|      0|		else /* no pub_info structure, falling back to TRUE */
 5059|      0|			*(CK_BBOOL*)attr->pValue = TRUE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
 5060|      0|		break;
 5061|      0|	case CKA_LABEL:
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (5061:2): [True: 0, False: 6.82k]
  ------------------
 5062|      0|		if (pubkey->pub_p15obj) {
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
  |  Branch (5062:7): [True: 0, False: 0]
  ------------------
 5063|      0|			len = strnlen(pubkey->pub_p15obj->label, sizeof pubkey->pub_p15obj->label);
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
              			len = strnlen(pubkey->pub_p15obj->label, sizeof pubkey->pub_p15obj->label);
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
 5064|      0|			check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5065|      0|			memcpy(attr->pValue, pubkey->pub_p15obj->label, len);
  ------------------
  |  |  116|      0|#define pub_p15obj		base.p15_object
  ------------------
 5066|      0|		}
 5067|      0|		else if (cert && cert->cert_p15obj) {
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
  |  Branch (5067:12): [True: 0, False: 0]
  |  Branch (5067:20): [True: 0, False: 0]
  ------------------
 5068|      0|			len = strnlen(cert->cert_p15obj->label, sizeof cert->cert_p15obj->label);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
              			len = strnlen(cert->cert_p15obj->label, sizeof cert->cert_p15obj->label);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
 5069|      0|			check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5070|      0|			memcpy(attr->pValue, cert->cert_p15obj->label, len);
  ------------------
  |  |   93|      0|#define cert_p15obj		base.p15_object
  ------------------
 5071|      0|		}
 5072|      0|		else {
 5073|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5074|      0|		}
 5075|      0|		break;
 5076|    120|	case CKA_KEY_TYPE:
  ------------------
  |  |  159|    120|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (5076:2): [True: 120, False: 6.70k]
  ------------------
 5077|    120|		check_attribute_buffer(attr, sizeof(CK_KEY_TYPE));
  ------------------
  |  |   56|    120|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|    240|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 120]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|    120|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 120]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    120|	attr->ulValueLen = size;
  ------------------
 5078|       |		/* TODO: -DEE why would we not have a pubkey->pub_data? */
 5079|       |		/* even if we do not, we should not assume RSA */
 5080|    120|		if (pubkey->pub_data && pubkey->pub_data->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   71|    111|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (5080:7): [True: 111, False: 9]
  |  Branch (5080:27): [True: 0, False: 111]
  ------------------
 5081|      0|			*(CK_KEY_TYPE*)attr->pValue = CKK_GOSTR3410;
  ------------------
  |  |  502|      0|#define CKK_GOSTR3410 0x00000030UL
  ------------------
 5082|    120|		else if (pubkey->pub_data && pubkey->pub_data->algorithm == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    111|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (5082:12): [True: 111, False: 9]
  |  Branch (5082:32): [True: 0, False: 111]
  ------------------
 5083|      0|			*(CK_KEY_TYPE*)attr->pValue = CKK_EC_EDWARDS;
  ------------------
  |  |  518|      0|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
 5084|    120|		else if (pubkey->pub_data && pubkey->pub_data->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|    111|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (5084:12): [True: 111, False: 9]
  |  Branch (5084:32): [True: 0, False: 111]
  ------------------
 5085|      0|			*(CK_KEY_TYPE*)attr->pValue = CKK_EC_MONTGOMERY;
  ------------------
  |  |  519|      0|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
 5086|    120|		else if (pubkey->pub_data && pubkey->pub_data->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|    111|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (5086:12): [True: 111, False: 9]
  |  Branch (5086:32): [True: 65, False: 46]
  ------------------
 5087|     65|			*(CK_KEY_TYPE*)attr->pValue = CKK_EC;
  ------------------
  |  |  467|     65|#define CKK_EC 0x00000003UL
  ------------------
 5088|     55|		else
 5089|     55|			*(CK_KEY_TYPE*)attr->pValue = CKK_RSA;
  ------------------
  |  |  464|     55|#define CKK_RSA 0x00000000UL
  ------------------
 5090|    120|		break;
 5091|  1.43k|	case CKA_ID:
  ------------------
  |  |  161|  1.43k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (5091:2): [True: 1.43k, False: 5.38k]
  ------------------
 5092|  1.43k|		if (pubkey->pub_info) {
  ------------------
  |  Branch (5092:7): [True: 1.40k, False: 34]
  ------------------
 5093|  1.40k|			check_attribute_buffer(attr, pubkey->pub_info->id.len);
  ------------------
  |  |   56|  1.40k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  2.80k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 718, False: 686]
  |  |  ------------------
  |  |   57|    718|		attr->ulValueLen = size;        \
  |  |   58|    718|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|    718|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|    718|	}                                       \
  |  |   60|  1.40k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 686]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    686|	attr->ulValueLen = size;
  ------------------
 5094|  1.37k|			memcpy(attr->pValue, pubkey->pub_info->id.value, pubkey->pub_info->id.len);
 5095|  1.37k|		}
 5096|     34|		else if (cert && cert->cert_info) {
  ------------------
  |  Branch (5096:12): [True: 34, False: 0]
  |  Branch (5096:20): [True: 34, False: 0]
  ------------------
 5097|     34|			check_attribute_buffer(attr, cert->cert_info->id.len);
  ------------------
  |  |   56|     34|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|     68|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 18, False: 16]
  |  |  ------------------
  |  |   57|     18|		attr->ulValueLen = size;        \
  |  |   58|     18|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|     18|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|     18|	}                                       \
  |  |   60|     34|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 16]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|     16|	attr->ulValueLen = size;
  ------------------
 5098|     32|			memcpy(attr->pValue, cert->cert_info->id.value, cert->cert_info->id.len);
 5099|     32|		}
 5100|      0|		else {
 5101|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5102|      0|		}
 5103|    702|		break;
 5104|    702|	case CKA_KEY_GEN_MECHANISM:
  ------------------
  |  |  196|      0|#define CKA_KEY_GEN_MECHANISM 0x00000166UL
  ------------------
  |  Branch (5104:2): [True: 0, False: 6.82k]
  ------------------
 5105|      0|		check_attribute_buffer(attr, sizeof(CK_MECHANISM_TYPE));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5106|      0|		*(CK_MECHANISM_TYPE*)attr->pValue = CK_UNAVAILABLE_INFORMATION;
  ------------------
  |  |   32|      0|#define CK_UNAVAILABLE_INFORMATION ~0UL
  ------------------
 5107|      0|		break;
 5108|      0|	case CKA_ENCRYPT:
  ------------------
  |  |  163|      0|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (5108:2): [True: 0, False: 6.82k]
  ------------------
 5109|      0|	case CKA_WRAP:
  ------------------
  |  |  165|      0|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (5109:2): [True: 0, False: 6.82k]
  ------------------
 5110|      0|	case CKA_VERIFY:
  ------------------
  |  |  169|      0|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (5110:2): [True: 0, False: 6.82k]
  ------------------
 5111|      0|	case CKA_VERIFY_RECOVER:
  ------------------
  |  |  170|      0|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (5111:2): [True: 0, False: 6.82k]
  ------------------
 5112|      0|	case CKA_DERIVE:
  ------------------
  |  |  171|      0|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (5112:2): [True: 0, False: 6.82k]
  ------------------
 5113|      0|		if (pubkey->pub_info)
  ------------------
  |  Branch (5113:7): [True: 0, False: 0]
  ------------------
 5114|      0|			return get_usage_bit(pubkey->pub_info->usage, attr);
 5115|      0|		else
 5116|      0|			return get_usage_bit(SC_PKCS15_PRKEY_USAGE_ENCRYPT |SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER, attr);
  ------------------
  |  |  305|      0|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              			return get_usage_bit(SC_PKCS15_PRKEY_USAGE_ENCRYPT |SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER, attr);
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              			return get_usage_bit(SC_PKCS15_PRKEY_USAGE_ENCRYPT |SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER, attr);
  ------------------
  |  |  312|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
 5117|      0|	case CKA_MODULUS:
  ------------------
  |  |  174|      0|#define CKA_MODULUS 0x00000120UL
  ------------------
  |  Branch (5117:2): [True: 0, False: 6.82k]
  ------------------
 5118|      0|		return get_modulus(pubkey->pub_data, attr);
 5119|      0|	case CKA_MODULUS_BITS:
  ------------------
  |  |  175|      0|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
  |  Branch (5119:2): [True: 0, False: 6.82k]
  ------------------
 5120|      0|		return get_modulus_bits(pubkey->pub_data, attr);
 5121|      0|	case CKA_PUBLIC_EXPONENT:
  ------------------
  |  |  176|      0|#define CKA_PUBLIC_EXPONENT 0x00000122UL
  ------------------
  |  Branch (5121:2): [True: 0, False: 6.82k]
  ------------------
 5122|      0|		return get_public_exponent(pubkey->pub_data, attr);
 5123|       |	/*
 5124|       |	 * PKCS#11 does not define a CKA_VALUE for a CKO_PUBLIC_KEY.
 5125|       |	 * OpenSC does, but it is not consistent it what it returns
 5126|       |	 * Internally to do verify, with OpenSSL, we need a SPKI that
 5127|       |	 * can be converted into a EVP_KEY with d2i_PUBKEY
 5128|       |	 * CKA_SPKI is defined internally as a CKA_VENDOR_DFINED attribute.
 5129|       |	 */
 5130|      0|	case CKA_VALUE:
  ------------------
  |  |  143|      0|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (5130:2): [True: 0, False: 6.82k]
  ------------------
 5131|     93|	case CKA_SPKI:
  ------------------
  |  |   21|     93|#define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |  289|     93|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |   12|     93|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
  |  Branch (5131:2): [True: 93, False: 6.72k]
  ------------------
 5132|     93|	case CKA_PUBLIC_KEY_INFO:
  ------------------
  |  |  183|     93|#define CKA_PUBLIC_KEY_INFO 0x00000129UL
  ------------------
  |  Branch (5132:2): [True: 0, False: 6.82k]
  ------------------
 5133|       |
 5134|     93|		if (attr->type != CKA_SPKI && attr->type != CKA_PUBLIC_KEY_INFO && pubkey->pub_info && pubkey->pub_info->direct.raw.value && pubkey->pub_info->direct.raw.len) {
  ------------------
  |  |   21|    186|#define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |  289|     93|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |   12|     93|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
              		if (attr->type != CKA_SPKI && attr->type != CKA_PUBLIC_KEY_INFO && pubkey->pub_info && pubkey->pub_info->direct.raw.value && pubkey->pub_info->direct.raw.len) {
  ------------------
  |  |  183|     93|#define CKA_PUBLIC_KEY_INFO 0x00000129UL
  ------------------
  |  Branch (5134:7): [True: 0, False: 93]
  |  Branch (5134:33): [True: 0, False: 0]
  |  Branch (5134:70): [True: 0, False: 0]
  |  Branch (5134:90): [True: 0, False: 0]
  |  Branch (5134:128): [True: 0, False: 0]
  ------------------
 5135|      0|			check_attribute_buffer(attr, pubkey->pub_info->direct.raw.len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5136|      0|			memcpy(attr->pValue, pubkey->pub_info->direct.raw.value, pubkey->pub_info->direct.raw.len);
 5137|     93|		} else if (pubkey->pub_info && pubkey->pub_info->direct.spki.value && pubkey->pub_info->direct.spki.len) {
  ------------------
  |  Branch (5137:14): [True: 86, False: 7]
  |  Branch (5137:34): [True: 86, False: 0]
  |  Branch (5137:73): [True: 86, False: 0]
  ------------------
 5138|     86|			check_attribute_buffer(attr, pubkey->pub_info->direct.spki.len);
  ------------------
  |  |   56|     86|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|    172|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 43, False: 43]
  |  |  ------------------
  |  |   57|     43|		attr->ulValueLen = size;        \
  |  |   58|     43|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|     43|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|     43|	}                                       \
  |  |   60|     86|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 43]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|     43|	attr->ulValueLen = size;
  ------------------
 5139|     86|			memcpy(attr->pValue, pubkey->pub_info->direct.spki.value, pubkey->pub_info->direct.spki.len);
 5140|     86|		} else if (pubkey->pub_data) {
  ------------------
  |  Branch (5140:14): [True: 7, False: 0]
  ------------------
 5141|      7|			unsigned char *value = NULL;
 5142|      7|			size_t len;
 5143|       |
 5144|      7|			if (attr->type != CKA_SPKI && attr->type != CKA_PUBLIC_KEY_INFO) {
  ------------------
  |  |   21|     14|#define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |  289|      7|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |   12|      7|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
              			if (attr->type != CKA_SPKI && attr->type != CKA_PUBLIC_KEY_INFO) {
  ------------------
  |  |  183|      0|#define CKA_PUBLIC_KEY_INFO 0x00000129UL
  ------------------
  |  Branch (5144:8): [True: 0, False: 7]
  |  Branch (5144:34): [True: 0, False: 0]
  ------------------
 5145|      0|				if (sc_pkcs15_encode_pubkey(context, pubkey->pub_data, &value, &len))
  ------------------
  |  Branch (5145:9): [True: 0, False: 0]
  ------------------
 5146|      0|					return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 5147|      7|			} else {
 5148|      7|				if (sc_pkcs15_encode_pubkey_as_spki(context, pubkey->pub_data, &value, &len))
  ------------------
  |  Branch (5148:9): [True: 1, False: 6]
  ------------------
 5149|      1|					return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
 5150|      7|			}
 5151|       |
 5152|      6|			if (attr->pValue == NULL_PTR) {
  ------------------
  |  |   27|      6|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (5152:8): [True: 3, False: 3]
  ------------------
 5153|      3|				attr->ulValueLen = len;
 5154|      3|				free(value);
 5155|      3|				return CKR_OK;
  ------------------
  |  | 1086|      3|#define CKR_OK 0x00000000UL
  ------------------
 5156|      3|			}
 5157|      3|			if (attr->ulValueLen < len) {
  ------------------
  |  Branch (5157:8): [True: 0, False: 3]
  ------------------
 5158|      0|				attr->ulValueLen = len;
 5159|      0|				free(value);
 5160|      0|				return CKR_BUFFER_TOO_SMALL;
  ------------------
  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
 5161|      0|			}
 5162|      3|			attr->ulValueLen = len;
 5163|      3|			memcpy(attr->pValue, value, len);
 5164|       |
 5165|      3|			free(value);
 5166|      3|		} else if (attr->type != CKA_SPKI && attr->type != CKA_PUBLIC_KEY_INFO && pubkey->base.p15_object && pubkey->base.p15_object->content.value && pubkey->base.p15_object->content.len) {
  ------------------
  |  |   21|      0|#define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |  289|      0|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |   12|      0|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
              		} else if (attr->type != CKA_SPKI && attr->type != CKA_PUBLIC_KEY_INFO && pubkey->base.p15_object && pubkey->base.p15_object->content.value && pubkey->base.p15_object->content.len) {
  ------------------
  |  |  183|      0|#define CKA_PUBLIC_KEY_INFO 0x00000129UL
  ------------------
  |  Branch (5166:14): [True: 0, False: 0]
  |  Branch (5166:40): [True: 0, False: 0]
  |  Branch (5166:77): [True: 0, False: 0]
  |  Branch (5166:104): [True: 0, False: 0]
  |  Branch (5166:146): [True: 0, False: 0]
  ------------------
 5167|      0|			check_attribute_buffer(attr, pubkey->base.p15_object->content.len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5168|      0|			memcpy(attr->pValue, pubkey->base.p15_object->content.value, pubkey->base.p15_object->content.len);
 5169|      0|		} else if (cert && cert->cert_data) {
  ------------------
  |  Branch (5169:14): [True: 0, False: 0]
  |  Branch (5169:22): [True: 0, False: 0]
  ------------------
 5170|      0|			check_attribute_buffer(attr, cert->cert_data->data.len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5171|      0|			memcpy(attr->pValue, cert->cert_data->data.value, cert->cert_data->data.len);
 5172|      0|		} else {
 5173|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5174|      0|		}
 5175|     46|		break;
 5176|     46|	case CKA_GOSTR3410_PARAMS:
  ------------------
  |  |  218|      0|#define CKA_GOSTR3410_PARAMS 0x00000250UL
  ------------------
  |  Branch (5176:2): [True: 0, False: 6.82k]
  ------------------
 5177|      0|		if (pubkey->pub_info && pubkey->pub_info->params.len)
  ------------------
  |  Branch (5177:7): [True: 0, False: 0]
  |  Branch (5177:27): [True: 0, False: 0]
  ------------------
 5178|      0|			return get_gostr3410_params(pubkey->pub_info->params.data, pubkey->pub_info->params.len, attr);
 5179|      0|		else
 5180|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5181|      0|	case CKA_EC_PARAMS:
  ------------------
  |  |  200|      0|#define CKA_EC_PARAMS 0x00000180UL
  ------------------
  |  Branch (5181:2): [True: 0, False: 6.82k]
  ------------------
 5182|      0|		return get_ec_pubkey_params(pubkey->pub_data, attr);
 5183|      0|	case CKA_EC_POINT:
  ------------------
  |  |  201|      0|#define CKA_EC_POINT 0x00000181UL
  ------------------
  |  Branch (5183:2): [True: 0, False: 6.82k]
  ------------------
 5184|      0|		return get_ec_pubkey_point(pubkey->pub_data, attr);
 5185|       |
 5186|      0|	default:
  ------------------
  |  Branch (5186:2): [True: 0, False: 6.82k]
  ------------------
 5187|      0|		return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5188|  6.82k|	}
 5189|       |
 5190|  4.26k|	return CKR_OK;
  ------------------
  |  | 1086|  4.26k|#define CKR_OK 0x00000000UL
  ------------------
 5191|  6.82k|}
framework-pkcs15.c:pkcs15_dobj_release:
 5214|  35.2k|{
 5215|  35.2k|	__pkcs15_release_object((struct pkcs15_any_object *) object);
 5216|  35.2k|}
framework-pkcs15.c:pkcs15_dobj_get_attribute:
 5286|  24.1k|{
 5287|  24.1k|	struct pkcs15_data_object *dobj = (struct pkcs15_data_object*) object;
 5288|  24.1k|	struct sc_pkcs15_data *data = NULL;
 5289|  24.1k|	CK_RV rv;
 5290|  24.1k|	size_t len;
 5291|  24.1k|	int r;
 5292|  24.1k|	unsigned char *buf = NULL;
 5293|       |
 5294|  24.1k|	sc_log(context, "pkcs15_dobj_get_attribute() called");
  ------------------
  |  |   71|  24.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5295|  24.1k|	switch (attr->type) {
 5296|  15.9k|	case CKA_CLASS:
  ------------------
  |  |  137|  15.9k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (5296:2): [True: 15.9k, False: 8.19k]
  ------------------
 5297|  15.9k|		check_attribute_buffer(attr, sizeof(CK_OBJECT_CLASS));
  ------------------
  |  |   56|  15.9k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  31.8k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 7.97k, False: 7.97k]
  |  |  ------------------
  |  |   57|  7.97k|		attr->ulValueLen = size;        \
  |  |   58|  7.97k|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|  7.97k|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|  7.97k|	}                                       \
  |  |   60|  15.9k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 7.97k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  7.97k|	attr->ulValueLen = size;
  ------------------
 5298|  7.97k|		*(CK_OBJECT_CLASS*)attr->pValue = CKO_DATA;
  ------------------
  |  | 1027|  7.97k|#define CKO_DATA 0x00000000UL
  ------------------
 5299|  7.97k|		break;
 5300|      0|	case CKA_TOKEN:
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (5300:2): [True: 0, False: 24.1k]
  ------------------
 5301|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5302|      0|		*(CK_BBOOL*)attr->pValue = TRUE;
  ------------------
  |  |   51|      0|#define TRUE 1
  ------------------
 5303|      0|		break;
 5304|  8.19k|	case CKA_PRIVATE:
  ------------------
  |  |  139|  8.19k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (5304:2): [True: 8.19k, False: 15.9k]
  ------------------
 5305|  8.19k|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|  8.19k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  16.3k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 8.19k]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|  8.19k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 8.19k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  8.19k|	attr->ulValueLen = size;
  ------------------
 5306|  8.19k|		*(CK_BBOOL*)attr->pValue = (dobj->base.p15_object->flags & SC_PKCS15_CO_FLAG_PRIVATE) != 0;
  ------------------
  |  |   50|  8.19k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 5307|  8.19k|		break;
 5308|      0|	case CKA_MODIFIABLE:
  ------------------
  |  |  197|      0|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (5308:2): [True: 0, False: 24.1k]
  ------------------
 5309|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5310|      0|		*(CK_BBOOL*)attr->pValue = (dobj->base.p15_object->flags & 0x02) != 0;
 5311|      0|		break;
 5312|      0|	case CKA_LABEL:
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  |  Branch (5312:2): [True: 0, False: 24.1k]
  ------------------
 5313|      0|		len = strnlen(dobj->base.p15_object->label, sizeof dobj->base.p15_object->label);
 5314|      0|		check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5315|      0|		memcpy(attr->pValue, dobj->base.p15_object->label, len);
 5316|      0|		break;
 5317|      0|	case CKA_APPLICATION:
  ------------------
  |  |  142|      0|#define CKA_APPLICATION 0x00000010UL
  ------------------
  |  Branch (5317:2): [True: 0, False: 24.1k]
  ------------------
 5318|      0|		len = strlen(dobj->info->app_label);
 5319|      0|		check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5320|      0|		memcpy(attr->pValue, dobj->info->app_label, len);
 5321|      0|		break;
 5322|       |#if 0
 5323|       |	case CKA_ID:
 5324|       |		check_attribute_buffer(attr, dobj->info->id.len);
 5325|       |		memcpy(attr->pValue, dobj->info->id.value, dobj->info->id.len);
 5326|       |		break;
 5327|       |#endif
 5328|      0|	case CKA_OBJECT_ID:
  ------------------
  |  |  144|      0|#define CKA_OBJECT_ID 0x00000012UL
  ------------------
  |  Branch (5328:2): [True: 0, False: 24.1k]
  ------------------
 5329|      0|		if (!sc_valid_oid(&dobj->info->app_oid))   {
  ------------------
  |  Branch (5329:7): [True: 0, False: 0]
  ------------------
 5330|      0|			attr->ulValueLen = -1;
 5331|      0|			return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5332|      0|		}
 5333|      0|		r = sc_asn1_encode_object_id(NULL, &len, &dobj->info->app_oid);
 5334|      0|		if (r)   {
  ------------------
  |  Branch (5334:7): [True: 0, False: 0]
  ------------------
 5335|      0|			sc_log(context, "data_get_attr(): encode OID error %i", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5336|      0|			return CKR_FUNCTION_FAILED;
  ------------------
  |  | 1091|      0|#define CKR_FUNCTION_FAILED 0x00000006UL
  ------------------
 5337|      0|		}
 5338|       |
 5339|      0|		check_attribute_buffer(attr, len);
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5340|       |
 5341|      0|		r = sc_asn1_encode_object_id(&buf, &len, &dobj->info->app_oid);
 5342|      0|		if (r)   {
  ------------------
  |  Branch (5342:7): [True: 0, False: 0]
  ------------------
 5343|      0|			sc_log(context, "data_get_attr(): encode OID error %i", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5344|      0|			return CKR_FUNCTION_FAILED;
  ------------------
  |  | 1091|      0|#define CKR_FUNCTION_FAILED 0x00000006UL
  ------------------
 5345|      0|		}
 5346|       |
 5347|      0|		memcpy(attr->pValue, buf, len);
 5348|      0|		free(buf);
 5349|      0|		break;
 5350|      0|	case CKA_VALUE:
  ------------------
  |  |  143|      0|#define CKA_VALUE 0x00000011UL
  ------------------
  |  Branch (5350:2): [True: 0, False: 24.1k]
  ------------------
 5351|       |		/* if CKA_VALUE is empty, sets data to NULL */
 5352|      0|		rv = pkcs15_dobj_get_value(session, dobj, &data);
 5353|      0|		if (rv == CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (5353:7): [True: 0, False: 0]
  ------------------
 5354|      0|			if (data) {
  ------------------
  |  Branch (5354:8): [True: 0, False: 0]
  ------------------
 5355|      0|				rv = data_value_to_attr(attr, data);
 5356|      0|			}
 5357|      0|			else {
 5358|      0|				attr->ulValueLen = 0;
 5359|      0|				attr->pValue = NULL_PTR;
  ------------------
  |  |   27|      0|#define NULL_PTR ((void *)0)
  ------------------
 5360|      0|			}
 5361|      0|		}
 5362|      0|		if (data) {
  ------------------
  |  Branch (5362:7): [True: 0, False: 0]
  ------------------
 5363|      0|			free(data->data);
 5364|      0|			free(data);
 5365|      0|		}
 5366|      0|		if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (5366:7): [True: 0, False: 0]
  ------------------
 5367|      0|			return rv;
 5368|      0|		break;
 5369|      0|	default:
  ------------------
  |  Branch (5369:2): [True: 0, False: 24.1k]
  ------------------
 5370|      0|		return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5371|  24.1k|	}
 5372|       |
 5373|  16.1k|	return CKR_OK;
  ------------------
  |  | 1086|  16.1k|#define CKR_OK 0x00000000UL
  ------------------
 5374|  24.1k|}
framework-pkcs15.c:pkcs15_profile_release:
 5396|  10.3k|{
 5397|  10.3k|	struct pkcs15_any_object *object = (struct pkcs15_any_object *) obj;
 5398|  10.3k|	struct sc_pkcs15_object *p15_obj = object->p15_object;
 5399|       |
 5400|  10.3k|	if (__pkcs15_release_object((struct pkcs15_any_object *) obj) < 1) {
  ------------------
  |  Branch (5400:6): [True: 5.18k, False: 5.18k]
  ------------------
 5401|       |		/* This is not a real pkcs15 object. We need to free it here */
 5402|  5.18k|		free(p15_obj);
 5403|  5.18k|	}
 5404|  10.3k|}
framework-pkcs15.c:pkcs15_profile_get_attribute:
 5417|  3.33k|{
 5418|  3.33k|	struct pkcs15_profile_object *pobj = (struct pkcs15_profile_object*) object;
 5419|       |
 5420|  3.33k|	sc_log(context, "pkcs15_profile_get_attribute() called");
  ------------------
  |  |   71|  3.33k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5421|  3.33k|	switch (attr->type) {
 5422|  2.75k|	case CKA_CLASS:
  ------------------
  |  |  137|  2.75k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (5422:2): [True: 2.75k, False: 582]
  ------------------
 5423|  2.75k|		check_attribute_buffer(attr, sizeof(CK_OBJECT_CLASS));
  ------------------
  |  |   56|  2.75k|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  5.50k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 1.37k, False: 1.37k]
  |  |  ------------------
  |  |   57|  1.37k|		attr->ulValueLen = size;        \
  |  |   58|  1.37k|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|  1.37k|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|  1.37k|	}                                       \
  |  |   60|  2.75k|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 1.37k]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|  1.37k|	attr->ulValueLen = size;
  ------------------
 5424|  1.37k|		*(CK_OBJECT_CLASS*)attr->pValue = CKO_PROFILE;
  ------------------
  |  | 1036|  1.37k|#define CKO_PROFILE 0x00000009UL
  ------------------
 5425|  1.37k|		break;
 5426|    582|	case CKA_PRIVATE:
  ------------------
  |  |  139|    582|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (5426:2): [True: 582, False: 2.75k]
  ------------------
 5427|       |		/* This is needed internally for the object to be visible */
 5428|    582|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|    582|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|  1.16k|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 582]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|    582|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 582]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|    582|	attr->ulValueLen = size;
  ------------------
 5429|    582|		*(CK_BBOOL*)attr->pValue = CK_FALSE;
  ------------------
  |  |   35|    582|#define CK_FALSE 0
  ------------------
 5430|    582|		break;
 5431|      0|	case CKA_PROFILE_ID:
  ------------------
  |  |  238|      0|#define CKA_PROFILE_ID 0x00000601UL
  ------------------
  |  Branch (5431:2): [True: 0, False: 3.33k]
  ------------------
 5432|       |		/* TODO */
 5433|      0|		check_attribute_buffer(attr, sizeof(CK_ULONG));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5434|      0|		*(CK_ULONG*)attr->pValue = pobj->profile_id;
 5435|      0|		break;
 5436|      0|	case CKA_TOKEN:
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (5436:2): [True: 0, False: 3.33k]
  ------------------
 5437|      0|		check_attribute_buffer(attr, sizeof(CK_BBOOL));
  ------------------
  |  |   56|      0|	if (attr->pValue == NULL_PTR) {         \
  |  |  ------------------
  |  |  |  |   27|      0|#define NULL_PTR ((void *)0)
  |  |  ------------------
  |  |  |  Branch (56:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   57|      0|		attr->ulValueLen = size;        \
  |  |   58|      0|		return CKR_OK;                  \
  |  |  ------------------
  |  |  |  | 1086|      0|#define CKR_OK 0x00000000UL
  |  |  ------------------
  |  |   59|      0|	}                                       \
  |  |   60|      0|	if (attr->ulValueLen < size) {		\
  |  |  ------------------
  |  |  |  Branch (60:6): [True: 0, False: 0]
  |  |  ------------------
  |  |   61|      0|		attr->ulValueLen = size;	\
  |  |   62|      0|		return CKR_BUFFER_TOO_SMALL;    \
  |  |  ------------------
  |  |  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  |  |  ------------------
  |  |   63|      0|	}                                       \
  |  |   64|      0|	attr->ulValueLen = size;
  ------------------
 5438|      0|		*(CK_BBOOL*)attr->pValue = CK_TRUE;
  ------------------
  |  |   34|      0|#define CK_TRUE 1
  ------------------
 5439|      0|		break;
 5440|      0|	default:
  ------------------
  |  Branch (5440:2): [True: 0, False: 3.33k]
  ------------------
 5441|      0|		return CKR_ATTRIBUTE_TYPE_INVALID;
  ------------------
  |  | 1098|      0|#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012UL
  ------------------
 5442|  3.33k|	}
 5443|       |
 5444|  1.95k|	return CKR_OK;
  ------------------
  |  | 1086|  1.95k|#define CKR_OK 0x00000000UL
  ------------------
 5445|  3.33k|}
framework-pkcs15.c:pkcs15_skey_release:
 5469|     28|{
 5470|     28|	struct pkcs15_skey_object *skey = (struct pkcs15_skey_object *)object;
 5471|     28|	struct sc_pkcs15_skey_info *skey_info = skey->info;
 5472|     28|	struct sc_pkcs15_object *p15obj = skey->skey_p15obj;
  ------------------
  |  |  150|     28|#define skey_p15obj	base.p15_object
  ------------------
 5473|       |
 5474|     28|	if (__pkcs15_release_object((struct pkcs15_any_object *)skey) == 0) {
  ------------------
  |  Branch (5474:6): [True: 14, False: 14]
  ------------------
 5475|     14|		if (p15obj->session_object) {
  ------------------
  |  Branch (5475:7): [True: 14, False: 0]
  ------------------
 5476|     14|			sc_pkcs15_free_skey_info(skey_info);
 5477|     14|			free(p15obj);
 5478|     14|		}
 5479|     14|	}
 5480|     28|}

_update_mech_info:
   90|    104|void _update_mech_info(CK_MECHANISM_INFO_PTR mech_info, CK_MECHANISM_INFO_PTR new_mech_info) {
   91|    104|	if (new_mech_info->ulMaxKeySize > mech_info->ulMaxKeySize)
  ------------------
  |  Branch (91:6): [True: 0, False: 104]
  ------------------
   92|      0|		mech_info->ulMaxKeySize = new_mech_info->ulMaxKeySize;
   93|    104|	if (new_mech_info->ulMinKeySize < mech_info->ulMinKeySize)
  ------------------
  |  Branch (93:6): [True: 104, False: 0]
  ------------------
   94|    104|		mech_info->ulMinKeySize = new_mech_info->ulMinKeySize;
   95|    104|	mech_info->flags |= new_mech_info->flags;
   96|    104|}
sc_pkcs11_register_mechanism:
  131|   125k|{
  132|   125k|	sc_pkcs11_mechanism_type_t *existing_mt;
  133|   125k|	sc_pkcs11_mechanism_type_t *copy_mt = NULL;
  134|   125k|	sc_pkcs11_mechanism_type_t **p;
  135|   125k|	int i;
  136|   125k|	CK_RV rv;
  137|       |
  138|   125k|	if (mt == NULL)
  ------------------
  |  Branch (138:6): [True: 0, False: 125k]
  ------------------
  139|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  140|       |
  141|   125k|	if ((existing_mt = sc_pkcs11_find_mechanism(p11card, mt->mech, mt->mech_info.flags))) {
  ------------------
  |  Branch (141:6): [True: 104, False: 125k]
  ------------------
  142|    208|		for (i = 0; i < MAX_KEY_TYPES; i++) {
  ------------------
  |  |  281|    208|#define MAX_KEY_TYPES 2
  ------------------
  |  Branch (142:15): [True: 208, False: 0]
  ------------------
  143|    208|			if (existing_mt->key_types[i] == mt->key_types[0]) {
  ------------------
  |  Branch (143:8): [True: 0, False: 208]
  ------------------
  144|       |				/* Mechanism already registered with the same key_type,
  145|       |				 * just update it's info */
  146|      0|				_update_mech_info(&existing_mt->mech_info, &mt->mech_info);
  147|      0|				return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  148|      0|			}
  149|    208|			if (existing_mt->key_types[i] < 0) {
  ------------------
  |  Branch (149:8): [True: 104, False: 104]
  ------------------
  150|       |				/* There is a free slot for new key type, let's add it and
  151|       |				 * update mechanism info */
  152|    104|				_update_mech_info(&existing_mt->mech_info, &mt->mech_info);
  153|       |				/* XXX Should be changed to loop over mt->key_types, if
  154|       |				 * we allow to register mechanism with multiple key types
  155|       |				 * in one operation */
  156|    104|				existing_mt->key_types[i] = mt->key_types[0];
  157|    104|				if (i + 1 < MAX_KEY_TYPES) {
  ------------------
  |  |  281|    104|#define MAX_KEY_TYPES 2
  ------------------
  |  Branch (157:9): [True: 0, False: 104]
  ------------------
  158|      0|					existing_mt->key_types[i + 1] = -1;
  159|      0|				}
  160|    104|				return CKR_OK;
  ------------------
  |  | 1086|    104|#define CKR_OK 0x00000000UL
  ------------------
  161|    104|			}
  162|    208|		}
  163|      0|		sc_log(p11card->card->ctx, "Too many key types in mechanism 0x%lx, more than %d", mt->mech, MAX_KEY_TYPES);
  ------------------
  |  |   71|      0|#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)
  |  |  ------------------
  |  |  |  |  163|      0|		sc_log(p11card->card->ctx, "Too many key types in mechanism 0x%lx, more than %d", mt->mech, MAX_KEY_TYPES);
  |  |  |  |  ------------------
  |  |  |  |  |  |  281|      0|#define MAX_KEY_TYPES 2
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|      0|		return CKR_BUFFER_TOO_SMALL;
  ------------------
  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  165|    104|	}
  166|       |
  167|   125k|	p = (sc_pkcs11_mechanism_type_t **) realloc(p11card->mechanisms,
  168|   125k|			(p11card->nmechanisms + 2) * sizeof(*p));
  169|   125k|	if (p == NULL)
  ------------------
  |  Branch (169:6): [True: 0, False: 125k]
  ------------------
  170|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  171|   125k|	if ((rv = sc_pkcs11_copy_mechanism(mt, &copy_mt)) != CKR_OK) {
  ------------------
  |  | 1086|   125k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (171:6): [True: 0, False: 125k]
  ------------------
  172|      0|		free(p);
  173|      0|		return rv;
  174|      0|	}
  175|   125k|	p11card->mechanisms = p;
  176|   125k|	p[p11card->nmechanisms++] = copy_mt;
  177|   125k|	p[p11card->nmechanisms] = NULL;
  178|       |	/* Return registered mechanism for further use */
  179|   125k|	if (result_mt)
  ------------------
  |  Branch (179:6): [True: 10.8k, False: 114k]
  ------------------
  180|  10.8k|		*result_mt = copy_mt;
  181|   125k|	return CKR_OK;
  ------------------
  |  | 1086|   125k|#define CKR_OK 0x00000000UL
  ------------------
  182|   125k|}
_validate_key_type:
  186|    483|_validate_key_type(sc_pkcs11_mechanism_type_t *mech, CK_KEY_TYPE key_type) {
  187|    483|	int i;
  188|    485|	for (i = 0; i < MAX_KEY_TYPES; i++) {
  ------------------
  |  |  281|    485|#define MAX_KEY_TYPES 2
  ------------------
  |  Branch (188:14): [True: 485, False: 0]
  ------------------
  189|    485|		if (mech->key_types[i] < 0)
  ------------------
  |  Branch (189:7): [True: 2, False: 483]
  ------------------
  190|      2|			break;
  191|    483|		if ((CK_KEY_TYPE)mech->key_types[i] == key_type)
  ------------------
  |  Branch (191:7): [True: 481, False: 2]
  ------------------
  192|    481|			return CKR_OK;
  ------------------
  |  | 1086|    481|#define CKR_OK 0x00000000UL
  ------------------
  193|    483|	}
  194|      2|	return CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      2|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  195|    483|}
sc_pkcs11_find_mechanism:
  202|   184k|{
  203|   184k|	sc_pkcs11_mechanism_type_t *mt;
  204|   184k|	unsigned int n;
  205|       |
  206|   184k|	if (p11card == NULL)
  ------------------
  |  Branch (206:6): [True: 0, False: 184k]
  ------------------
  207|      0|		return NULL;
  208|  1.93M|	for (n = 0; n < p11card->nmechanisms; n++) {
  ------------------
  |  Branch (208:14): [True: 1.80M, False: 125k]
  ------------------
  209|  1.80M|		mt = p11card->mechanisms[n];
  210|  1.80M|		if (mt && mt->mech == mech && ((mt->mech_info.flags & flags) == flags))
  ------------------
  |  Branch (210:7): [True: 1.80M, False: 0]
  |  Branch (210:13): [True: 58.8k, False: 1.74M]
  |  Branch (210:33): [True: 58.8k, False: 2]
  ------------------
  211|  58.8k|			return mt;
  212|  1.80M|	}
  213|   125k|	return NULL;
  214|   184k|}
sc_pkcs11_new_operation:
  268|  2.15k|{
  269|  2.15k|	sc_pkcs11_operation_t *res;
  270|       |
  271|  2.15k|	res = calloc(1, type->obj_size);
  272|  2.15k|	if (res) {
  ------------------
  |  Branch (272:6): [True: 2.15k, False: 0]
  ------------------
  273|  2.15k|		res->session = session;
  274|  2.15k|		res->type = type;
  275|  2.15k|	}
  276|  2.15k|	return res;
  277|  2.15k|}
sc_pkcs11_release_operation:
  281|  95.6k|{
  282|  95.6k|	sc_pkcs11_operation_t *operation = *ptr;
  283|       |
  284|  95.6k|	if (!operation)
  ------------------
  |  Branch (284:6): [True: 93.5k, False: 2.15k]
  ------------------
  285|  93.5k|		return;
  286|  2.15k|	if (operation->type && operation->type->release)
  ------------------
  |  Branch (286:6): [True: 2.15k, False: 0]
  |  Branch (286:25): [True: 2.15k, False: 0]
  ------------------
  287|  2.15k|		operation->type->release(operation);
  288|  2.15k|	memset(operation, 0, sizeof(*operation));
  289|  2.15k|	free(operation);
  290|       |	*ptr = NULL;
  291|  2.15k|}
sc_pkcs11_md_init:
  296|    248|{
  297|    248|	struct sc_pkcs11_card *p11card;
  298|    248|	sc_pkcs11_operation_t *operation;
  299|    248|	sc_pkcs11_mechanism_type_t *mt;
  300|    248|	CK_RV rv;
  301|       |
  302|    248|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|    248|	if (!session || !session->slot || !(p11card = session->slot->p11card))
  ------------------
  |  Branch (303:6): [True: 0, False: 248]
  |  Branch (303:18): [True: 0, False: 248]
  |  Branch (303:36): [True: 0, False: 248]
  ------------------
  304|    248|		LOG_FUNC_RETURN(context, CKR_ARGUMENTS_BAD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|       |	/* See if we support this mechanism type */
  307|    248|	mt = sc_pkcs11_find_mechanism(p11card, pMechanism->mechanism, CKF_DIGEST);
  ------------------
  |  |  362|    248|#define CKF_DIGEST 0x00000400UL
  ------------------
  308|    248|	if (mt == NULL)
  ------------------
  |  Branch (308:6): [True: 238, False: 10]
  ------------------
  309|    248|		LOG_FUNC_RETURN(context, CKR_MECHANISM_INVALID);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|    238|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    238|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    238|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  310|       |
  311|     10|	rv = session_start_operation(session, SC_PKCS11_OPERATION_DIGEST, mt, &operation);
  312|     10|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     10|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (312:6): [True: 0, False: 10]
  ------------------
  313|     10|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|       |
  315|     10|	memcpy(&operation->mechanism, pMechanism, sizeof(CK_MECHANISM));
  316|       |
  317|     10|	rv = mt->md_init(operation);
  318|       |
  319|     10|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     10|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (319:6): [True: 1, False: 9]
  ------------------
  320|      1|		session_stop_operation(session, SC_PKCS11_OPERATION_DIGEST);
  321|       |
  322|     10|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|     10|}
sc_pkcs11_md_update:
  328|    101|{
  329|    101|	sc_pkcs11_operation_t *op;
  330|    101|	CK_RV rv;
  331|       |
  332|    101|	rv = session_get_operation(session, SC_PKCS11_OPERATION_DIGEST, &op);
  333|    101|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    101|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (333:6): [True: 0, False: 101]
  ------------------
  334|      0|		goto done;
  335|       |
  336|    101|	rv = op->type->md_update(op, pData, ulDataLen);
  337|       |
  338|    101|done:
  339|    101|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    101|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (339:6): [True: 0, False: 101]
  ------------------
  340|      0|		session_stop_operation(session, SC_PKCS11_OPERATION_DIGEST);
  341|       |
  342|    101|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    101|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    101|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    101|	int _ret = r; \
  |  |  |  |  155|    101|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 101, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    101|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 101]
  |  |  |  |  ------------------
  |  |  |  |  157|    101|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    101|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    101|	return _ret; \
  |  |  |  |  163|    101|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  343|    101|}
sc_pkcs11_md_final:
  348|     10|{
  349|     10|	sc_pkcs11_operation_t *op;
  350|     10|	CK_RV rv;
  351|       |
  352|     10|	rv = session_get_operation(session, SC_PKCS11_OPERATION_DIGEST, &op);
  353|     10|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     10|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (353:6): [True: 0, False: 10]
  ------------------
  354|     10|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  355|       |
  356|       |	/* This is a request for the digest length */
  357|     10|	if (pData == NULL)
  ------------------
  |  Branch (357:6): [True: 1, False: 9]
  ------------------
  358|      1|		*pulDataLen = 0;
  359|       |
  360|     10|	rv = op->type->md_final(op, pData, pulDataLen);
  361|     10|	if (rv == CKR_BUFFER_TOO_SMALL)
  ------------------
  |  | 1165|     10|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  |  Branch (361:6): [True: 1, False: 9]
  ------------------
  362|     10|		LOG_FUNC_RETURN(context,  pData == NULL ? CKR_OK : CKR_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|      2|	int _ret = r; \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (154:13): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|       |
  364|      9|	session_stop_operation(session, SC_PKCS11_OPERATION_DIGEST);
  365|      9|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  366|      9|}
sc_pkcs11_sign_init:
  375|    262|{
  376|    262|	struct sc_pkcs11_card *p11card;
  377|    262|	sc_pkcs11_operation_t *operation;
  378|    262|	sc_pkcs11_mechanism_type_t *mt;
  379|    262|	CK_RV rv;
  380|       |
  381|    262|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|    262|	if (!session || !session->slot || !(p11card = session->slot->p11card))
  ------------------
  |  Branch (382:6): [True: 0, False: 262]
  |  Branch (382:18): [True: 0, False: 262]
  |  Branch (382:36): [True: 0, False: 262]
  ------------------
  383|    262|		LOG_FUNC_RETURN(context, CKR_ARGUMENTS_BAD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|       |	/* See if we support this mechanism type */
  386|    262|	sc_log(context, "mechanism 0x%lX, key-type 0x%lX",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  387|    262|	       pMechanism->mechanism, key_type);
  388|    262|	mt = sc_pkcs11_find_mechanism(p11card, pMechanism->mechanism, CKF_SIGN);
  ------------------
  |  |  363|    262|#define CKF_SIGN 0x00000800UL
  ------------------
  389|    262|	if (mt == NULL)
  ------------------
  |  Branch (389:6): [True: 17, False: 245]
  ------------------
  390|    262|		LOG_FUNC_RETURN(context, CKR_MECHANISM_INVALID);
  ------------------
  |  |  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: 0, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|     17|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     17|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     17|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|       |
  392|       |	/* See if compatible with key type */
  393|    245|	rv = _validate_key_type(mt, key_type);
  394|    245|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    245|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (394:6): [True: 1, False: 244]
  ------------------
  395|    245|		LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|       |
  397|    244|	if (pMechanism->pParameter &&
  ------------------
  |  Branch (397:6): [True: 0, False: 244]
  ------------------
  398|      0|			pMechanism->ulParameterLen > sizeof(operation->mechanism_params))
  ------------------
  |  Branch (398:4): [True: 0, False: 0]
  ------------------
  399|    244|		LOG_FUNC_RETURN(context, CKR_ARGUMENTS_BAD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  400|       |
  401|    244|	rv = session_start_operation(session, SC_PKCS11_OPERATION_SIGN, mt, &operation);
  402|    244|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    244|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (402:6): [True: 0, False: 244]
  ------------------
  403|    244|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  404|       |
  405|    244|	memcpy(&operation->mechanism, pMechanism, sizeof(CK_MECHANISM));
  406|    244|	if (pMechanism->pParameter) {
  ------------------
  |  Branch (406:6): [True: 0, False: 244]
  ------------------
  407|      0|		memcpy(&operation->mechanism_params, pMechanism->pParameter,
  408|      0|				pMechanism->ulParameterLen);
  409|      0|		operation->mechanism.pParameter = &operation->mechanism_params;
  410|      0|	}
  411|    244|	rv = mt->sign_init(operation, key);
  412|    244|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    244|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (412:6): [True: 6, False: 238]
  ------------------
  413|      6|		session_stop_operation(session, SC_PKCS11_OPERATION_SIGN);
  414|       |
  415|    244|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    244|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    244|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    244|	int _ret = r; \
  |  |  |  |  155|    244|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|      6|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      6|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      6|	} \
  |  |  |  |  162|    244|	return _ret; \
  |  |  |  |  163|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|    244|}
sc_pkcs11_sign_update:
  421|    246|{
  422|    246|	sc_pkcs11_operation_t *op;
  423|    246|	CK_RV rv;
  424|       |
  425|    246|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|    246|	rv = session_get_operation(session, SC_PKCS11_OPERATION_SIGN, &op);
  427|    246|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    246|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (427:6): [True: 0, False: 246]
  ------------------
  428|    246|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|       |
  430|    246|	if (op->type->sign_update == NULL) {
  ------------------
  |  Branch (430:6): [True: 0, False: 246]
  ------------------
  431|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  432|      0|		goto done;
  433|      0|	}
  434|       |
  435|    246|	rv = op->type->sign_update(op, pData, ulDataLen);
  436|       |
  437|    246|done:
  438|    246|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    246|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (438:6): [True: 0, False: 246]
  ------------------
  439|      0|		session_stop_operation(session, SC_PKCS11_OPERATION_SIGN);
  440|       |
  441|    246|	LOG_FUNC_RETURN(context, (int) 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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 246]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  442|    246|}
sc_pkcs11_sign_final:
  447|    238|{
  448|    238|	sc_pkcs11_operation_t *op;
  449|    238|	CK_RV rv;
  450|       |
  451|    238|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|    238|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    238|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    238|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    238|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 238]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  452|    238|	rv = session_get_operation(session, SC_PKCS11_OPERATION_SIGN, &op);
  453|    238|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    238|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (453:6): [True: 0, False: 238]
  ------------------
  454|    238|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|       |
  456|       |	/* Bail out for signature mechanisms that don't do hashing */
  457|    238|	if (op->type->sign_final == NULL) {
  ------------------
  |  Branch (457:6): [True: 0, False: 238]
  ------------------
  458|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  459|      0|		goto done;
  460|      0|	}
  461|       |
  462|    238|	rv = op->type->sign_final(op, pSignature, pulSignatureLen);
  463|       |
  464|    238|done:
  465|    238|	if (rv != CKR_BUFFER_TOO_SMALL && pSignature != NULL)
  ------------------
  |  | 1165|    476|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  |  Branch (465:6): [True: 237, False: 1]
  |  Branch (465:36): [True: 237, False: 0]
  ------------------
  466|    237|		session_stop_operation(session, SC_PKCS11_OPERATION_SIGN);
  467|       |
  468|    238|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 191]
  |  |  |  |  ------------------
  |  |  |  |  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|    191|	} else { \
  |  |  |  |  159|    191|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    191|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    191|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  469|    238|}
sc_pkcs11_sign_size:
  473|    238|{
  474|    238|	sc_pkcs11_operation_t *op;
  475|    238|	CK_RV rv;
  476|       |
  477|    238|	rv = session_get_operation(session, SC_PKCS11_OPERATION_SIGN, &op);
  478|    238|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    238|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (478:6): [True: 0, False: 238]
  ------------------
  479|    238|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|       |
  481|       |	/* Bail out for signature mechanisms that don't do hashing */
  482|    238|	if (op->type->sign_size == NULL) {
  ------------------
  |  Branch (482:6): [True: 0, False: 238]
  ------------------
  483|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  484|      0|		goto done;
  485|      0|	}
  486|       |
  487|    238|	rv = op->type->sign_size(op, pLength);
  488|       |
  489|    238|done:
  490|    238|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    238|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (490:6): [True: 0, False: 238]
  ------------------
  491|      0|		session_stop_operation(session, SC_PKCS11_OPERATION_SIGN);
  492|       |
  493|    238|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|    238|}
sc_pkcs11_verif_init:
  676|     70|{
  677|     70|	struct sc_pkcs11_card *p11card;
  678|     70|	sc_pkcs11_operation_t *operation;
  679|     70|	sc_pkcs11_mechanism_type_t *mt;
  680|     70|	CK_RV rv;
  681|       |
  682|     70|	if (!session || !session->slot
  ------------------
  |  Branch (682:6): [True: 0, False: 70]
  |  Branch (682:18): [True: 0, False: 70]
  ------------------
  683|     70|	 || !(p11card = session->slot->p11card))
  ------------------
  |  Branch (683:6): [True: 0, False: 70]
  ------------------
  684|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  685|       |
  686|       |	/* See if we support this mechanism type */
  687|     70|	mt = sc_pkcs11_find_mechanism(p11card, pMechanism->mechanism, CKF_VERIFY);
  ------------------
  |  |  365|     70|#define CKF_VERIFY 0x00002000UL
  ------------------
  688|     70|	if (mt == NULL)
  ------------------
  |  Branch (688:6): [True: 19, False: 51]
  ------------------
  689|     19|		return CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|     19|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
  690|       |
  691|       |	/* See if compatible with key type */
  692|     51|	rv = _validate_key_type(mt, key_type);
  693|     51|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     51|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (693:6): [True: 1, False: 50]
  ------------------
  694|     51|		LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  695|       |
  696|     50|	if (pMechanism->pParameter &&
  ------------------
  |  Branch (696:6): [True: 0, False: 50]
  ------------------
  697|      0|			pMechanism->ulParameterLen > sizeof(operation->mechanism_params))
  ------------------
  |  Branch (697:4): [True: 0, False: 0]
  ------------------
  698|     50|		LOG_FUNC_RETURN(context, CKR_ARGUMENTS_BAD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  699|       |
  700|     50|	rv = session_start_operation(session, SC_PKCS11_OPERATION_VERIFY, mt, &operation);
  701|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (701:6): [True: 0, False: 50]
  ------------------
  702|      0|		return rv;
  703|       |
  704|     50|	memcpy(&operation->mechanism, pMechanism, sizeof(CK_MECHANISM));
  705|     50|	if (pMechanism->pParameter) {
  ------------------
  |  Branch (705:6): [True: 0, False: 50]
  ------------------
  706|      0|		memcpy(&operation->mechanism_params, pMechanism->pParameter,
  707|      0|				pMechanism->ulParameterLen);
  708|      0|		operation->mechanism.pParameter = &operation->mechanism_params;
  709|      0|	}
  710|       |
  711|     50|	rv = mt->verif_init(operation, key);
  712|       |
  713|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (713:6): [True: 0, False: 50]
  ------------------
  714|      0|		session_stop_operation(session, SC_PKCS11_OPERATION_VERIFY);
  715|       |
  716|     50|	return rv;
  717|       |
  718|     50|}
sc_pkcs11_verif_update:
  723|     50|{
  724|     50|	sc_pkcs11_operation_t *op;
  725|     50|	CK_RV rv;
  726|       |
  727|     50|	rv = session_get_operation(session, SC_PKCS11_OPERATION_VERIFY, &op);
  728|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (728:6): [True: 0, False: 50]
  ------------------
  729|      0|		return rv;
  730|       |
  731|     50|	if (op->type->verif_update == NULL) {
  ------------------
  |  Branch (731:6): [True: 0, False: 50]
  ------------------
  732|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  733|      0|		goto done;
  734|      0|	}
  735|       |
  736|     50|	rv = op->type->verif_update(op, pData, ulDataLen);
  737|       |
  738|     50|done:
  739|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (739:6): [True: 0, False: 50]
  ------------------
  740|      0|		session_stop_operation(session, SC_PKCS11_OPERATION_VERIFY);
  741|       |
  742|     50|	return rv;
  743|     50|}
sc_pkcs11_verif_final:
  748|     50|{
  749|     50|	sc_pkcs11_operation_t *op;
  750|     50|	CK_RV rv;
  751|       |
  752|     50|	rv = session_get_operation(session, SC_PKCS11_OPERATION_VERIFY, &op);
  753|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (753:6): [True: 0, False: 50]
  ------------------
  754|      0|		return rv;
  755|       |
  756|     50|	if (op->type->verif_final == NULL) {
  ------------------
  |  Branch (756:6): [True: 0, False: 50]
  ------------------
  757|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  758|      0|		goto done;
  759|      0|	}
  760|       |
  761|     50|	rv = op->type->verif_final(op, pSignature, ulSignatureLen);
  762|       |
  763|     50|done:
  764|     50|	session_stop_operation(session, SC_PKCS11_OPERATION_VERIFY);
  765|     50|	return rv;
  766|     50|}
sc_pkcs11_decr_init:
 1042|    241|{
 1043|    241|	struct sc_pkcs11_card *p11card;
 1044|    241|	sc_pkcs11_operation_t *operation;
 1045|    241|	sc_pkcs11_mechanism_type_t *mt;
 1046|    241|	CK_RV rv;
 1047|       |
 1048|    241|	if (!session || !session->slot
  ------------------
  |  Branch (1048:6): [True: 0, False: 241]
  |  Branch (1048:18): [True: 0, False: 241]
  ------------------
 1049|    241|	 || !(p11card = session->slot->p11card))
  ------------------
  |  Branch (1049:6): [True: 0, False: 241]
  ------------------
 1050|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1051|       |
 1052|       |	/* See if we support this mechanism type */
 1053|    241|	mt = sc_pkcs11_find_mechanism(p11card, pMechanism->mechanism, CKF_DECRYPT);
  ------------------
  |  |  361|    241|#define CKF_DECRYPT 0x00000200UL
  ------------------
 1054|    241|	if (mt == NULL)
  ------------------
  |  Branch (1054:6): [True: 54, False: 187]
  ------------------
 1055|     54|		return CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|     54|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
 1056|       |
 1057|       |	/* See if compatible with key type */
 1058|    187|	rv = _validate_key_type(mt, key_type);
 1059|    187|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    187|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1059:6): [True: 0, False: 187]
  ------------------
 1060|    187|		LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1061|       |
 1062|    187|	if (pMechanism->pParameter &&
  ------------------
  |  Branch (1062:6): [True: 0, False: 187]
  ------------------
 1063|      0|			pMechanism->ulParameterLen > sizeof(operation->mechanism_params))
  ------------------
  |  Branch (1063:4): [True: 0, False: 0]
  ------------------
 1064|    187|		LOG_FUNC_RETURN(context, CKR_ARGUMENTS_BAD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|       |
 1066|    187|	rv = session_start_operation(session, SC_PKCS11_OPERATION_DECRYPT, mt, &operation);
 1067|    187|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    187|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1067:6): [True: 0, False: 187]
  ------------------
 1068|      0|		return rv;
 1069|       |
 1070|    187|	memcpy(&operation->mechanism, pMechanism, sizeof(CK_MECHANISM));
 1071|    187|	if (pMechanism->pParameter) {
  ------------------
  |  Branch (1071:6): [True: 0, False: 187]
  ------------------
 1072|      0|		memcpy(&operation->mechanism_params, pMechanism->pParameter,
 1073|      0|				pMechanism->ulParameterLen);
 1074|      0|		operation->mechanism.pParameter = &operation->mechanism_params;
 1075|      0|	}
 1076|    187|	rv = mt->decrypt_init(operation, key);
 1077|       |
 1078|       |	/* Validate the mechanism parameters */
 1079|    187|	if (rv == CKR_OK && key->ops->init_params) {
  ------------------
  |  | 1086|    374|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1079:6): [True: 187, False: 0]
  |  Branch (1079:22): [True: 187, False: 0]
  ------------------
 1080|    187|		rv = key->ops->init_params(operation->session, &operation->mechanism);
 1081|    187|	}
 1082|       |
 1083|    187|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    187|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1083:6): [True: 1, False: 186]
  ------------------
 1084|      1|		session_stop_operation(session, SC_PKCS11_OPERATION_DECRYPT);
 1085|       |
 1086|    187|	LOG_FUNC_RETURN(context, (int)rv);
  ------------------
  |  |  164|    187|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    187|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    187|	int _ret = r; \
  |  |  |  |  155|    187|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 186, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|    186|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 186]
  |  |  |  |  ------------------
  |  |  |  |  157|    186|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    186|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|    187|	return _ret; \
  |  |  |  |  163|    187|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|    187|}
sc_pkcs11_decr:
 1093|    186|{
 1094|    186|	sc_pkcs11_operation_t *op;
 1095|    186|	CK_RV rv;
 1096|       |
 1097|    186|	rv = session_get_operation(session, SC_PKCS11_OPERATION_DECRYPT, &op);
 1098|    186|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    186|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1098:6): [True: 0, False: 186]
  ------------------
 1099|      0|		return rv;
 1100|       |
 1101|    186|	rv = op->type->decrypt(op, pEncryptedData, ulEncryptedDataLen,
 1102|    186|	                       pData, pulDataLen);
 1103|       |
 1104|       |	/* terminate session for any return value except CKR_BUFFER_TOO_SMALL,
 1105|       |	 * perform check in time side-channel free way to prevent Marvin attack */
 1106|    186|	if (!constant_time_eq_s(rv, CKR_BUFFER_TOO_SMALL) && pData != NULL)
  ------------------
  |  | 1165|    186|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  |  Branch (1106:6): [True: 186, False: 0]
  |  Branch (1106:55): [True: 186, False: 0]
  ------------------
 1107|    186|		session_stop_operation(session, SC_PKCS11_OPERATION_DECRYPT);
 1108|       |
 1109|    186|	return rv;
 1110|    186|}
sc_pkcs11_deri:
 1265|     14|{
 1266|       |
 1267|     14|	struct sc_pkcs11_card *p11card;
 1268|     14|	sc_pkcs11_operation_t *operation;
 1269|     14|	sc_pkcs11_mechanism_type_t *mt;
 1270|     14|	CK_BYTE_PTR keybuf = NULL;
 1271|     14|	CK_ULONG ulDataLen = 0;
 1272|     14|	CK_ATTRIBUTE template[] = {
 1273|     14|		{CKA_VALUE, keybuf, 0}
  ------------------
  |  |  143|     14|#define CKA_VALUE 0x00000011UL
  ------------------
 1274|     14|	};
 1275|       |
 1276|     14|	CK_RV rv;
 1277|       |
 1278|       |
 1279|     14|	if (!session || !session->slot
  ------------------
  |  Branch (1279:6): [True: 0, False: 14]
  |  Branch (1279:18): [True: 0, False: 14]
  ------------------
 1280|     14|	 || !(p11card = session->slot->p11card))
  ------------------
  |  Branch (1280:6): [True: 0, False: 14]
  ------------------
 1281|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1282|       |
 1283|       |	/* See if we support this mechanism type */
 1284|     14|	mt = sc_pkcs11_find_mechanism(p11card, pMechanism->mechanism, CKF_DERIVE);
  ------------------
  |  |  371|     14|#define CKF_DERIVE 0x00080000UL
  ------------------
 1285|     14|	if (mt == NULL)
  ------------------
  |  Branch (1285:6): [True: 14, False: 0]
  ------------------
 1286|     14|		return CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|     14|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
 1287|       |
 1288|       |	/* See if compatible with key type */
 1289|      0|	rv = _validate_key_type(mt, key_type);
 1290|      0|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1290:6): [True: 0, False: 0]
  ------------------
 1291|      0|		LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1292|       |
 1293|      0|	rv = session_start_operation(session, SC_PKCS11_OPERATION_DERIVE, mt, &operation);
 1294|      0|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1294:6): [True: 0, False: 0]
  ------------------
 1295|      0|		return rv;
 1296|       |
 1297|      0|	memcpy(&operation->mechanism, pMechanism, sizeof(CK_MECHANISM));
 1298|       |
 1299|       |	/* Get the size of the data to be returned
 1300|       |	 * If the card could derive a key an leave it on the card
 1301|       |	 * then no data is returned.
 1302|       |	 * If the card returns the data, we will store it in the secret key CKA_VALUE
 1303|       |	 */
 1304|       |
 1305|      0|	ulDataLen = 0;
 1306|      0|	rv = operation->type->derive(operation, basekey,
 1307|      0|			pMechanism->pParameter, pMechanism->ulParameterLen,
 1308|      0|			NULL, &ulDataLen);
 1309|      0|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1309:6): [True: 0, False: 0]
  ------------------
 1310|      0|		goto out;
 1311|       |
 1312|      0|	if (ulDataLen > 0)
  ------------------
  |  Branch (1312:6): [True: 0, False: 0]
  ------------------
 1313|      0|		keybuf = calloc(1,ulDataLen);
 1314|      0|	else
 1315|      0|		keybuf = calloc(1,8); /* pass in  dummy buffer */
 1316|       |
 1317|      0|	if (!keybuf) {
  ------------------
  |  Branch (1317:6): [True: 0, False: 0]
  ------------------
 1318|      0|		rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 1319|      0|		goto out;
 1320|      0|	}
 1321|       |
 1322|       |	/* Now do the actual derivation */
 1323|       |
 1324|      0|	rv = operation->type->derive(operation, basekey,
 1325|      0|	    pMechanism->pParameter, pMechanism->ulParameterLen,
 1326|      0|	    keybuf, &ulDataLen);
 1327|      0|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1327:6): [True: 0, False: 0]
  ------------------
 1328|      0|	    goto out;
 1329|       |
 1330|       |
 1331|       |/* add the CKA_VALUE attribute to the template if it was returned
 1332|       | * if not assume it is on the card...
 1333|       | * But for now PIV with ECDH returns the generic key data
 1334|       | * TODO need to support truncation, if CKA_VALUE_LEN < ulDataLem
 1335|       | */
 1336|      0|	if (ulDataLen > 0) {
  ------------------
  |  Branch (1336:6): [True: 0, False: 0]
  ------------------
 1337|      0|	    template[0].pValue = keybuf;
 1338|      0|	    template[0].ulValueLen = ulDataLen;
 1339|       |
 1340|      0|	    dkey->ops->set_attribute(session, dkey, &template[0]);
 1341|       |
 1342|      0|	    memset(keybuf,0,ulDataLen);
 1343|      0|	}
 1344|       |
 1345|      0|out:
 1346|      0|	session_stop_operation(session, SC_PKCS11_OPERATION_DERIVE);
 1347|       |
 1348|      0|	if (keybuf)
  ------------------
  |  Branch (1348:6): [True: 0, False: 0]
  ------------------
 1349|      0|	    free(keybuf);
 1350|      0|	return rv;
 1351|      0|}
sc_pkcs11_new_fw_mechanism:
 1691|  83.4k|{
 1692|  83.4k|	sc_pkcs11_mechanism_type_t *mt;
 1693|       |
 1694|  83.4k|	mt = calloc(1, sizeof(*mt));
 1695|  83.4k|	if (mt == NULL)
  ------------------
  |  Branch (1695:6): [True: 0, False: 83.4k]
  ------------------
 1696|      0|		return mt;
 1697|  83.4k|	mt->mech = mech;
 1698|  83.4k|	mt->mech_info = *pInfo;
 1699|  83.4k|	mt->key_types[0] = (int)key_type;
 1700|  83.4k|	mt->key_types[1] = -1;
 1701|  83.4k|	mt->mech_data = priv_data;
 1702|  83.4k|	mt->free_mech_data = free_priv_data;
 1703|  83.4k|	mt->copy_mech_data = copy_priv_data;
 1704|  83.4k|	mt->obj_size = sizeof(sc_pkcs11_operation_t);
 1705|       |
 1706|  83.4k|	mt->release = sc_pkcs11_operation_release;
 1707|       |
 1708|  83.4k|	if (pInfo->flags & CKF_SIGN) {
  ------------------
  |  |  363|  83.4k|#define CKF_SIGN 0x00000800UL
  ------------------
  |  Branch (1708:6): [True: 74.3k, False: 9.12k]
  ------------------
 1709|  74.3k|		mt->sign_init = sc_pkcs11_signature_init;
 1710|  74.3k|		mt->sign_update = sc_pkcs11_signature_update;
 1711|  74.3k|		mt->sign_final = sc_pkcs11_signature_final;
 1712|  74.3k|		mt->sign_size = sc_pkcs11_signature_size;
 1713|  74.3k|#ifdef ENABLE_OPENSSL
 1714|  74.3k|		mt->verif_init = sc_pkcs11_verify_init;
 1715|  74.3k|		mt->verif_update = sc_pkcs11_verify_update;
 1716|  74.3k|		mt->verif_final = sc_pkcs11_verify_final;
 1717|  74.3k|#endif
 1718|  74.3k|	}
 1719|  83.4k|	if (pInfo->flags & CKF_WRAP) {
  ------------------
  |  |  369|  83.4k|#define CKF_WRAP 0x00020000UL
  ------------------
  |  Branch (1719:6): [True: 78, False: 83.3k]
  ------------------
 1720|     78|		mt->wrap = sc_pkcs11_wrap_operation;
 1721|     78|	}
 1722|  83.4k|	if (pInfo->flags & CKF_UNWRAP) {
  ------------------
  |  |  370|  83.4k|#define CKF_UNWRAP 0x00040000UL
  ------------------
  |  Branch (1722:6): [True: 78, False: 83.3k]
  ------------------
 1723|     78|		mt->unwrap = sc_pkcs11_unwrap_operation;
 1724|     78|	}
 1725|  83.4k|	if (pInfo->flags & CKF_DERIVE) {
  ------------------
  |  |  371|  83.4k|#define CKF_DERIVE 0x00080000UL
  ------------------
  |  Branch (1725:6): [True: 3.90k, False: 79.5k]
  ------------------
 1726|  3.90k|		mt->derive = sc_pkcs11_derive;
 1727|  3.90k|	}
 1728|  83.4k|	if (pInfo->flags & CKF_DECRYPT) {
  ------------------
  |  |  361|  83.4k|#define CKF_DECRYPT 0x00000200UL
  ------------------
  |  Branch (1728:6): [True: 13.2k, False: 70.2k]
  ------------------
 1729|  13.2k|		mt->decrypt_init = sc_pkcs11_decrypt_init;
 1730|  13.2k|		mt->decrypt = sc_pkcs11_decrypt;
 1731|  13.2k|		mt->decrypt_update = sc_pkcs11_decrypt_update;
 1732|  13.2k|		mt->decrypt_final = sc_pkcs11_decrypt_final;
 1733|  13.2k|	}
 1734|  83.4k|	if (pInfo->flags & CKF_ENCRYPT) {
  ------------------
  |  |  360|  83.4k|#define CKF_ENCRYPT 0x00000100UL
  ------------------
  |  Branch (1734:6): [True: 15, False: 83.4k]
  ------------------
 1735|     15|		mt->encrypt_init = sc_pkcs11_encrypt_init;
 1736|     15|		mt->encrypt = sc_pkcs11_encrypt;
 1737|     15|		mt->encrypt_update = sc_pkcs11_encrypt_update;
 1738|     15|		mt->encrypt_final = sc_pkcs11_encrypt_final;
 1739|     15|	}
 1740|       |
 1741|  83.4k|	return mt;
 1742|  83.4k|}
sc_pkcs11_free_mechanism:
 1745|   127k|{
 1746|   127k|	if (!mt || !(*mt))
  ------------------
  |  Branch (1746:6): [True: 0, False: 127k]
  |  Branch (1746:13): [True: 1.93k, False: 125k]
  ------------------
 1747|  1.93k|		return;
 1748|   125k|	if ((*mt)->free_mech_data)
  ------------------
  |  Branch (1748:6): [True: 94.7k, False: 30.4k]
  ------------------
 1749|  94.7k|		(*mt)->free_mech_data((*mt)->mech_data);
 1750|   125k|	free(*mt);
 1751|       |	*mt = NULL;
 1752|   125k|}
sc_pkcs11_register_generic_mechanisms:
 1759|  5.21k|{
 1760|  5.21k|#ifdef ENABLE_OPENSSL
 1761|  5.21k|	sc_pkcs11_register_openssl_mechanisms(p11card);
 1762|  5.21k|#endif
 1763|  5.21k|	return CKR_OK;
  ------------------
  |  | 1086|  5.21k|#define CKR_OK 0x00000000UL
  ------------------
 1764|  5.21k|}
free_info:
 1767|   116k|{
 1768|   116k|	free((void *) info);
 1769|   116k|}
copy_hash_signature_info:
 1772|  58.2k|{
 1773|  58.2k|	if (mech_data == NULL || new_data == NULL)
  ------------------
  |  Branch (1773:6): [True: 0, False: 58.2k]
  |  Branch (1773:27): [True: 0, False: 58.2k]
  ------------------
 1774|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1775|       |
 1776|  58.2k|	*new_data = calloc(1, sizeof(struct hash_signature_info));
 1777|  58.2k|	if (!(*new_data))
  ------------------
  |  Branch (1777:6): [True: 0, False: 58.2k]
  ------------------
 1778|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 1779|       |
 1780|  58.2k|	memcpy(*new_data, mech_data, sizeof(struct hash_signature_info));
 1781|  58.2k|	return CKR_OK;
  ------------------
  |  | 1086|  58.2k|#define CKR_OK 0x00000000UL
  ------------------
 1782|  58.2k|}
sc_pkcs11_register_sign_and_hash_mechanism:
 1793|  58.2k|{
 1794|  58.2k|	sc_pkcs11_mechanism_type_t *hash_type, *new_type;
 1795|  58.2k|	struct hash_signature_info *info;
 1796|  58.2k|	CK_MECHANISM_INFO mech_info;
 1797|  58.2k|	CK_RV rv;
 1798|       |
 1799|  58.2k|	LOG_FUNC_CALLED(p11card->card->ctx);
  ------------------
  |  |  151|  58.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  58.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  58.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  58.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 58.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1800|  58.2k|	sc_log(p11card->card->ctx, "mech = 0x%lx, hash_mech = 0x%lx", mech, hash_mech);
  ------------------
  |  |   71|  58.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__
  |  |  ------------------
  ------------------
 1801|       |
 1802|  58.2k|	if (!sign_type)
  ------------------
  |  Branch (1802:6): [True: 0, False: 58.2k]
  ------------------
 1803|  58.2k|		LOG_FUNC_RETURN(p11card->card->ctx, CKR_MECHANISM_INVALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1804|  58.2k|	mech_info = sign_type->mech_info;
 1805|       |
 1806|  58.2k|	if (!(hash_type = sc_pkcs11_find_mechanism(p11card, hash_mech, CKF_DIGEST)))
  ------------------
  |  |  362|  58.2k|#define CKF_DIGEST 0x00000400UL
  ------------------
  |  Branch (1806:6): [True: 0, False: 58.2k]
  ------------------
 1807|  58.2k|		LOG_FUNC_RETURN(p11card->card->ctx, CKR_MECHANISM_INVALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1808|       |
 1809|       |	/* These hash-based mechs can only be used for sign/verify */
 1810|  58.2k|	mech_info.flags &= (CKF_SIGN | CKF_SIGN_RECOVER | CKF_VERIFY | CKF_VERIFY_RECOVER);
  ------------------
  |  |  363|  58.2k|#define CKF_SIGN 0x00000800UL
  ------------------
              	mech_info.flags &= (CKF_SIGN | CKF_SIGN_RECOVER | CKF_VERIFY | CKF_VERIFY_RECOVER);
  ------------------
  |  |  364|  58.2k|#define CKF_SIGN_RECOVER 0x00001000UL
  ------------------
              	mech_info.flags &= (CKF_SIGN | CKF_SIGN_RECOVER | CKF_VERIFY | CKF_VERIFY_RECOVER);
  ------------------
  |  |  365|  58.2k|#define CKF_VERIFY 0x00002000UL
  ------------------
              	mech_info.flags &= (CKF_SIGN | CKF_SIGN_RECOVER | CKF_VERIFY | CKF_VERIFY_RECOVER);
  ------------------
  |  |  366|  58.2k|#define CKF_VERIFY_RECOVER 0x00004000UL
  ------------------
 1811|       |
 1812|  58.2k|	info = calloc(1, sizeof(*info));
 1813|  58.2k|	if (!info)
  ------------------
  |  Branch (1813:6): [True: 0, False: 58.2k]
  ------------------
 1814|  58.2k|		LOG_FUNC_RETURN(p11card->card->ctx, CKR_HOST_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1815|       |
 1816|  58.2k|	info->mech = mech;
 1817|  58.2k|	info->hash_type = hash_type;
 1818|  58.2k|	info->sign_mech = sign_type->mech;
 1819|  58.2k|	info->hash_mech = hash_mech;
 1820|       |
 1821|  58.2k|	new_type = sc_pkcs11_new_fw_mechanism(mech, &mech_info, sign_type->key_types[0],
 1822|  58.2k|			info, free_info, copy_hash_signature_info);
 1823|  58.2k|	if (!new_type) {
  ------------------
  |  Branch (1823:6): [True: 0, False: 58.2k]
  ------------------
 1824|      0|		free_info(info);
 1825|      0|		LOG_FUNC_RETURN(p11card->card->ctx, CKR_HOST_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1826|      0|	}
 1827|       |
 1828|  58.2k|	rv = sc_pkcs11_register_mechanism(p11card, new_type, NULL);
 1829|  58.2k|	sc_pkcs11_free_mechanism(&new_type);
 1830|       |
 1831|  58.2k|	LOG_FUNC_RETURN(p11card->card->ctx, (int)rv);
  ------------------
  |  |  164|  58.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  58.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  58.2k|	int _ret = r; \
  |  |  |  |  155|  58.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  58.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: 58.2k]
  |  |  |  |  ------------------
  |  |  |  |  157|  58.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  58.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|  58.2k|	return _ret; \
  |  |  |  |  163|  58.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1832|  58.2k|}
mechanism.c:sc_pkcs11_copy_mechanism:
  104|   125k|{
  105|   125k|	CK_RV rv;
  106|       |
  107|   125k|	*new_mt = calloc(1, sizeof(sc_pkcs11_mechanism_type_t));
  108|   125k|	if (!(*new_mt))
  ------------------
  |  Branch (108:6): [True: 0, False: 125k]
  ------------------
  109|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  110|       |
  111|   125k|	memcpy(*new_mt, mt, sizeof(sc_pkcs11_mechanism_type_t));
  112|       |	/* mech_data needs specific function for making copy*/
  113|   125k|	if (mt->copy_mech_data
  ------------------
  |  Branch (113:6): [True: 94.7k, False: 30.3k]
  ------------------
  114|  94.7k|		&& (rv = mt->copy_mech_data(mt->mech_data, (void **) &(*new_mt)->mech_data)) != CKR_OK) {
  ------------------
  |  | 1086|  94.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (114:6): [True: 0, False: 94.7k]
  ------------------
  115|      0|		free(*new_mt);
  116|      0|		return rv;
  117|      0|	}
  118|       |
  119|   125k|	return CKR_OK;
  ------------------
  |  | 1086|   125k|#define CKR_OK 0x00000000UL
  ------------------
  120|   125k|}
mechanism.c:sc_pkcs11_operation_release:
  662|    481|{
  663|    481|	if (!operation)
  ------------------
  |  Branch (663:6): [True: 0, False: 481]
  ------------------
  664|      0|	    return;
  665|    481|	operation_data_release(operation->priv_data);
  666|    481|}
mechanism.c:operation_data_release:
   56|    487|{
   57|    487|	if (!data)
  ------------------
  |  Branch (57:6): [True: 6, False: 481]
  ------------------
   58|      6|		return;
   59|    481|	sc_pkcs11_release_operation(&data->md);
   60|    481|	sc_mem_secure_clear_free(data->buffer, data->buffer_len);
  ------------------
  |  | 1580|    481|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|    481|	sc_mem_clear(ptr, len); \
  |  | 1582|    481|	sc_mem_secure_free(ptr, len); \
  |  | 1583|    481|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 481]
  |  |  ------------------
  ------------------
   61|    481|	free(data);
   62|    481|}
mechanism.c:sc_pkcs11_signature_init:
  502|    244|{
  503|    244|	struct hash_signature_info *info;
  504|    244|	struct operation_data *data;
  505|    244|	CK_RV rv;
  506|    244|	int can_do_it = 0;
  507|       |
  508|    244|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|    244|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    244|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    244|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    244|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 244]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  509|    244|	if (!(data = new_operation_data()))
  ------------------
  |  Branch (509:6): [True: 0, False: 244]
  ------------------
  510|    244|		LOG_FUNC_RETURN(context, CKR_HOST_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|    244|	data->info = NULL;
  512|    244|	data->key = key;
  513|       |
  514|    244|	if (key->ops->can_do)   {
  ------------------
  |  Branch (514:6): [True: 244, False: 0]
  ------------------
  515|    244|		rv = key->ops->can_do(operation->session, key, operation->type->mech, CKF_SIGN);
  ------------------
  |  |  363|    244|#define CKF_SIGN 0x00000800UL
  ------------------
  516|    244|		if (rv == CKR_OK)   {
  ------------------
  |  | 1086|    244|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (516:7): [True: 0, False: 244]
  ------------------
  517|       |			/* Mechanism recognised and can be performed by pkcs#15 card */
  518|      0|			can_do_it = 1;
  519|      0|		}
  520|    244|		else if (rv == CKR_FUNCTION_NOT_SUPPORTED)   {
  ------------------
  |  | 1111|    244|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
  |  Branch (520:12): [True: 244, False: 0]
  ------------------
  521|       |			/* Mechanism not recognised by pkcs#15 card */
  522|    244|			can_do_it = 0;
  523|    244|		}
  524|      0|		else  {
  525|       |			/* Mechanism recognised but cannot be performed by pkcs#15 card, or some general error. */
  526|      0|			operation_data_release(data);
  527|      0|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  528|      0|		}
  529|    244|	}
  530|       |
  531|       |	/* Validate the mechanism parameters */
  532|    244|	if (key->ops->init_params) {
  ------------------
  |  Branch (532:6): [True: 244, False: 0]
  ------------------
  533|    244|		rv = key->ops->init_params(operation->session, &operation->mechanism);
  534|    244|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|    244|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (534:7): [True: 6, False: 238]
  ------------------
  535|       |			/* Probably bad arguments */
  536|      6|			operation_data_release(data);
  537|      6|			LOG_FUNC_RETURN(context, (int) 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: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      6|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      6|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      6|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|      6|		}
  539|    244|	}
  540|       |
  541|       |	/* If this is a signature with hash operation,
  542|       |	 * and card cannot perform itself signature with hash operation,
  543|       |	 * set up the hash operation */
  544|    238|	info = (struct hash_signature_info *)operation->type->mech_data;
  545|    238|	if (info != NULL && !can_do_it) {
  ------------------
  |  Branch (545:6): [True: 147, False: 91]
  |  Branch (545:22): [True: 147, False: 0]
  ------------------
  546|       |		/* Initialize hash operation */
  547|       |
  548|    147|		data->md = sc_pkcs11_new_operation(operation->session, info->hash_type);
  549|    147|		if (data->md == NULL)
  ------------------
  |  Branch (549:7): [True: 0, False: 147]
  ------------------
  550|      0|			rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  551|    147|		else
  552|    147|			rv = info->hash_type->md_init(data->md);
  553|    147|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|    147|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (553:7): [True: 0, False: 147]
  ------------------
  554|      0|			sc_pkcs11_release_operation(&data->md);
  555|      0|			operation_data_release(data);
  556|      0|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  557|      0|		}
  558|    147|		data->info = info;
  559|    147|	}
  560|       |
  561|    238|	operation->priv_data = data;
  562|    238|	LOG_FUNC_RETURN(context, CKR_OK);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  563|    238|}
mechanism.c:new_operation_data:
   50|    481|{
   51|    481|	return calloc(1, sizeof(struct operation_data));
   52|    481|}
mechanism.c:sc_pkcs11_signature_update:
  568|    246|{
  569|    246|	struct operation_data *data;
  570|    246|	CK_RV rv;
  571|       |
  572|    246|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  573|    246|	sc_log(context, "data part length %li", ulPartLen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  574|    246|	data = (struct operation_data *)operation->priv_data;
  575|    246|	if (data->md) {
  ------------------
  |  Branch (575:6): [True: 153, False: 93]
  ------------------
  576|    153|		rv = data->md->type->md_update(data->md, pPart, ulPartLen);
  577|    153|		LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    153|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    153|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    153|	int _ret = r; \
  |  |  |  |  155|    153|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 153, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    153|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 153]
  |  |  |  |  ------------------
  |  |  |  |  157|    153|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    153|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    153|	return _ret; \
  |  |  |  |  163|    153|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|    153|	}
  579|       |
  580|       |	/* This signature mechanism operates on the raw data */
  581|     93|	rv = signature_data_buffer_append(data, pPart, ulPartLen);
  582|     93|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|     93|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     93|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     93|	int _ret = r; \
  |  |  |  |  155|     93|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 93, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     93|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  157|     93|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     93|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     93|	return _ret; \
  |  |  |  |  163|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|     93|}
mechanism.c:signature_data_buffer_append:
   67|    252|{
   68|    252|	if (!data)
  ------------------
  |  Branch (68:6): [True: 0, False: 252]
  ------------------
   69|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
   70|    252|	if (in_len == 0)
  ------------------
  |  Branch (70:6): [True: 0, False: 252]
  ------------------
   71|      0|		return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
   72|       |
   73|    252|	CK_ULONG new_len;
   74|    252|	if (__builtin_uaddl_overflow(data->buffer_len, in_len, &new_len))
  ------------------
  |  Branch (74:6): [True: 0, False: 252]
  ------------------
   75|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
   76|    252|	CK_BYTE *new_buffer = sc_mem_secure_alloc(new_len);
   77|    252|	if (!new_buffer)
  ------------------
  |  Branch (77:6): [True: 0, False: 252]
  ------------------
   78|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
   79|       |
   80|    252|	if (data->buffer_len != 0)
  ------------------
  |  Branch (80:6): [True: 2, False: 250]
  ------------------
   81|      2|		memcpy(new_buffer, data->buffer, data->buffer_len);
   82|    252|	memcpy(new_buffer+data->buffer_len, in, in_len);
   83|       |
   84|    252|	sc_mem_secure_clear_free(data->buffer, data->buffer_len);
  ------------------
  |  | 1580|    252|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|    252|	sc_mem_clear(ptr, len); \
  |  | 1582|    252|	sc_mem_secure_free(ptr, len); \
  |  | 1583|    252|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 252]
  |  |  ------------------
  ------------------
   85|    252|	data->buffer = new_buffer;
   86|    252|	data->buffer_len = new_len;
   87|    252|	return CKR_OK;
  ------------------
  |  | 1086|    252|#define CKR_OK 0x00000000UL
  ------------------
   88|    252|}
mechanism.c:sc_pkcs11_signature_final:
  588|    238|{
  589|    238|	struct operation_data *data;
  590|    238|	CK_RV rv;
  591|       |
  592|    238|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|    238|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    238|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    238|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    238|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 238]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  593|    238|	data = (struct operation_data *)operation->priv_data;
  594|    238|	if (data->md) {
  ------------------
  |  Branch (594:6): [True: 147, False: 91]
  ------------------
  595|    147|		sc_pkcs11_operation_t	*md = data->md;
  596|    147|		CK_BYTE hash[64];
  597|    147|		CK_ULONG len = sizeof(hash);
  598|       |
  599|    147|		rv = md->type->md_final(md, hash, &len);
  600|    147|		if (rv == CKR_BUFFER_TOO_SMALL)
  ------------------
  |  | 1165|    147|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  |  Branch (600:7): [True: 0, False: 147]
  ------------------
  601|      0|			rv = CKR_FUNCTION_FAILED;
  ------------------
  |  | 1091|      0|#define CKR_FUNCTION_FAILED 0x00000006UL
  ------------------
  602|    147|		if (rv != CKR_OK)
  ------------------
  |  | 1086|    147|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (602:7): [True: 0, False: 147]
  ------------------
  603|    147|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  604|    147|		rv = signature_data_buffer_append(data, hash, len);
  605|    147|		if (rv != CKR_OK)
  ------------------
  |  | 1086|    147|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (605:7): [True: 0, False: 147]
  ------------------
  606|    147|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  607|    147|	}
  608|       |
  609|    238|	rv = data->key->ops->sign(operation->session, data->key, &operation->mechanism,
  610|    238|			data->buffer, data->buffer_len, pSignature, pulSignatureLen);
  611|    238|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 191]
  |  |  |  |  ------------------
  |  |  |  |  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|    191|	} else { \
  |  |  |  |  159|    191|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    191|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    191|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|    238|}
mechanism.c:sc_pkcs11_signature_size:
  616|    238|{
  617|    238|	struct sc_pkcs11_object *key;
  618|    238|	CK_ATTRIBUTE attr = { CKA_MODULUS_BITS, pLength, sizeof(*pLength) };
  ------------------
  |  |  175|    238|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
  619|    238|	CK_KEY_TYPE key_type;
  620|    238|	CK_ATTRIBUTE attr_key_type = { CKA_KEY_TYPE, &key_type, sizeof(key_type) };
  ------------------
  |  |  159|    238|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  621|    238|	CK_RV rv;
  622|       |
  623|    238|	key = ((struct operation_data *)operation->priv_data)->key;
  624|       |	/*
  625|       |	 * EC and GOSTR do not have CKA_MODULUS_BITS attribute.
  626|       |	 * But other code in framework treats them as if they do.
  627|       |	 * So should do switch(key_type)
  628|       |	 * and then get what ever attributes are needed.
  629|       |	 */
  630|    238|	rv = key->ops->get_attribute(operation->session, key, &attr_key_type);
  631|    238|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|    238|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (631:6): [True: 238, False: 0]
  ------------------
  632|    238|		switch(key_type) {
  633|    211|			case CKK_RSA:
  ------------------
  |  |  464|    211|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (633:4): [True: 211, False: 27]
  ------------------
  634|    211|				rv = key->ops->get_attribute(operation->session, key, &attr);
  635|       |				/* convert bits to bytes */
  636|    211|				if (rv == CKR_OK)
  ------------------
  |  | 1086|    211|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (636:9): [True: 211, False: 0]
  ------------------
  637|    211|					*pLength = BYTES4BITS(*pLength);
  ------------------
  |  |  146|    211|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  638|    211|				break;
  639|     27|			case CKK_EC:
  ------------------
  |  |  467|     27|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (639:4): [True: 27, False: 211]
  ------------------
  640|     27|			case CKK_EC_EDWARDS:
  ------------------
  |  |  518|     27|#define CKK_EC_EDWARDS 0x00000040UL
  ------------------
  |  Branch (640:4): [True: 0, False: 238]
  ------------------
  641|     27|			case CKK_EC_MONTGOMERY:
  ------------------
  |  |  519|     27|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
  |  Branch (641:4): [True: 0, False: 238]
  ------------------
  642|       |				/* TODO: -DEE we should use something other then CKA_MODULUS_BITS... */
  643|     27|				rv = key->ops->get_attribute(operation->session, key, &attr);
  644|     27|				if (rv == CKR_OK)
  ------------------
  |  | 1086|     27|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (644:9): [True: 27, False: 0]
  ------------------
  645|     27|					*pLength = BYTES4BITS(*pLength) * 2 ; /* 2*nLen in bytes */
  ------------------
  |  |  146|     27|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  646|     27|				break;
  647|      0|			case CKK_GOSTR3410:
  ------------------
  |  |  502|      0|#define CKK_GOSTR3410 0x00000030UL
  ------------------
  |  Branch (647:4): [True: 0, False: 238]
  ------------------
  648|      0|				rv = key->ops->get_attribute(operation->session, key, &attr);
  649|      0|				if (rv == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (649:9): [True: 0, False: 0]
  ------------------
  650|      0|					*pLength = BYTES4BITS(*pLength) * 2;
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  651|      0|				break;
  652|      0|			default:
  ------------------
  |  Branch (652:4): [True: 0, False: 238]
  ------------------
  653|      0|				rv = CKR_MECHANISM_INVALID;
  ------------------
  |  | 1122|      0|#define CKR_MECHANISM_INVALID 0x00000070UL
  ------------------
  654|    238|		}
  655|    238|	}
  656|       |
  657|    238|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  658|    238|}
mechanism.c:sc_pkcs11_verify_init:
  774|     50|{
  775|     50|	struct hash_signature_info *info;
  776|     50|	struct operation_data *data;
  777|     50|	CK_RV rv;
  778|       |
  779|     50|	if (!(data = new_operation_data()))
  ------------------
  |  Branch (779:6): [True: 0, False: 50]
  ------------------
  780|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  781|       |
  782|     50|	data->info = NULL;
  783|     50|	data->key = key;
  784|       |
  785|     50|	if (key->ops->can_do)   {
  ------------------
  |  Branch (785:6): [True: 0, False: 50]
  ------------------
  786|      0|		rv = key->ops->can_do(operation->session, key, operation->type->mech, CKF_SIGN);
  ------------------
  |  |  363|      0|#define CKF_SIGN 0x00000800UL
  ------------------
  787|      0|		if ((rv == CKR_OK) || (rv == CKR_FUNCTION_NOT_SUPPORTED))   {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
              		if ((rv == CKR_OK) || (rv == CKR_FUNCTION_NOT_SUPPORTED))   {
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
  |  Branch (787:7): [True: 0, False: 0]
  |  Branch (787:25): [True: 0, False: 0]
  ------------------
  788|       |			/* Mechanism recognized and can be performed by pkcs#15 card or algorithm references not supported */
  789|      0|		}
  790|      0|		else {
  791|       |			/* Mechanism cannot be performed by pkcs#15 card, or some general error. */
  792|      0|			free(data);
  793|      0|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  794|      0|		}
  795|      0|	}
  796|       |
  797|       |	/* Validate the mechanism parameters */
  798|     50|	if (key->ops->init_params) {
  ------------------
  |  Branch (798:6): [True: 0, False: 50]
  ------------------
  799|      0|		rv = key->ops->init_params(operation->session, &operation->mechanism);
  800|      0|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (800:7): [True: 0, False: 0]
  ------------------
  801|       |			/* Probably bad arguments */
  802|      0|			free(data);
  803|      0|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  804|      0|		}
  805|      0|	}
  806|       |
  807|       |	/* If this is a verify with hash operation, set up the
  808|       |	 * hash operation */
  809|     50|	info = (struct hash_signature_info *) operation->type->mech_data;
  810|     50|	if (info != NULL) {
  ------------------
  |  Branch (810:6): [True: 38, False: 12]
  ------------------
  811|       |		/* Initialize hash operation */
  812|     38|		data->md = sc_pkcs11_new_operation(operation->session,
  813|     38|						   info->hash_type);
  814|     38|		if (data->md == NULL)
  ------------------
  |  Branch (814:7): [True: 0, False: 38]
  ------------------
  815|      0|			rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  816|     38|		else
  817|     38|			rv = info->hash_type->md_init(data->md);
  818|     38|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|     38|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (818:7): [True: 0, False: 38]
  ------------------
  819|      0|			sc_pkcs11_release_operation(&data->md);
  820|      0|			free(data);
  821|      0|			return rv;
  822|      0|		}
  823|     38|		data->info = info;
  824|     38|	}
  825|       |
  826|     50|	operation->priv_data = data;
  827|     50|	return CKR_OK;
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  828|     50|}
mechanism.c:sc_pkcs11_verify_update:
  833|     50|{
  834|     50|	struct operation_data *data;
  835|       |
  836|     50|	data = (struct operation_data *)operation->priv_data;
  837|     50|	if (data->md) {
  ------------------
  |  Branch (837:6): [True: 38, False: 12]
  ------------------
  838|     38|		sc_pkcs11_operation_t	*md = data->md;
  839|       |
  840|     38|		return md->type->md_update(md, pPart, ulPartLen);
  841|     38|	}
  842|       |
  843|       |	/* This verification mechanism operates on the raw data */
  844|     12|	CK_RV rv = signature_data_buffer_append(data, pPart, ulPartLen);
  845|     12|	LOG_FUNC_RETURN(context, (int) rv);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     12|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|     12|}
mechanism.c:sc_pkcs11_verify_final:
  851|     50|{
  852|     50|	struct operation_data *data;
  853|     50|	struct sc_pkcs11_object *key;
  854|     50|	unsigned char *pubkey_value = NULL;
  855|     50|	CK_KEY_TYPE key_type;
  856|     50|	CK_BYTE params[9 /* GOST_PARAMS_ENCODED_OID_SIZE */] = { 0 };
  857|     50|	CK_ATTRIBUTE attr = {CKA_VALUE, NULL, 0};
  ------------------
  |  |  143|     50|#define CKA_VALUE 0x00000011UL
  ------------------
  858|     50|	CK_ATTRIBUTE attr_key_type = {CKA_KEY_TYPE, &key_type, sizeof(key_type)};
  ------------------
  |  |  159|     50|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  859|     50|	CK_ATTRIBUTE attr_key_params = {CKA_GOSTR3410_PARAMS, &params, sizeof(params)};
  ------------------
  |  |  218|     50|#define CKA_GOSTR3410_PARAMS 0x00000250UL
  ------------------
  860|     50|	CK_RV rv;
  861|       |
  862|     50|	data = (struct operation_data *)operation->priv_data;
  863|       |
  864|     50|	if (pSignature == NULL)
  ------------------
  |  Branch (864:6): [True: 0, False: 50]
  ------------------
  865|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  866|       |
  867|     50|	key = data->key;
  868|     50|	rv = key->ops->get_attribute(operation->session, key, &attr_key_type);
  869|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (869:6): [True: 0, False: 50]
  ------------------
  870|      0|		return rv;
  871|       |
  872|     50|	if (key_type != CKK_GOSTR3410)
  ------------------
  |  |  502|     50|#define CKK_GOSTR3410 0x00000030UL
  ------------------
  |  Branch (872:6): [True: 50, False: 0]
  ------------------
  873|     50|		attr.type = CKA_SPKI;
  ------------------
  |  |   21|     50|#define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |  289|     50|#define CKA_VENDOR_DEFINED 0x80000000UL
  |  |  ------------------
  |  |               #define CKA_SPKI			(CKA_VENDOR_DEFINED | SC_VENDOR_DEFINED | 2UL)
  |  |  ------------------
  |  |  |  |   12|     50|#define SC_VENDOR_DEFINED 0x4F534300  /* OSC */
  |  |  ------------------
  ------------------
  874|       |
  875|     50|	rv = key->ops->get_attribute(operation->session, key, &attr);
  876|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (876:6): [True: 4, False: 46]
  ------------------
  877|      4|		return rv;
  878|     46|	pubkey_value = calloc(1, attr.ulValueLen);
  879|     46|	if (!pubkey_value) {
  ------------------
  |  Branch (879:6): [True: 0, False: 46]
  ------------------
  880|      0|		rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  881|      0|		goto done;
  882|      0|	}
  883|     46|	attr.pValue = pubkey_value;
  884|     46|	rv = key->ops->get_attribute(operation->session, key, &attr);
  885|     46|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     46|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (885:6): [True: 0, False: 46]
  ------------------
  886|      0|		goto done;
  887|       |
  888|     46|	if (key_type == CKK_GOSTR3410) {
  ------------------
  |  |  502|     46|#define CKK_GOSTR3410 0x00000030UL
  ------------------
  |  Branch (888:6): [True: 0, False: 46]
  ------------------
  889|      0|		rv = key->ops->get_attribute(operation->session, key, &attr_key_params);
  890|      0|		if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (890:7): [True: 0, False: 0]
  ------------------
  891|      0|			goto done;
  892|      0|	}
  893|       |
  894|     46|	rv = sc_pkcs11_verify_data(pubkey_value, attr.ulValueLen,
  895|     46|		params, sizeof(params),
  896|     46|		&operation->mechanism, data->md,
  897|     46|		data->buffer, data->buffer_len, pSignature, ulSignatureLen);
  898|       |
  899|     46|done:
  900|     46|	free(pubkey_value);
  901|       |
  902|     46|	return rv;
  903|     46|}
mechanism.c:sc_pkcs11_decrypt_init:
 1496|    187|{
 1497|    187|	struct operation_data *data;
 1498|    187|	CK_RV rv;
 1499|       |
 1500|    187|	if (!(data = new_operation_data()))
  ------------------
  |  Branch (1500:6): [True: 0, False: 187]
  ------------------
 1501|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
 1502|       |
 1503|    187|	data->key = key;
 1504|       |
 1505|    187|	if (key->ops->can_do)   {
  ------------------
  |  Branch (1505:6): [True: 187, False: 0]
  ------------------
 1506|    187|		rv = key->ops->can_do(operation->session, key, operation->type->mech, CKF_DECRYPT);
  ------------------
  |  |  361|    187|#define CKF_DECRYPT 0x00000200UL
  ------------------
 1507|    187|		if ((rv == CKR_OK) || (rv == CKR_FUNCTION_NOT_SUPPORTED))   {
  ------------------
  |  | 1086|    187|#define CKR_OK 0x00000000UL
  ------------------
              		if ((rv == CKR_OK) || (rv == CKR_FUNCTION_NOT_SUPPORTED))   {
  ------------------
  |  | 1111|    187|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
  |  Branch (1507:7): [True: 0, False: 187]
  |  Branch (1507:25): [True: 187, False: 0]
  ------------------
 1508|       |			/* Mechanism recognized and can be performed by pkcs#15 card or algorithm references not supported */
 1509|    187|		}
 1510|      0|		else {
 1511|       |			/* Mechanism cannot be performed by pkcs#15 card, or some general error. */
 1512|      0|			free(data);
 1513|      0|			LOG_FUNC_RETURN(context, (int) 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1514|      0|		}
 1515|    187|	}
 1516|    187|	operation->priv_data = data;
 1517|       |
 1518|       |	/* The last parameter is NULL - this is call to INIT code in underlying functions */
 1519|    187|	return key->ops->decrypt(operation->session,
 1520|    187|			key, &operation->mechanism, NULL, 0, NULL, NULL);
 1521|    187|}
mechanism.c:sc_pkcs11_decrypt:
 1527|    186|{
 1528|    186|	struct operation_data *data;
 1529|    186|	struct sc_pkcs11_object *key;
 1530|    186|	CK_RV rv;
 1531|    186|	CK_ULONG ulDataLen, ulLastDataLen;
 1532|       |
 1533|       |	/* PKCS#11: If pBuf is not NULL_PTR, then *pulBufLen must contain the size in bytes.. */
 1534|    186|	if (pData && !pulDataLen)
  ------------------
  |  Branch (1534:6): [True: 186, False: 0]
  |  Branch (1534:15): [True: 0, False: 186]
  ------------------
 1535|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1536|       |
 1537|    186|	ulDataLen = pulDataLen ? *pulDataLen : 0;
  ------------------
  |  Branch (1537:14): [True: 186, False: 0]
  ------------------
 1538|    186|	ulLastDataLen = ulDataLen;
 1539|       |
 1540|    186|	data = (struct operation_data *)operation->priv_data;
 1541|       |
 1542|    186|	key = data->key;
 1543|       |
 1544|       |	/* Decrypt */
 1545|    186|	rv = key->ops->decrypt(operation->session, key, &operation->mechanism,
 1546|    186|			pEncryptedData, ulEncryptedDataLen, pData, &ulDataLen);
 1547|       |
 1548|    186|	if (pulDataLen)
  ------------------
  |  Branch (1548:6): [True: 186, False: 0]
  ------------------
 1549|    186|		*pulDataLen = ulDataLen;
 1550|       |
 1551|       |	/* Skip DecryptFinalize for PKCS#1 v1.5 padding to prevent time side-channel leakage */
 1552|    186|	if (((CK_MECHANISM_PTR)&operation->mechanism)->mechanism == CKM_RSA_PKCS)
  ------------------
  |  |  539|    186|#define CKM_RSA_PKCS 0x00000001UL
  ------------------
  |  Branch (1552:6): [True: 181, False: 5]
  ------------------
 1553|    181|		return rv;
 1554|       |
 1555|      5|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      5|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1555:6): [True: 2, False: 3]
  ------------------
 1556|      2|		return rv;
 1557|       |
 1558|       |	/* recalculate buffer space */
 1559|      3|	if (ulDataLen <= ulLastDataLen)
  ------------------
  |  Branch (1559:6): [True: 3, False: 0]
  ------------------
 1560|      3|		ulLastDataLen -= ulDataLen;
 1561|      0|	else
 1562|      0|		ulLastDataLen = 0;
 1563|       |
 1564|       |	/* DecryptFinalize */
 1565|      3|	rv = key->ops->decrypt(operation->session, key, &operation->mechanism,
 1566|      3|			NULL, 0, pData ? pData + ulDataLen : NULL,
  ------------------
  |  Branch (1566:13): [True: 3, False: 0]
  ------------------
 1567|      3|			&ulLastDataLen);
 1568|      3|	if (pulDataLen)
  ------------------
  |  Branch (1568:6): [True: 3, False: 0]
  ------------------
 1569|      3|		*pulDataLen = ulDataLen + ulLastDataLen;
 1570|      3|	return rv;
 1571|      5|}

strcpy_bp:
   46|   107k|{
   47|   107k|	if (!dst || !dstsize)
  ------------------
  |  Branch (47:6): [True: 0, False: 107k]
  |  Branch (47:14): [True: 0, False: 107k]
  ------------------
   48|      0|		return;
   49|       |
   50|   107k|	memset((char *)dst, ' ', dstsize);
   51|       |
   52|   107k|	if (src) {
  ------------------
  |  Branch (52:6): [True: 60.1k, False: 47.6k]
  ------------------
   53|  60.1k|		size_t src_len = strlen(src);
   54|       |
   55|  60.1k|		if (src_len > dstsize) {
  ------------------
  |  Branch (55:7): [True: 1, False: 60.1k]
  ------------------
   56|       |			/* string will be truncated */
   57|      1|			memcpy((char *)dst, src, dstsize);
   58|      1|			if (dstsize > 3) {
  ------------------
  |  Branch (58:8): [True: 1, False: 0]
  ------------------
   59|       |				/* show truncation with '...' */
   60|       |				/* FIXME avoid breaking an UTF-8 character on multiple bytes */
   61|      1|				memset((char *)dst + dstsize - 3, '.', 3);
   62|      1|			}
   63|  60.1k|		} else {
   64|  60.1k|			memcpy((char *)dst, src, src_len);
   65|  60.1k|		}
   66|  60.1k|	}
   67|   107k|}
sc_to_cryptoki_error:
  127|  33.1k|{
  128|  33.1k|	if (ctx)   {
  ------------------
  |  Branch (128:6): [True: 9.83k, False: 23.3k]
  ------------------
  129|  9.83k|		int ii;
  130|       |
  131|  39.3k|		for (ii = 0; sc_to_cryptoki_error_map[ii].context; ii++) {
  ------------------
  |  Branch (131:16): [True: 29.5k, False: 9.83k]
  ------------------
  132|  29.5k|			if (sc_to_cryptoki_error_map[ii].sc_error != rc)
  ------------------
  |  Branch (132:8): [True: 29.3k, False: 204]
  ------------------
  133|  29.3k|				continue;
  134|    204|			if (strcmp(sc_to_cryptoki_error_map[ii].context, ctx))
  ------------------
  |  Branch (134:8): [True: 203, False: 1]
  ------------------
  135|    203|				continue;
  136|      1|			return sc_to_cryptoki_error_map[ii].ck_error;
  137|    204|		}
  138|  9.83k|	}
  139|  33.1k|	return sc_to_cryptoki_error_common(rc);
  140|  33.1k|}
restore_login_state:
  150|  3.49k|{
  151|  3.49k|	CK_RV r = CKR_OK;
  ------------------
  |  | 1086|  3.49k|#define CKR_OK 0x00000000UL
  ------------------
  152|       |
  153|  3.49k|	if (sc_pkcs11_conf.atomic && slot) {
  ------------------
  |  Branch (153:6): [True: 0, False: 3.49k]
  |  Branch (153:31): [True: 0, False: 0]
  ------------------
  154|      0|		if (list_iterator_start(&slot->logins)) {
  ------------------
  |  Branch (154:7): [True: 0, False: 0]
  ------------------
  155|      0|			struct sc_pkcs11_login *login = list_iterator_next(&slot->logins);
  156|      0|			while (login && slot->p11card && slot->p11card->framework) {
  ------------------
  |  Branch (156:11): [True: 0, False: 0]
  |  Branch (156:20): [True: 0, False: 0]
  |  Branch (156:37): [True: 0, False: 0]
  ------------------
  157|      0|				r = slot->p11card->framework->login(slot, login->userType,
  158|      0|						login->pPin, login->ulPinLen);
  159|      0|				if (r != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (159:9): [True: 0, False: 0]
  ------------------
  160|      0|					break;
  161|      0|				login = list_iterator_next(&slot->logins);
  162|      0|			}
  163|      0|			list_iterator_stop(&slot->logins);
  164|      0|		}
  165|      0|	}
  166|       |
  167|  3.49k|	return r;
  168|  3.49k|}
reset_login_state:
  171|  3.49k|{
  172|  3.49k|	if (slot) {
  ------------------
  |  Branch (172:6): [True: 3.49k, False: 0]
  ------------------
  173|  3.49k|		if (sc_pkcs11_conf.atomic
  ------------------
  |  Branch (173:7): [True: 0, False: 3.49k]
  ------------------
  174|      0|				&& slot->p11card && slot->p11card->framework) {
  ------------------
  |  Branch (174:8): [True: 0, False: 0]
  |  Branch (174:25): [True: 0, False: 0]
  ------------------
  175|      0|			slot->p11card->framework->logout(slot);
  176|      0|		}
  177|       |
  178|  3.49k|		if (constant_time_eq_s(rv, CKR_USER_NOT_LOGGED_IN)) {
  ------------------
  |  | 1151|  3.49k|#define CKR_USER_NOT_LOGGED_IN 0x00000101UL
  ------------------
  |  Branch (178:7): [True: 8, False: 3.48k]
  ------------------
  179|      8|			slot->login_user = -1;
  180|      8|			pop_all_login_states(slot);
  181|      8|		}
  182|  3.49k|	}
  183|       |
  184|  3.49k|	return rv;
  185|  3.49k|}
push_login_state:
  189|    865|{
  190|    865|	CK_RV r = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|    865|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  191|    865|	struct sc_pkcs11_login *login = NULL;
  192|       |
  193|    865|	if (!sc_pkcs11_conf.atomic || !slot) {
  ------------------
  |  Branch (193:6): [True: 865, False: 0]
  |  Branch (193:32): [True: 0, False: 0]
  ------------------
  194|    865|		return CKR_OK;
  ------------------
  |  | 1086|    865|#define CKR_OK 0x00000000UL
  ------------------
  195|    865|	}
  196|       |
  197|      0|	login = (struct sc_pkcs11_login *) calloc(1, sizeof *login);
  198|      0|	if (login == NULL) {
  ------------------
  |  Branch (198:6): [True: 0, False: 0]
  ------------------
  199|      0|		goto err;
  200|      0|	}
  201|       |
  202|      0|	if (pPin && ulPinLen) {
  ------------------
  |  Branch (202:6): [True: 0, False: 0]
  |  Branch (202:14): [True: 0, False: 0]
  ------------------
  203|      0|		login->pPin = sc_mem_secure_alloc((sizeof *pPin)*ulPinLen);
  204|      0|		if (login->pPin == NULL) {
  ------------------
  |  Branch (204:7): [True: 0, False: 0]
  ------------------
  205|      0|			goto err;
  206|      0|		}
  207|      0|		memcpy(login->pPin, pPin, (sizeof *pPin)*ulPinLen);
  208|      0|		login->ulPinLen = ulPinLen;
  209|      0|	}
  210|      0|	login->userType = userType;
  211|       |
  212|      0|	if (0 > list_append(&slot->logins, login)) {
  ------------------
  |  Branch (212:6): [True: 0, False: 0]
  ------------------
  213|      0|		goto err;
  214|      0|	}
  215|       |
  216|      0|	login = NULL;
  217|      0|	r = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  218|       |
  219|      0|err:
  220|      0|	if (login) {
  ------------------
  |  Branch (220:6): [True: 0, False: 0]
  ------------------
  221|      0|		if (login->pPin) {
  ------------------
  |  Branch (221:7): [True: 0, False: 0]
  ------------------
  222|      0|			sc_mem_secure_clear_free(login->pPin, login->ulPinLen);
  ------------------
  |  | 1580|      0|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|      0|	sc_mem_clear(ptr, len); \
  |  | 1582|      0|	sc_mem_secure_free(ptr, len); \
  |  | 1583|      0|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
  223|      0|		}
  224|      0|		free(login);
  225|      0|	}
  226|       |
  227|      0|	return r;
  228|      0|}
pop_all_login_states:
  247|  15.7k|{
  248|  15.7k|	if (sc_pkcs11_conf.atomic && slot) {
  ------------------
  |  Branch (248:6): [True: 0, False: 15.7k]
  |  Branch (248:31): [True: 0, False: 0]
  ------------------
  249|      0|		struct sc_pkcs11_login *login = list_fetch(&slot->logins);
  250|      0|		while (login) {
  ------------------
  |  Branch (250:10): [True: 0, False: 0]
  ------------------
  251|      0|			sc_mem_secure_clear_free(login->pPin, login->ulPinLen);
  ------------------
  |  | 1580|      0|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|      0|	sc_mem_clear(ptr, len); \
  |  | 1582|      0|	sc_mem_secure_free(ptr, len); \
  |  | 1583|      0|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
  252|      0|			free(login);
  253|      0|			login = list_fetch(&slot->logins);
  254|      0|		}
  255|      0|	}
  256|  15.7k|}
session_start_operation:
  262|  1.96k|{
  263|  1.96k|	sc_pkcs11_operation_t *op;
  264|       |
  265|  1.96k|	if (context == NULL)
  ------------------
  |  Branch (265:6): [True: 0, False: 1.96k]
  ------------------
  266|      0|		return CKR_CRYPTOKI_NOT_INITIALIZED;
  ------------------
  |  | 1169|      0|#define CKR_CRYPTOKI_NOT_INITIALIZED 0x00000190UL
  ------------------
  267|       |
  268|  1.96k|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|  1.96k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.96k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.96k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.96k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.96k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  1.96k|	sc_log(context, "Session 0x%lx, type %d", session->handle, type);
  ------------------
  |  |   71|  1.96k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  270|  1.96k|	if (type < 0 || type >= SC_PKCS11_OPERATION_MAX)
  ------------------
  |  Branch (270:6): [True: 0, False: 1.96k]
  |  Branch (270:18): [True: 0, False: 1.96k]
  ------------------
  271|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  272|       |
  273|  1.96k|	if (session->operation[type] != NULL)
  ------------------
  |  Branch (273:6): [True: 0, False: 1.96k]
  ------------------
  274|      0|		return CKR_OPERATION_ACTIVE;
  ------------------
  |  | 1125|      0|#define CKR_OPERATION_ACTIVE 0x00000090UL
  ------------------
  275|       |
  276|  1.96k|	if (!(op = sc_pkcs11_new_operation(session, mech)))
  ------------------
  |  Branch (276:6): [True: 0, False: 1.96k]
  ------------------
  277|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  278|       |
  279|  1.96k|	session->operation[type] = op;
  280|  1.96k|	if (operation)
  ------------------
  |  Branch (280:6): [True: 1.96k, False: 0]
  ------------------
  281|  1.96k|		*operation = op;
  282|       |
  283|  1.96k|	return CKR_OK;
  ------------------
  |  | 1086|  1.96k|#define CKR_OK 0x00000000UL
  ------------------
  284|  1.96k|}
session_get_operation:
  287|  4.07k|{
  288|  4.07k|	sc_pkcs11_operation_t *op;
  289|       |
  290|  4.07k|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|  4.07k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.07k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.07k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.07k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|  4.07k|	if (type < 0 || type >= SC_PKCS11_OPERATION_MAX)
  ------------------
  |  Branch (292:6): [True: 0, False: 4.07k]
  |  Branch (292:18): [True: 0, False: 4.07k]
  ------------------
  293|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  294|       |
  295|  4.07k|	if (!(op = session->operation[type]))
  ------------------
  |  Branch (295:6): [True: 0, False: 4.07k]
  ------------------
  296|      0|		return CKR_OPERATION_NOT_INITIALIZED;
  ------------------
  |  | 1126|      0|#define CKR_OPERATION_NOT_INITIALIZED 0x00000091UL
  ------------------
  297|       |
  298|  4.07k|	if (operation)
  ------------------
  |  Branch (298:6): [True: 2.59k, False: 1.47k]
  ------------------
  299|  2.59k|		*operation = op;
  300|       |
  301|  4.07k|	return CKR_OK;
  ------------------
  |  | 1086|  4.07k|#define CKR_OK 0x00000000UL
  ------------------
  302|  4.07k|}
session_stop_operation:
  305|  1.96k|{
  306|  1.96k|	if (type < 0 || type >= SC_PKCS11_OPERATION_MAX)
  ------------------
  |  Branch (306:6): [True: 0, False: 1.96k]
  |  Branch (306:18): [True: 0, False: 1.96k]
  ------------------
  307|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  308|       |
  309|  1.96k|	if (session->operation[type] == NULL)
  ------------------
  |  Branch (309:6): [True: 0, False: 1.96k]
  ------------------
  310|      0|		return CKR_OPERATION_NOT_INITIALIZED;
  ------------------
  |  | 1126|      0|#define CKR_OPERATION_NOT_INITIALIZED 0x00000091UL
  ------------------
  311|       |
  312|  1.96k|	sc_pkcs11_release_operation(&session->operation[type]);
  313|  1.96k|	return CKR_OK;
  ------------------
  |  | 1086|  1.96k|#define CKR_OK 0x00000000UL
  ------------------
  314|  1.96k|}
attr_extract:
  317|    706|{
  318|    706|	size_t size;
  319|       |
  320|    706|	if (sizep) {
  ------------------
  |  Branch (320:6): [True: 4, False: 702]
  ------------------
  321|      4|		size = *sizep;
  322|      4|		if (size < pAttr->ulValueLen)
  ------------------
  |  Branch (322:7): [True: 0, False: 4]
  ------------------
  323|      0|			return CKR_ATTRIBUTE_VALUE_INVALID;
  ------------------
  |  | 1099|      0|#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013UL
  ------------------
  324|      4|		*sizep = pAttr->ulValueLen;
  325|    702|	} else {
  326|    702|		switch (pAttr->type) {
  327|    151|		case CKA_CLASS:
  ------------------
  |  |  137|    151|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (327:3): [True: 151, False: 551]
  ------------------
  328|    151|			size = sizeof(CK_OBJECT_CLASS);
  329|    151|			break;
  330|     15|		case CKA_KEY_TYPE:
  ------------------
  |  |  159|     15|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (330:3): [True: 15, False: 687]
  ------------------
  331|     15|			size = sizeof(CK_KEY_TYPE);
  332|     15|			break;
  333|     39|		case CKA_PRIVATE:
  ------------------
  |  |  139|     39|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (333:3): [True: 39, False: 663]
  ------------------
  334|    533|		case CKA_TOKEN:
  ------------------
  |  |  138|    533|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (334:3): [True: 494, False: 208]
  ------------------
  335|    533|			size = sizeof(CK_BBOOL);
  336|    533|			break;
  337|      3|		case CKA_CERTIFICATE_TYPE:
  ------------------
  |  |  145|      3|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (337:3): [True: 3, False: 699]
  ------------------
  338|      3|			size = sizeof(CK_CERTIFICATE_TYPE);
  339|      3|			break;
  340|      0|		case CKA_VALUE_LEN:
  ------------------
  |  |  191|      0|#define CKA_VALUE_LEN 0x00000161UL
  ------------------
  |  Branch (340:3): [True: 0, False: 702]
  ------------------
  341|      0|		case CKA_MODULUS_BITS:
  ------------------
  |  |  175|      0|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
  |  Branch (341:3): [True: 0, False: 702]
  ------------------
  342|      0|			size = sizeof(CK_ULONG);
  343|      0|			break;
  344|      0|		case CKA_OBJECT_ID:
  ------------------
  |  |  144|      0|#define CKA_OBJECT_ID 0x00000012UL
  ------------------
  |  Branch (344:3): [True: 0, False: 702]
  ------------------
  345|      0|			size = sizeof(struct sc_object_id);
  346|      0|			break;
  347|      0|		default:
  ------------------
  |  Branch (347:3): [True: 0, False: 702]
  ------------------
  348|      0|			return CKR_FUNCTION_FAILED;
  ------------------
  |  | 1091|      0|#define CKR_FUNCTION_FAILED 0x00000006UL
  ------------------
  349|    702|		}
  350|    702|		if (size != pAttr->ulValueLen)
  ------------------
  |  Branch (350:7): [True: 0, False: 702]
  ------------------
  351|      0|			return CKR_ATTRIBUTE_VALUE_INVALID;
  ------------------
  |  | 1099|      0|#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013UL
  ------------------
  352|    702|	}
  353|    706|	memcpy(ptr, pAttr->pValue, pAttr->ulValueLen);
  354|    706|	return CKR_OK;
  ------------------
  |  | 1086|    706|#define CKR_OK 0x00000000UL
  ------------------
  355|    706|}
attr_find:
  358|    664|{
  359|    664|	unsigned int n;
  360|       |
  361|  1.70k|	for (n = 0; n < ulCount; n++, pTemplate++) {
  ------------------
  |  Branch (361:14): [True: 1.70k, False: 1]
  ------------------
  362|  1.70k|		if (pTemplate->type == type)
  ------------------
  |  Branch (362:7): [True: 663, False: 1.03k]
  ------------------
  363|    663|			break;
  364|  1.70k|	}
  365|       |
  366|    664|	if (n >= ulCount)
  ------------------
  |  Branch (366:6): [True: 1, False: 663]
  ------------------
  367|      1|		return CKR_TEMPLATE_INCOMPLETE;
  ------------------
  |  | 1142|      1|#define CKR_TEMPLATE_INCOMPLETE 0x000000D0UL
  ------------------
  368|    663|	return attr_extract(pTemplate, ptr, sizep);
  369|    664|}
load_pkcs11_parameters:
  478|  15.7k|{
  479|  15.7k|	scconf_block *conf_block = NULL;
  480|  15.7k|	char *unblock_style = NULL;
  481|  15.7k|	char *create_slots_for_pins = NULL, *op, *tmp;
  482|       |
  483|       |	/* Set defaults */
  484|  15.7k|	conf->max_virtual_slots = 16;
  485|  15.7k|	if (is_nss_browser(ctx)) {
  ------------------
  |  Branch (485:6): [True: 0, False: 15.7k]
  ------------------
  486|       |		/* NSS verifies *every* PIN even though only a single one would be
  487|       |		 * needed to use one specific key. In known NSS browsers, we set
  488|       |		 * slots_per_card to `1` to only look at the authentication PIN, i.e.
  489|       |		 * ignoring a potential signature PIN. */
  490|      0|		conf->slots_per_card = 1;
  491|  15.7k|	} else {
  492|  15.7k|		conf->slots_per_card = 4;
  493|  15.7k|	}
  494|  15.7k|	conf->atomic = 0;
  495|  15.7k|	conf->lock_login = 0;
  496|  15.7k|	conf->init_sloppy = 1;
  497|  15.7k|	conf->pin_unblock_style = SC_PKCS11_PIN_UNBLOCK_NOT_ALLOWED;
  ------------------
  |  |   39|  15.7k|#define SC_PKCS11_PIN_UNBLOCK_NOT_ALLOWED	0
  ------------------
  498|  15.7k|	conf->create_puk_slot = 0;
  499|  15.7k|	conf->create_slots_flags = SC_PKCS11_SLOT_CREATE_ALL;
  ------------------
  |  |   46|  15.7k|#define SC_PKCS11_SLOT_CREATE_ALL	8
  ------------------
  500|       |
  501|  15.7k|	conf_block = sc_get_conf_block(ctx, "pkcs11", NULL, 1);
  502|  15.7k|	if (!conf_block)
  ------------------
  |  Branch (502:6): [True: 15.7k, False: 0]
  ------------------
  503|  15.7k|		goto out;
  504|       |
  505|       |	/* contains the defaults, if there is a "pkcs11" config block */
  506|      0|	conf->max_virtual_slots = scconf_get_int(conf_block, "max_virtual_slots", conf->max_virtual_slots);
  507|      0|	conf->slots_per_card = scconf_get_int(conf_block, "slots_per_card", conf->slots_per_card);
  508|      0|	conf->atomic = scconf_get_bool(conf_block, "atomic", conf->atomic);
  509|      0|	if (conf->atomic)
  ------------------
  |  Branch (509:6): [True: 0, False: 0]
  ------------------
  510|      0|		conf->lock_login = 1;
  511|      0|	conf->lock_login = scconf_get_bool(conf_block, "lock_login", conf->lock_login);
  512|      0|	conf->init_sloppy = scconf_get_bool(conf_block, "init_sloppy", conf->init_sloppy);
  513|       |
  514|      0|	unblock_style = (char *)scconf_get_str(conf_block, "user_pin_unblock_style", NULL);
  515|      0|	if (unblock_style && !strcmp(unblock_style, "set_pin_in_unlogged_session"))
  ------------------
  |  Branch (515:6): [True: 0, False: 0]
  |  Branch (515:23): [True: 0, False: 0]
  ------------------
  516|      0|		conf->pin_unblock_style = SC_PKCS11_PIN_UNBLOCK_UNLOGGED_SETPIN;
  ------------------
  |  |   40|      0|#define SC_PKCS11_PIN_UNBLOCK_UNLOGGED_SETPIN	1
  ------------------
  517|      0|	else if (unblock_style && !strcmp(unblock_style, "set_pin_in_specific_context"))
  ------------------
  |  Branch (517:11): [True: 0, False: 0]
  |  Branch (517:28): [True: 0, False: 0]
  ------------------
  518|      0|		conf->pin_unblock_style = SC_PKCS11_PIN_UNBLOCK_SCONTEXT_SETPIN;
  ------------------
  |  |   41|      0|#define SC_PKCS11_PIN_UNBLOCK_SCONTEXT_SETPIN	2
  ------------------
  519|      0|	else if (unblock_style && !strcmp(unblock_style, "init_pin_in_so_session"))
  ------------------
  |  Branch (519:11): [True: 0, False: 0]
  |  Branch (519:28): [True: 0, False: 0]
  ------------------
  520|      0|		conf->pin_unblock_style = SC_PKCS11_PIN_UNBLOCK_SO_LOGGED_INITPIN;
  ------------------
  |  |   42|      0|#define SC_PKCS11_PIN_UNBLOCK_SO_LOGGED_INITPIN	3
  ------------------
  521|       |
  522|      0|	conf->create_puk_slot = scconf_get_bool(conf_block, "create_puk_slot", conf->create_puk_slot);
  523|       |
  524|      0|	create_slots_for_pins = (char *)scconf_get_str(conf_block, "create_slots_for_pins", "all");
  525|      0|	conf->create_slots_flags = 0;
  526|      0|	tmp = strdup(create_slots_for_pins);
  527|      0|	op = strtok(tmp, " ,");
  528|      0|	while (op) {
  ------------------
  |  Branch (528:9): [True: 0, False: 0]
  ------------------
  529|      0|		if (!strcmp(op, "user"))
  ------------------
  |  Branch (529:7): [True: 0, False: 0]
  ------------------
  530|      0|			conf->create_slots_flags |= SC_PKCS11_SLOT_FOR_PIN_USER;
  ------------------
  |  |   44|      0|#define SC_PKCS11_SLOT_FOR_PIN_USER	1
  ------------------
  531|      0|		else if (!strcmp(op, "sign"))
  ------------------
  |  Branch (531:12): [True: 0, False: 0]
  ------------------
  532|      0|			conf->create_slots_flags |= SC_PKCS11_SLOT_FOR_PIN_SIGN;
  ------------------
  |  |   45|      0|#define SC_PKCS11_SLOT_FOR_PIN_SIGN	2
  ------------------
  533|      0|		else if (!strcmp(op, "all"))
  ------------------
  |  Branch (533:12): [True: 0, False: 0]
  ------------------
  534|      0|			conf->create_slots_flags |= SC_PKCS11_SLOT_CREATE_ALL;
  ------------------
  |  |   46|      0|#define SC_PKCS11_SLOT_CREATE_ALL	8
  ------------------
  535|      0|		op = strtok(NULL, " ,");
  536|      0|	}
  537|      0|	free(tmp);
  538|       |
  539|  15.7k|out:
  540|  15.7k|	sc_log(ctx, "PKCS#11 options: max_virtual_slots=%d slots_per_card=%d "
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  541|  15.7k|		 "lock_login=%d atomic=%d pin_unblock_style=%d "
  542|  15.7k|		 "create_slots_flags=0x%X",
  543|  15.7k|		 conf->max_virtual_slots, conf->slots_per_card,
  544|  15.7k|		 conf->lock_login, conf->atomic, conf->pin_unblock_style,
  545|  15.7k|		 conf->create_slots_flags);
  546|  15.7k|}
misc.c:sc_to_cryptoki_error_common:
   71|  33.1k|{
   72|  33.1k|	sc_log(context, "libopensc return value: %d (%s)\n", rc, sc_strerror(rc));
  ------------------
  |  |   71|  33.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__
  |  |  ------------------
  ------------------
   73|  33.1k|	switch (rc) {
  ------------------
  |  Branch (73:10): [True: 28.4k, False: 4.73k]
  ------------------
   74|  14.3k|	case SC_SUCCESS:
  ------------------
  |  |   28|  14.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:2): [True: 14.3k, False: 18.7k]
  ------------------
   75|  14.3k|		return CKR_OK;
  ------------------
  |  | 1086|  14.3k|#define CKR_OK 0x00000000UL
  ------------------
   76|  1.31k|	case SC_ERROR_NOT_SUPPORTED:
  ------------------
  |  |   89|  1.31k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (76:2): [True: 1.31k, False: 31.8k]
  ------------------
   77|  1.31k|		return CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|  1.31k|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
   78|      0|	case SC_ERROR_OUT_OF_MEMORY:
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  |  Branch (78:2): [True: 0, False: 33.1k]
  ------------------
   79|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
   80|     12|	case SC_ERROR_PIN_CODE_INCORRECT:
  ------------------
  |  |   64|     12|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (80:2): [True: 12, False: 33.1k]
  ------------------
   81|     12|		return CKR_PIN_INCORRECT;
  ------------------
  |  | 1127|     12|#define CKR_PIN_INCORRECT 0x000000A0UL
  ------------------
   82|      2|	case SC_ERROR_AUTH_METHOD_BLOCKED:
  ------------------
  |  |   62|      2|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (82:2): [True: 2, False: 33.1k]
  ------------------
   83|      2|		return CKR_PIN_LOCKED;
  ------------------
  |  | 1131|      2|#define CKR_PIN_LOCKED 0x000000A4UL
  ------------------
   84|      1|	case SC_ERROR_BUFFER_TOO_SMALL:
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  |  Branch (84:2): [True: 1, False: 33.1k]
  ------------------
   85|      1|		return CKR_BUFFER_TOO_SMALL;
  ------------------
  |  | 1165|      1|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
   86|      0|	case SC_ERROR_CARD_NOT_PRESENT:
  ------------------
  |  |   35|      0|#define SC_ERROR_CARD_NOT_PRESENT		-1104
  ------------------
  |  Branch (86:2): [True: 0, False: 33.1k]
  ------------------
   87|      0|		return CKR_TOKEN_NOT_PRESENT;
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
   88|  4.91k|	case SC_ERROR_INVALID_CARD:
  ------------------
  |  |   60|  4.91k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (88:2): [True: 4.91k, False: 28.2k]
  ------------------
   89|  12.1k|	case SC_ERROR_WRONG_CARD:
  ------------------
  |  |   94|  12.1k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (89:2): [True: 7.22k, False: 25.9k]
  ------------------
   90|  12.1k|	case SC_ERROR_NO_CARD_SUPPORT:
  ------------------
  |  |   58|  12.1k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  |  Branch (90:2): [True: 6, False: 33.1k]
  ------------------
   91|  12.1k|		return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|  12.1k|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
   92|     47|	case SC_ERROR_WRONG_LENGTH:
  ------------------
  |  |   56|     47|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (92:2): [True: 47, False: 33.1k]
  ------------------
   93|     47|		return CKR_DATA_LEN_RANGE;
  ------------------
  |  | 1102|     47|#define CKR_DATA_LEN_RANGE 0x00000021UL
  ------------------
   94|    190|	case SC_ERROR_INVALID_PIN_LENGTH:
  ------------------
  |  |   77|    190|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  |  Branch (94:2): [True: 190, False: 32.9k]
  ------------------
   95|    190|		return CKR_PIN_LEN_RANGE;
  ------------------
  |  | 1129|    190|#define CKR_PIN_LEN_RANGE 0x000000A2UL
  ------------------
   96|      0|	case SC_ERROR_KEYPAD_CANCELLED:
  ------------------
  |  |   40|      0|#define SC_ERROR_KEYPAD_CANCELLED		-1109
  ------------------
  |  Branch (96:2): [True: 0, False: 33.1k]
  ------------------
   97|      0|	case SC_ERROR_KEYPAD_TIMEOUT:
  ------------------
  |  |   39|      0|#define SC_ERROR_KEYPAD_TIMEOUT			-1108
  ------------------
  |  Branch (97:2): [True: 0, False: 33.1k]
  ------------------
   98|      0|		return CKR_FUNCTION_CANCELED;
  ------------------
  |  | 1109|      0|#define CKR_FUNCTION_CANCELED 0x00000050UL
  ------------------
   99|      0|	case SC_ERROR_CARD_REMOVED:
  ------------------
  |  |   36|      0|#define SC_ERROR_CARD_REMOVED			-1105
  ------------------
  |  Branch (99:2): [True: 0, False: 33.1k]
  ------------------
  100|      0|		return CKR_DEVICE_REMOVED;
  ------------------
  |  | 1105|      0|#define CKR_DEVICE_REMOVED 0x00000032UL
  ------------------
  101|     17|	case SC_ERROR_SECURITY_STATUS_NOT_SATISFIED:
  ------------------
  |  |   61|     17|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (101:2): [True: 17, False: 33.1k]
  ------------------
  102|     17|		return CKR_USER_NOT_LOGGED_IN;
  ------------------
  |  | 1151|     17|#define CKR_USER_NOT_LOGGED_IN 0x00000101UL
  ------------------
  103|      0|	case SC_ERROR_KEYPAD_PIN_MISMATCH:
  ------------------
  |  |   41|      0|#define SC_ERROR_KEYPAD_PIN_MISMATCH		-1110
  ------------------
  |  Branch (103:2): [True: 0, False: 33.1k]
  ------------------
  104|      0|		return CKR_PIN_INVALID;
  ------------------
  |  | 1128|      0|#define CKR_PIN_INVALID 0x000000A1UL
  ------------------
  105|     87|	case SC_ERROR_INVALID_ARGUMENTS:
  ------------------
  |  |   73|     87|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  |  Branch (105:2): [True: 87, False: 33.0k]
  ------------------
  106|     87|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|     87|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  107|    100|	case SC_ERROR_INVALID_DATA:
  ------------------
  |  |   78|    100|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  |  Branch (107:2): [True: 100, False: 33.0k]
  ------------------
  108|    117|	case SC_ERROR_INCORRECT_PARAMETERS:
  ------------------
  |  |   55|    117|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (108:2): [True: 17, False: 33.1k]
  ------------------
  109|    117|		return CKR_DATA_INVALID;
  ------------------
  |  | 1101|    117|#define CKR_DATA_INVALID 0x00000020UL
  ------------------
  110|      0|	case SC_ERROR_CARD_UNRESPONSIVE:
  ------------------
  |  |   44|      0|#define SC_ERROR_CARD_UNRESPONSIVE		-1113
  ------------------
  |  Branch (110:2): [True: 0, False: 33.1k]
  ------------------
  111|      0|	case SC_ERROR_READER_LOCKED:
  ------------------
  |  |   47|      0|#define SC_ERROR_READER_LOCKED			-1116
  ------------------
  |  Branch (111:2): [True: 0, False: 33.1k]
  ------------------
  112|      0|		return CKR_DEVICE_ERROR;
  ------------------
  |  | 1103|      0|#define CKR_DEVICE_ERROR 0x00000030UL
  ------------------
  113|      0|	case SC_ERROR_READER_DETACHED:
  ------------------
  |  |   45|      0|#define SC_ERROR_READER_DETACHED		-1114
  ------------------
  |  Branch (113:2): [True: 0, False: 33.1k]
  ------------------
  114|      0|		return CKR_TOKEN_NOT_PRESENT;	/* Maybe CKR_DEVICE_REMOVED ? */
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
  115|     17|	case SC_ERROR_NOT_ENOUGH_MEMORY:
  ------------------
  |  |   67|     17|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  |  Branch (115:2): [True: 17, False: 33.1k]
  ------------------
  116|     17|		return CKR_DEVICE_MEMORY;
  ------------------
  |  | 1104|     17|#define CKR_DEVICE_MEMORY 0x00000031UL
  ------------------
  117|      1|	case SC_ERROR_MEMORY_FAILURE:	/* EEPROM has failed */
  ------------------
  |  |   57|      1|#define SC_ERROR_MEMORY_FAILURE			-1207
  ------------------
  |  Branch (117:2): [True: 1, False: 33.1k]
  ------------------
  118|      1|		return CKR_DEVICE_ERROR;
  ------------------
  |  | 1103|      1|#define CKR_DEVICE_ERROR 0x00000030UL
  ------------------
  119|     67|	case SC_ERROR_WRONG_PADDING:
  ------------------
  |  |   93|     67|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
  |  Branch (119:2): [True: 67, False: 33.0k]
  ------------------
  120|     67|		return CKR_ENCRYPTED_DATA_INVALID;
  ------------------
  |  | 1106|     67|#define CKR_ENCRYPTED_DATA_INVALID 0x00000040UL
  ------------------
  121|  33.1k|	}
  122|  4.73k|	return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|  4.73k|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  123|  33.1k|}
misc.c:is_nss_browser:
  453|  15.7k|{
  454|  15.7k|	const char *basename;
  455|       |#ifdef _WIN32
  456|       |	const char sep = '\\';
  457|       |#else
  458|  15.7k|	const char sep = '/';
  459|  15.7k|#endif
  460|  15.7k|	if (!ctx || !ctx->exe_path)
  ------------------
  |  Branch (460:6): [True: 0, False: 15.7k]
  |  Branch (460:14): [True: 0, False: 15.7k]
  ------------------
  461|      0|		return 0;
  462|       |
  463|  15.7k|	basename = strrchr(ctx->exe_path, sep);
  464|  15.7k|	if (!basename)
  ------------------
  |  Branch (464:6): [True: 0, False: 15.7k]
  ------------------
  465|      0|		basename = ctx->exe_path;
  466|  15.7k|	else
  467|       |		/* discard the separator */
  468|  15.7k|		basename += sizeof(char);
  469|       |
  470|  15.7k|	if (strstr(basename, "chromium") || strstr(basename, "chrome")
  ------------------
  |  Branch (470:6): [True: 0, False: 15.7k]
  |  Branch (470:38): [True: 0, False: 15.7k]
  ------------------
  471|  15.7k|			|| strstr(basename, "firefox") || strstr(basename, "msedge"))
  ------------------
  |  Branch (471:7): [True: 0, False: 15.7k]
  |  Branch (471:38): [True: 0, False: 15.7k]
  ------------------
  472|      0|		return 1;
  473|       |
  474|  15.7k|	return 0;
  475|  15.7k|}

sc_pkcs11_register_openssl_mechanisms:
  256|  5.21k|{
  257|  5.21k|	sc_pkcs11_mechanism_type_t *mt = NULL;
  258|       |/*
  259|       | * Engine support is being deprecated in 3.0. OpenSC loads GOST as engine.
  260|       | * When GOST developers convert to provider, we can load the provider
  261|       | */
  262|  5.21k|#if !defined(OPENSSL_NO_ENGINE)
  263|  5.21k|	ENGINE *e;
  264|       |/* crypto locking removed in 1.1 */
  265|       |#if OPENSSL_VERSION_NUMBER  < 0x10100000L
  266|       |	void (*locking_cb)(int, int, const char *, int);
  267|       |
  268|       |	locking_cb = CRYPTO_get_locking_callback();
  269|       |	if (locking_cb)
  270|       |		CRYPTO_set_locking_callback(NULL);
  271|       |#endif
  272|       |
  273|  5.21k|	e = ENGINE_by_id("gost");
  274|  5.21k|	if (!e)
  ------------------
  |  Branch (274:6): [True: 5.21k, False: 0]
  ------------------
  275|  5.21k|	{
  276|       |#if !defined(OPENSSL_NO_STATIC_ENGINE) && !defined(OPENSSL_NO_GOST) && !defined(LIBRESSL_VERSION_NUMBER)
  277|       |
  278|       |/* ENGINE_load_gost removed in 1.1 */
  279|       |#if OPENSSL_VERSION_NUMBER  < 0x10100000L
  280|       |		ENGINE_load_gost();
  281|       |#endif
  282|       |		e = ENGINE_by_id("gost");
  283|       |#else
  284|       |		/* try to load dynamic gost engine */
  285|  5.21k|		e = ENGINE_by_id("dynamic");
  286|  5.21k|		if (!e) {
  ------------------
  |  Branch (286:7): [True: 1, False: 5.21k]
  ------------------
  287|      1|			ENGINE_load_dynamic();
  288|      1|			e = ENGINE_by_id("dynamic");
  289|      1|		}
  290|  5.21k|		if (e && (!ENGINE_ctrl_cmd_string(e, "SO_PATH", "gost", 0) ||
  ------------------
  |  Branch (290:7): [True: 5.21k, False: 0]
  |  Branch (290:13): [True: 0, False: 5.21k]
  ------------------
  291|  5.21k|					!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))) {
  ------------------
  |  Branch (291:6): [True: 5.21k, False: 0]
  ------------------
  292|  5.21k|			ENGINE_free(e);
  293|  5.21k|			e = NULL;
  294|  5.21k|		}
  295|  5.21k|#endif /* !OPENSSL_NO_STATIC_ENGINE && !OPENSSL_NO_GOST && !LIBRESSL_VERSION_NUMBER */
  296|  5.21k|	}
  297|  5.21k|	if (e) {
  ------------------
  |  Branch (297:6): [True: 0, False: 5.21k]
  ------------------
  298|      0|		ENGINE_set_default(e, ENGINE_METHOD_ALL);
  299|      0|		ENGINE_free(e);
  300|      0|	}
  301|       |
  302|       |#if OPENSSL_VERSION_NUMBER < 0x10100000L
  303|       |	if (locking_cb)
  304|       |		CRYPTO_set_locking_callback(locking_cb);
  305|       |#endif
  306|  5.21k|#endif /* !defined(OPENSSL_NO_ENGINE) */
  307|       |
  308|  5.21k|	openssl_sha1_mech.mech_data = sc_evp_md(context, "sha1");
  309|  5.21k|	openssl_sha1_mech.free_mech_data = ossl_md_free;
  310|  5.21k|	openssl_sha1_mech.copy_mech_data = ossl_md_copy;
  311|  5.21k|	mt = dup_mem(&openssl_sha1_mech, sizeof openssl_sha1_mech);
  312|  5.21k|	sc_pkcs11_register_mechanism(p11card, mt, NULL);
  313|  5.21k|	sc_pkcs11_free_mechanism(&mt);
  314|       |
  315|  5.21k|	openssl_sha224_mech.mech_data = sc_evp_md(context, "sha224");
  316|  5.21k|	openssl_sha224_mech.free_mech_data = ossl_md_free;
  317|  5.21k|	openssl_sha224_mech.copy_mech_data = ossl_md_copy;
  318|  5.21k|	mt = dup_mem(&openssl_sha224_mech, sizeof openssl_sha224_mech);
  319|  5.21k|	sc_pkcs11_register_mechanism(p11card, mt, NULL);
  320|  5.21k|	sc_pkcs11_free_mechanism(&mt);
  321|       |
  322|  5.21k|	openssl_sha256_mech.mech_data = sc_evp_md(context, "sha256");
  323|  5.21k|	openssl_sha256_mech.free_mech_data = ossl_md_free;
  324|  5.21k|	openssl_sha256_mech.copy_mech_data = ossl_md_copy;
  325|  5.21k|	mt = dup_mem(&openssl_sha256_mech, sizeof openssl_sha256_mech);
  326|  5.21k|	sc_pkcs11_register_mechanism(p11card, mt, NULL);
  327|  5.21k|	sc_pkcs11_free_mechanism(&mt);
  328|       |
  329|  5.21k|	openssl_sha384_mech.mech_data = sc_evp_md(context, "sha384");
  330|  5.21k|	openssl_sha384_mech.free_mech_data = ossl_md_free;
  331|  5.21k|	openssl_sha384_mech.copy_mech_data = ossl_md_copy;
  332|  5.21k|	mt = dup_mem(&openssl_sha384_mech, sizeof openssl_sha384_mech);
  333|  5.21k|	sc_pkcs11_register_mechanism(p11card, mt, NULL);
  334|  5.21k|	sc_pkcs11_free_mechanism(&mt);
  335|       |
  336|  5.21k|	openssl_sha512_mech.mech_data = sc_evp_md(context, "sha512");
  337|  5.21k|	openssl_sha512_mech.free_mech_data = ossl_md_free;
  338|  5.21k|	openssl_sha512_mech.copy_mech_data = ossl_md_copy;
  339|  5.21k|	mt = dup_mem(&openssl_sha512_mech, sizeof openssl_sha512_mech);
  340|  5.21k|	sc_pkcs11_register_mechanism(p11card, mt, NULL);
  341|  5.21k|	sc_pkcs11_free_mechanism(&mt);
  342|       |
  343|  5.21k|	if (!FIPS_mode()) {
  ------------------
  |  Branch (343:6): [True: 5.21k, False: 0]
  ------------------
  344|  5.21k|		openssl_md5_mech.mech_data = sc_evp_md(context, "md5");
  345|  5.21k|		openssl_md5_mech.free_mech_data = ossl_md_free;
  346|  5.21k|		openssl_md5_mech.copy_mech_data = ossl_md_copy;
  347|  5.21k|		mt = dup_mem(&openssl_md5_mech, sizeof openssl_md5_mech);
  348|  5.21k|		sc_pkcs11_register_mechanism(p11card, mt, NULL);
  349|  5.21k|		sc_pkcs11_free_mechanism(&mt);
  350|       |
  351|  5.21k|		openssl_ripemd160_mech.mech_data = sc_evp_md(context, "ripemd160");
  352|  5.21k|		openssl_ripemd160_mech.free_mech_data = ossl_md_free;
  353|  5.21k|		openssl_ripemd160_mech.copy_mech_data = ossl_md_copy;
  354|  5.21k|		mt = dup_mem(&openssl_ripemd160_mech, sizeof openssl_ripemd160_mech);
  355|  5.21k|		sc_pkcs11_register_mechanism(p11card, mt, NULL);
  356|  5.21k|		sc_pkcs11_free_mechanism(&mt);
  357|       |
  358|  5.21k|	}
  359|  5.21k|	openssl_gostr3411_mech.mech_data = EVP_get_digestbynid(NID_id_GostR3411_94);
  360|  5.21k|	mt = dup_mem(&openssl_gostr3411_mech, sizeof openssl_gostr3411_mech);
  361|  5.21k|	sc_pkcs11_register_mechanism(p11card, mt, NULL);
  362|  5.21k|	sc_pkcs11_free_mechanism(&mt);
  363|       |
  364|  5.21k|}
sc_pkcs11_verify_data:
  616|     46|{
  617|     46|	int res;
  618|     46|	CK_RV rv = CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|     46|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  619|     46|	EVP_PKEY *pkey = NULL;
  620|     46|	const unsigned char *pubkey_tmp = NULL;
  621|     46|	int sLen;
  622|       |
  623|     46|	if (mech->mechanism == CKM_GOSTR3410)
  ------------------
  |  |  909|     46|#define CKM_GOSTR3410 0x00001201UL
  ------------------
  |  Branch (623:6): [True: 0, False: 46]
  ------------------
  624|      0|	{
  625|      0|#if !defined(OPENSSL_NO_EC)
  626|      0|		return gostr3410_verify_data(pubkey, pubkey_len,
  627|      0|				pubkey_params, pubkey_params_len,
  628|      0|				data, data_len, signat, signat_len);
  629|       |#else
  630|       |		(void)pubkey_params, (void)pubkey_params_len; /* no warning */
  631|       |		return CKR_FUNCTION_NOT_SUPPORTED;
  632|       |#endif
  633|      0|	}
  634|       |
  635|       |	/*
  636|       |	 * PKCS#11 does not define CKA_VALUE for public keys, and different cards
  637|       |	 * return either the raw or spki versions as defined in PKCS#15
  638|       |	 * And we need to support more then just RSA.
  639|       |	 * We can use d2i_PUBKEY which works for SPKI and any key type.
  640|       |	 */
  641|     46|	pubkey_tmp = pubkey; /* pass in so pubkey pointer is not modified */
  642|       |
  643|     46|	pkey = d2i_PUBKEY(NULL, &pubkey_tmp, pubkey_len);
  644|     46|	if (pkey == NULL) {
  ------------------
  |  Branch (644:6): [True: 2, False: 44]
  ------------------
  645|      2|		sc_log_openssl(context);
  ------------------
  |  |   72|      2|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  646|      2|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      2|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  647|      2|	}
  648|       |
  649|     44|	if (md != NULL && (mech->mechanism == CKM_SHA1_RSA_PKCS
  ------------------
  |  |  544|     66|#define CKM_SHA1_RSA_PKCS 0x00000006UL
  ------------------
  |  Branch (649:6): [True: 33, False: 11]
  |  Branch (649:21): [True: 1, False: 32]
  ------------------
  650|     32|		|| mech->mechanism == CKM_MD5_RSA_PKCS
  ------------------
  |  |  543|     65|#define CKM_MD5_RSA_PKCS 0x00000005UL
  ------------------
  |  Branch (650:6): [True: 1, False: 31]
  ------------------
  651|     31|		|| mech->mechanism == CKM_RIPEMD160_RSA_PKCS
  ------------------
  |  |  546|     64|#define CKM_RIPEMD160_RSA_PKCS 0x00000008UL
  ------------------
  |  Branch (651:6): [True: 2, False: 29]
  ------------------
  652|     29|		|| mech->mechanism == CKM_SHA224_RSA_PKCS
  ------------------
  |  |  604|     62|#define CKM_SHA224_RSA_PKCS 0x00000046UL
  ------------------
  |  Branch (652:6): [True: 1, False: 28]
  ------------------
  653|     28|		|| mech->mechanism == CKM_SHA256_RSA_PKCS
  ------------------
  |  |  598|     61|#define CKM_SHA256_RSA_PKCS 0x00000040UL
  ------------------
  |  Branch (653:6): [True: 1, False: 27]
  ------------------
  654|     27|		|| mech->mechanism == CKM_SHA384_RSA_PKCS
  ------------------
  |  |  599|     60|#define CKM_SHA384_RSA_PKCS 0x00000041UL
  ------------------
  |  Branch (654:6): [True: 1, False: 26]
  ------------------
  655|     26|		|| mech->mechanism == CKM_SHA512_RSA_PKCS
  ------------------
  |  |  600|     59|#define CKM_SHA512_RSA_PKCS 0x00000042UL
  ------------------
  |  Branch (655:6): [True: 1, False: 25]
  ------------------
  656|     25|		|| mech->mechanism == CKM_ECDSA_SHA1
  ------------------
  |  |  861|     58|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
  |  Branch (656:6): [True: 7, False: 18]
  ------------------
  657|     18|		|| mech->mechanism == CKM_ECDSA_SHA224
  ------------------
  |  |  862|     51|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
  |  Branch (657:6): [True: 2, False: 16]
  ------------------
  658|     16|		|| mech->mechanism == CKM_ECDSA_SHA256
  ------------------
  |  |  863|     49|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
  |  Branch (658:6): [True: 1, False: 15]
  ------------------
  659|     15|		|| mech->mechanism == CKM_ECDSA_SHA384
  ------------------
  |  |  864|     48|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
  |  Branch (659:6): [True: 8, False: 7]
  ------------------
  660|      7|		|| mech->mechanism == CKM_ECDSA_SHA512
  ------------------
  |  |  865|      7|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
  |  Branch (660:6): [True: 1, False: 6]
  ------------------
  661|     33|		)) {
  662|     27|		EVP_MD_CTX *md_ctx = DIGEST_CTX(md);
  ------------------
  |  |  371|     27|	(op ? (EVP_MD_CTX *) (op)->priv_data : NULL)
  |  |  ------------------
  |  |  |  Branch (371:3): [True: 27, False: 0]
  |  |  ------------------
  ------------------
  663|       |
  664|       |		/* This does not really use the data argument, but the data
  665|       |		 * are already collected in the md_ctx
  666|       |		 */
  667|     27|		sc_log(context, "Trying to verify using EVP");
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  668|     27|		if (md_ctx) {
  ------------------
  |  Branch (668:7): [True: 27, False: 0]
  ------------------
  669|       |
  670|     27|			if (EVP_PKEY_base_id(pkey) == EVP_PKEY_EC) {
  ------------------
  |  Branch (670:8): [True: 19, False: 8]
  ------------------
  671|     19|				unsigned char *signat_tmp = NULL;
  672|     19|				size_t signat_len_tmp;
  673|     19|				int r;
  674|     19|				r = sc_asn1_sig_value_rs_to_sequence(NULL, signat,
  675|     19|						signat_len, &signat_tmp, &signat_len_tmp);
  676|     19|				if (r == 0 && signat_len_tmp < UINT_MAX) {
  ------------------
  |  Branch (676:9): [True: 18, False: 1]
  |  Branch (676:19): [True: 18, False: 0]
  ------------------
  677|     18|					res = EVP_VerifyFinal(md_ctx, signat_tmp, (unsigned int) signat_len_tmp, pkey);
  678|     18|				} else {
  679|      1|					sc_log(context, "sc_asn1_sig_value_rs_to_sequence failed r:%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__
  |  |  ------------------
  ------------------
  680|      1|							"or output too long signat_len_tmp:%zu",
  681|      1|							r, signat_len_tmp);
  682|      1|					res = -1;
  683|      1|				}
  684|     19|				free(signat_tmp);
  685|     19|			} else
  686|      8|				res = EVP_VerifyFinal(md_ctx, signat, (unsigned int) signat_len, pkey);
  687|     27|		} else {
  688|      0|			res = -1;
  689|      0|		}
  690|     27|		EVP_PKEY_free(pkey);
  691|     27|		if (res == 1)
  ------------------
  |  Branch (691:7): [True: 0, False: 27]
  ------------------
  692|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  693|     27|		else if (res == 0) {
  ------------------
  |  Branch (693:12): [True: 26, False: 1]
  ------------------
  694|     26|			sc_log_openssl(context);
  ------------------
  |  |   72|     26|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  695|     26|			sc_log(context, "EVP_VerifyFinal(): Signature invalid");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  696|     26|			return CKR_SIGNATURE_INVALID;
  ------------------
  |  | 1140|     26|#define CKR_SIGNATURE_INVALID 0x000000C0UL
  ------------------
  697|     26|		} else {
  698|      1|			sc_log_openssl(context);
  ------------------
  |  |   72|      1|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  699|      1|			sc_log(context, "EVP_VerifyFinal() returned %d\n", res);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  700|      1|			return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      1|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  701|      1|		}
  702|     27|	} else	/* If plain CKM_ECDSA (without any hashing) is used or card supports
  703|       |		 * on-card CKM_ECDSA_SHAx only we land here. Since for CKM_ECDSA_SHAx no
  704|       |		 * hashing happened in C_VerifyUpdate() we do it here instead.
  705|       |		 */
  706|     17|		if (md == NULL && (mech->mechanism == CKM_ECDSA
  ------------------
  |  |  860|     22|#define CKM_ECDSA 0x00001041UL
  ------------------
  |  Branch (706:7): [True: 11, False: 6]
  |  Branch (706:22): [True: 4, False: 7]
  ------------------
  707|      7|		    || mech->mechanism == CKM_ECDSA_SHA1
  ------------------
  |  |  861|     18|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
  |  Branch (707:10): [True: 0, False: 7]
  ------------------
  708|      7|		    || mech->mechanism == CKM_ECDSA_SHA224
  ------------------
  |  |  862|     18|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
  |  Branch (708:10): [True: 0, False: 7]
  ------------------
  709|      7|		    || mech->mechanism == CKM_ECDSA_SHA256
  ------------------
  |  |  863|     18|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
  |  Branch (709:10): [True: 0, False: 7]
  ------------------
  710|      7|		    || mech->mechanism == CKM_ECDSA_SHA384
  ------------------
  |  |  864|     18|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
  |  Branch (710:10): [True: 0, False: 7]
  ------------------
  711|      7|		    || mech->mechanism == CKM_ECDSA_SHA512)) {
  ------------------
  |  |  865|      7|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
  |  Branch (711:10): [True: 0, False: 7]
  ------------------
  712|      4|		size_t signat_len_tmp;
  713|      4|		unsigned char *signat_tmp = NULL;
  714|      4|		unsigned int mdbuf_len;
  715|      4|		unsigned char *mdbuf = NULL;
  716|      4|		EVP_PKEY_CTX *ctx;
  717|      4|		int r;
  718|       |
  719|      4|		sc_log(context, "Trying to verify using EVP");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  720|       |
  721|       |		/* If needed, hash input first
  722|       |		 */
  723|      4|		if (mech->mechanism == CKM_ECDSA_SHA1
  ------------------
  |  |  861|      8|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
  |  Branch (723:7): [True: 0, False: 4]
  ------------------
  724|      4|		    || mech->mechanism == CKM_ECDSA_SHA224
  ------------------
  |  |  862|      8|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
  |  Branch (724:10): [True: 0, False: 4]
  ------------------
  725|      4|		    || mech->mechanism == CKM_ECDSA_SHA256
  ------------------
  |  |  863|      8|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
  |  Branch (725:10): [True: 0, False: 4]
  ------------------
  726|      4|		    || mech->mechanism == CKM_ECDSA_SHA384
  ------------------
  |  |  864|      8|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
  |  Branch (726:10): [True: 0, False: 4]
  ------------------
  727|      4|		    || mech->mechanism == CKM_ECDSA_SHA512) {
  ------------------
  |  |  865|      4|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
  |  Branch (727:10): [True: 0, False: 4]
  ------------------
  728|      0|			EVP_MD_CTX *mdctx;
  729|      0|			EVP_MD *md = NULL;
  730|      0|			switch (mech->mechanism) {
  731|      0|				case CKM_ECDSA_SHA1:
  ------------------
  |  |  861|      0|#define CKM_ECDSA_SHA1 0x00001042UL
  ------------------
  |  Branch (731:5): [True: 0, False: 0]
  ------------------
  732|      0|					md = sc_evp_md(context, "sha1");
  733|      0|					break;
  734|      0|				case CKM_ECDSA_SHA224:
  ------------------
  |  |  862|      0|#define CKM_ECDSA_SHA224 0x00001043UL
  ------------------
  |  Branch (734:5): [True: 0, False: 0]
  ------------------
  735|      0|					md = sc_evp_md(context, "sha224");
  736|      0|					break;
  737|      0|				case CKM_ECDSA_SHA256:
  ------------------
  |  |  863|      0|#define CKM_ECDSA_SHA256 0x00001044UL
  ------------------
  |  Branch (737:5): [True: 0, False: 0]
  ------------------
  738|      0|					md = sc_evp_md(context, "sha256");
  739|      0|					break;
  740|      0|				case CKM_ECDSA_SHA384:
  ------------------
  |  |  864|      0|#define CKM_ECDSA_SHA384 0x00001045UL
  ------------------
  |  Branch (740:5): [True: 0, False: 0]
  ------------------
  741|      0|					md = sc_evp_md(context, "sha384");
  742|      0|					break;
  743|      0|				case CKM_ECDSA_SHA512:
  ------------------
  |  |  865|      0|#define CKM_ECDSA_SHA512 0x00001046UL
  ------------------
  |  Branch (743:5): [True: 0, False: 0]
  ------------------
  744|      0|					md = sc_evp_md(context, "sha512");
  745|      0|					break;
  746|      0|				default:
  ------------------
  |  Branch (746:5): [True: 0, False: 0]
  ------------------
  747|      0|					EVP_PKEY_free(pkey);
  748|      0|					return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  749|      0|			}
  750|      0|			mdbuf_len = EVP_MD_size(md);
  751|      0|			mdbuf = calloc(1, mdbuf_len);
  752|      0|			if (mdbuf == NULL) {
  ------------------
  |  Branch (752:8): [True: 0, False: 0]
  ------------------
  753|      0|				EVP_PKEY_free(pkey);
  754|      0|				sc_evp_md_free(md);
  755|      0|				return CKR_DEVICE_MEMORY;
  ------------------
  |  | 1104|      0|#define CKR_DEVICE_MEMORY 0x00000031UL
  ------------------
  756|      0|			}
  757|      0|			if ((mdctx = EVP_MD_CTX_new()) == NULL) {
  ------------------
  |  Branch (757:8): [True: 0, False: 0]
  ------------------
  758|      0|				sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  759|      0|				free(mdbuf);
  760|      0|				EVP_PKEY_free(pkey);
  761|      0|				sc_evp_md_free(md);
  762|      0|				return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  763|      0|			}
  764|      0|			if (!EVP_DigestInit(mdctx, md)
  ------------------
  |  Branch (764:8): [True: 0, False: 0]
  ------------------
  765|      0|				|| !EVP_DigestUpdate(mdctx, data, data_len)
  ------------------
  |  Branch (765:8): [True: 0, False: 0]
  ------------------
  766|      0|				|| !EVP_DigestFinal(mdctx, mdbuf, &mdbuf_len)) {
  ------------------
  |  Branch (766:8): [True: 0, False: 0]
  ------------------
  767|      0|				sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  768|      0|				EVP_PKEY_free(pkey);
  769|      0|				EVP_MD_CTX_free(mdctx);
  770|      0|				sc_evp_md_free(md);
  771|      0|				free(mdbuf);
  772|      0|				return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  773|      0|			}
  774|      0|			EVP_MD_CTX_free(mdctx);
  775|      0|			sc_evp_md_free(md);
  776|      0|			data = mdbuf;
  777|      0|			data_len = mdbuf_len;
  778|      0|		}
  779|       |
  780|      4|		res = 0;
  781|      4|		r = sc_asn1_sig_value_rs_to_sequence(NULL, signat, signat_len,
  782|      4|						     &signat_tmp, &signat_len_tmp);
  783|      4|		ctx = sc_evp_pkey_ctx_new(context, pkey);
  784|      4|		if (r == 0 && EVP_PKEY_base_id(pkey) == EVP_PKEY_EC && ctx && EVP_PKEY_verify_init(ctx) == 1)
  ------------------
  |  Branch (784:7): [True: 2, False: 2]
  |  Branch (784:17): [True: 2, False: 0]
  |  Branch (784:58): [True: 2, False: 0]
  |  Branch (784:65): [True: 2, False: 0]
  ------------------
  785|      2|			res = EVP_PKEY_verify(ctx, signat_tmp, signat_len_tmp, data, data_len);
  786|       |
  787|      4|		EVP_PKEY_CTX_free(ctx);
  788|      4|		EVP_PKEY_free(pkey);
  789|      4|		free(signat_tmp);
  790|      4|		free(mdbuf);
  791|       |
  792|      4|		if (res == 1) {
  ------------------
  |  Branch (792:7): [True: 0, False: 4]
  ------------------
  793|      0|			return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  794|      4|		} else if (res == 0) {
  ------------------
  |  Branch (794:14): [True: 3, False: 1]
  ------------------
  795|      3|			sc_log_openssl(context);
  ------------------
  |  |   72|      3|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  796|      3|			return CKR_SIGNATURE_INVALID;
  ------------------
  |  | 1140|      3|#define CKR_SIGNATURE_INVALID 0x000000C0UL
  ------------------
  797|      3|		} else {
  798|      1|			sc_log_openssl(context);
  ------------------
  |  |   72|      1|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  799|      1|			return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      1|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  800|      1|		}
  801|     13|	} else {
  802|     13|		unsigned char *rsa_out = NULL, pad;
  803|     13|		size_t rsa_outlen = 0;
  804|     13|		EVP_PKEY_CTX *ctx = sc_evp_pkey_ctx_new(context, pkey);
  805|     13|		if (!ctx) {
  ------------------
  |  Branch (805:7): [True: 0, False: 13]
  ------------------
  806|      0|			sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  807|      0|			EVP_PKEY_free(pkey);
  808|      0|			return CKR_DEVICE_MEMORY;
  ------------------
  |  | 1104|      0|#define CKR_DEVICE_MEMORY 0x00000031UL
  ------------------
  809|      0|		}
  810|       |
  811|     13|		sc_log(context, "Trying to verify using low-level API");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  812|     13|		switch (mech->mechanism) {
  813|      1|		case CKM_RSA_PKCS:
  ------------------
  |  |  539|      1|#define CKM_RSA_PKCS 0x00000001UL
  ------------------
  |  Branch (813:3): [True: 1, False: 12]
  ------------------
  814|      1|		case CKM_MD5_RSA_PKCS:
  ------------------
  |  |  543|      1|#define CKM_MD5_RSA_PKCS 0x00000005UL
  ------------------
  |  Branch (814:3): [True: 0, False: 13]
  ------------------
  815|      1|		case CKM_RIPEMD160_RSA_PKCS:
  ------------------
  |  |  546|      1|#define CKM_RIPEMD160_RSA_PKCS 0x00000008UL
  ------------------
  |  Branch (815:3): [True: 0, False: 13]
  ------------------
  816|      1|		 	pad = RSA_PKCS1_PADDING;
  817|      1|		 	break;
  818|      5|		case CKM_RSA_X_509:
  ------------------
  |  |  541|      5|#define CKM_RSA_X_509 0x00000003UL
  ------------------
  |  Branch (818:3): [True: 5, False: 8]
  ------------------
  819|      5|			pad = RSA_NO_PADDING;
  820|      5|			break;
  821|      1|		case CKM_RSA_PKCS_PSS:
  ------------------
  |  |  551|      1|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
  |  Branch (821:3): [True: 1, False: 12]
  ------------------
  822|      3|		case CKM_SHA1_RSA_PKCS_PSS:
  ------------------
  |  |  552|      3|#define CKM_SHA1_RSA_PKCS_PSS 0x0000000EUL
  ------------------
  |  Branch (822:3): [True: 2, False: 11]
  ------------------
  823|      4|		case CKM_SHA224_RSA_PKCS_PSS:
  ------------------
  |  |  605|      4|#define CKM_SHA224_RSA_PKCS_PSS 0x00000047UL
  ------------------
  |  Branch (823:3): [True: 1, False: 12]
  ------------------
  824|      5|		case CKM_SHA256_RSA_PKCS_PSS:
  ------------------
  |  |  601|      5|#define CKM_SHA256_RSA_PKCS_PSS 0x00000043UL
  ------------------
  |  Branch (824:3): [True: 1, False: 12]
  ------------------
  825|      6|		case CKM_SHA384_RSA_PKCS_PSS:
  ------------------
  |  |  602|      6|#define CKM_SHA384_RSA_PKCS_PSS 0x00000044UL
  ------------------
  |  Branch (825:3): [True: 1, False: 12]
  ------------------
  826|      7|		case CKM_SHA512_RSA_PKCS_PSS:
  ------------------
  |  |  603|      7|#define CKM_SHA512_RSA_PKCS_PSS 0x00000045UL
  ------------------
  |  Branch (826:3): [True: 1, False: 12]
  ------------------
  827|      7|			pad = RSA_NO_PADDING;
  828|      7|			break;
  829|      0|		default:
  ------------------
  |  Branch (829:3): [True: 0, False: 13]
  ------------------
  830|      0|			EVP_PKEY_free(pkey);
  831|      0|			EVP_PKEY_CTX_free(ctx);
  832|      0|			return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  833|     13|		}
  834|       |
  835|     13|		if (EVP_PKEY_verify_recover_init(ctx) != 1 ||
  ------------------
  |  Branch (835:7): [True: 0, False: 13]
  ------------------
  836|     13|			EVP_PKEY_CTX_set_rsa_padding(ctx, pad) != 1) {
  ------------------
  |  Branch (836:4): [True: 0, False: 13]
  ------------------
  837|      0|			sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  838|      0|			EVP_PKEY_CTX_free(ctx);
  839|      0|			EVP_PKEY_free(pkey);
  840|      0|			return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  841|      0|		}
  842|       |
  843|     13|		rsa_outlen = EVP_PKEY_size(pkey);
  844|     13|		rsa_out = calloc(1, rsa_outlen);
  845|     13|		if (rsa_out == NULL) {
  ------------------
  |  Branch (845:7): [True: 0, False: 13]
  ------------------
  846|      0|			EVP_PKEY_free(pkey);
  847|      0|			EVP_PKEY_CTX_free(ctx);
  848|      0|			return CKR_DEVICE_MEMORY;
  ------------------
  |  | 1104|      0|#define CKR_DEVICE_MEMORY 0x00000031UL
  ------------------
  849|      0|		}
  850|     13|		if (EVP_PKEY_verify_recover(ctx, rsa_out, &rsa_outlen, signat, signat_len) != 1) {
  ------------------
  |  Branch (850:7): [True: 1, False: 12]
  ------------------
  851|      1|			sc_log_openssl(context);
  ------------------
  |  |   72|      1|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  852|      1|			free(rsa_out);
  853|      1|			EVP_PKEY_free(pkey);
  854|      1|			EVP_PKEY_CTX_free(ctx);
  855|      1|			sc_log(context, "RSA_public_decrypt() returned %d\n", (int) rsa_outlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  856|      1|			return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      1|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  857|      1|		}
  858|     12|		EVP_PKEY_CTX_free(ctx);
  859|       |		/* For PSS mechanisms we can not simply compare the "decrypted"
  860|       |		 * data -- we need to verify the PSS padding is valid
  861|       |		 */
  862|     12|		if (mech->mechanism == CKM_RSA_PKCS_PSS ||
  ------------------
  |  |  551|     24|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
  |  Branch (862:7): [True: 1, False: 11]
  ------------------
  863|     11|		    mech->mechanism == CKM_SHA1_RSA_PKCS_PSS ||
  ------------------
  |  |  552|     23|#define CKM_SHA1_RSA_PKCS_PSS 0x0000000EUL
  ------------------
  |  Branch (863:7): [True: 2, False: 9]
  ------------------
  864|      9|		    mech->mechanism == CKM_SHA224_RSA_PKCS_PSS ||
  ------------------
  |  |  605|     21|#define CKM_SHA224_RSA_PKCS_PSS 0x00000047UL
  ------------------
  |  Branch (864:7): [True: 1, False: 8]
  ------------------
  865|      8|		    mech->mechanism == CKM_SHA256_RSA_PKCS_PSS ||
  ------------------
  |  |  601|     20|#define CKM_SHA256_RSA_PKCS_PSS 0x00000043UL
  ------------------
  |  Branch (865:7): [True: 1, False: 7]
  ------------------
  866|      7|		    mech->mechanism == CKM_SHA384_RSA_PKCS_PSS ||
  ------------------
  |  |  602|     19|#define CKM_SHA384_RSA_PKCS_PSS 0x00000044UL
  ------------------
  |  Branch (866:7): [True: 1, False: 6]
  ------------------
  867|      7|		    mech->mechanism == CKM_SHA512_RSA_PKCS_PSS) {
  ------------------
  |  |  603|      6|#define CKM_SHA512_RSA_PKCS_PSS 0x00000045UL
  ------------------
  |  Branch (867:7): [True: 1, False: 5]
  ------------------
  868|      7|			CK_RSA_PKCS_PSS_PARAMS* param = NULL;
  869|      7|			EVP_MD *mgf_md = NULL, *pss_md = NULL;
  870|      7|			unsigned char digest[EVP_MAX_MD_SIZE];
  871|       |
  872|      7|			if (mech->pParameter == NULL) {
  ------------------
  |  Branch (872:8): [True: 7, False: 0]
  ------------------
  873|      7|				free(rsa_out);
  874|      7|				EVP_PKEY_free(pkey);
  875|      7|				sc_log(context, "PSS mechanism requires parameter");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  876|      7|				return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      7|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
  877|      7|			}
  878|       |
  879|      0|			param = (CK_RSA_PKCS_PSS_PARAMS*)mech->pParameter;
  880|      0|			switch (param->mgf) {
  881|      0|			case CKG_MGF1_SHA1:
  ------------------
  |  |  442|      0|#define CKG_MGF1_SHA1 0x00000001UL
  ------------------
  |  Branch (881:4): [True: 0, False: 0]
  ------------------
  882|      0|				mgf_md = sc_evp_md(context, "sha1");
  883|      0|				break;
  884|      0|			case CKG_MGF1_SHA224:
  ------------------
  |  |  446|      0|#define CKG_MGF1_SHA224 0x00000005UL
  ------------------
  |  Branch (884:4): [True: 0, False: 0]
  ------------------
  885|      0|				mgf_md = sc_evp_md(context, "sha224");
  886|      0|				break;
  887|      0|			case CKG_MGF1_SHA256:
  ------------------
  |  |  443|      0|#define CKG_MGF1_SHA256 0x00000002UL
  ------------------
  |  Branch (887:4): [True: 0, False: 0]
  ------------------
  888|      0|				mgf_md = sc_evp_md(context, "sha256");
  889|      0|				break;
  890|      0|			case CKG_MGF1_SHA384:
  ------------------
  |  |  444|      0|#define CKG_MGF1_SHA384 0x00000003UL
  ------------------
  |  Branch (890:4): [True: 0, False: 0]
  ------------------
  891|      0|				mgf_md = sc_evp_md(context, "sha384");
  892|      0|				break;
  893|      0|			case CKG_MGF1_SHA512:
  ------------------
  |  |  445|      0|#define CKG_MGF1_SHA512 0x00000004UL
  ------------------
  |  Branch (893:4): [True: 0, False: 0]
  ------------------
  894|      0|				mgf_md = sc_evp_md(context, "sha512");
  895|      0|				break;
  896|      0|			default:
  ------------------
  |  Branch (896:4): [True: 0, False: 0]
  ------------------
  897|      0|				free(rsa_out);
  898|      0|				EVP_PKEY_free(pkey);
  899|      0|				return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
  900|      0|			}
  901|       |
  902|      0|			switch (param->hashAlg) {
  903|      0|			case CKM_SHA_1:
  ------------------
  |  |  667|      0|#define CKM_SHA_1 0x00000220UL
  ------------------
  |  Branch (903:4): [True: 0, False: 0]
  ------------------
  904|      0|				pss_md = sc_evp_md(context, "sha1");
  905|      0|				break;
  906|      0|			case CKM_SHA224:
  ------------------
  |  |  679|      0|#define CKM_SHA224 0x00000255UL
  ------------------
  |  Branch (906:4): [True: 0, False: 0]
  ------------------
  907|      0|				pss_md = sc_evp_md(context, "sha224");
  908|      0|				break;
  909|      0|			case CKM_SHA256:
  ------------------
  |  |  676|      0|#define CKM_SHA256 0x00000250UL
  ------------------
  |  Branch (909:4): [True: 0, False: 0]
  ------------------
  910|      0|				pss_md = sc_evp_md(context, "sha256");
  911|      0|				break;
  912|      0|			case CKM_SHA384:
  ------------------
  |  |  682|      0|#define CKM_SHA384 0x00000260UL
  ------------------
  |  Branch (912:4): [True: 0, False: 0]
  ------------------
  913|      0|				pss_md = sc_evp_md(context, "sha384");
  914|      0|				break;
  915|      0|			case CKM_SHA512:
  ------------------
  |  |  685|      0|#define CKM_SHA512 0x00000270UL
  ------------------
  |  Branch (915:4): [True: 0, False: 0]
  ------------------
  916|      0|				pss_md = sc_evp_md(context, "sha512");
  917|      0|				break;
  918|      0|			default:
  ------------------
  |  Branch (918:4): [True: 0, False: 0]
  ------------------
  919|      0|				sc_evp_md_free(mgf_md);
  920|      0|				free(rsa_out);
  921|      0|				EVP_PKEY_free(pkey);
  922|      0|				return CKR_MECHANISM_PARAM_INVALID;
  ------------------
  |  | 1123|      0|#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
  ------------------
  923|      0|			}
  924|       |
  925|       |			/* for the mechanisms with hash algorithm, the data
  926|       |			 * is already added to the hash buffer, so we need
  927|       |			 * to finish the hash operation here
  928|       |			 */
  929|      0|			if (mech->mechanism != CKM_RSA_PKCS_PSS) {
  ------------------
  |  |  551|      0|#define CKM_RSA_PKCS_PSS 0x0000000DUL
  ------------------
  |  Branch (929:8): [True: 0, False: 0]
  ------------------
  930|      0|				EVP_MD_CTX *md_ctx = DIGEST_CTX(md);
  ------------------
  |  |  371|      0|	(op ? (EVP_MD_CTX *) (op)->priv_data : NULL)
  |  |  ------------------
  |  |  |  Branch (371:3): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  931|      0|				unsigned char *tmp = digest;
  932|      0|				unsigned int tmp_len;
  933|       |
  934|      0|				if (!md_ctx || !EVP_DigestFinal(md_ctx, tmp, &tmp_len)) {
  ------------------
  |  Branch (934:9): [True: 0, False: 0]
  |  Branch (934:20): [True: 0, False: 0]
  ------------------
  935|      0|					sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  936|      0|					sc_evp_md_free(mgf_md);
  937|      0|					sc_evp_md_free(pss_md);
  938|      0|					free(rsa_out);
  939|      0|					EVP_PKEY_free(pkey);
  940|      0|					return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  941|      0|				}
  942|      0|				data = tmp;
  943|      0|				data_len = tmp_len;
  944|      0|			}
  945|      0|			rv = CKR_SIGNATURE_INVALID;
  ------------------
  |  | 1140|      0|#define CKR_SIGNATURE_INVALID 0x000000C0UL
  ------------------
  946|       |
  947|       |			/* special mode - autodetect sLen from signature */
  948|       |			/* https://github.com/openssl/openssl/blob/master/crypto/rsa/rsa_pss.c */
  949|       |			/* there is no way to pass negative value here, we using maximal value for this */
  950|      0|			if (((CK_ULONG) 1 ) << (sizeof(CK_ULONG) * CHAR_BIT -1) == param->sLen || param->sLen > INT_MAX)
  ------------------
  |  Branch (950:8): [True: 0, False: 0]
  |  Branch (950:78): [True: 0, False: 0]
  ------------------
  951|      0|				sLen = RSA_PSS_SALTLEN_AUTO;
  952|      0|			else
  953|      0|				sLen = (int) param->sLen;
  954|       |
  955|      0|			if ((ctx = sc_evp_pkey_ctx_new(context, pkey)) == NULL ||
  ------------------
  |  Branch (955:8): [True: 0, False: 0]
  ------------------
  956|      0|				EVP_PKEY_verify_init(ctx) != 1 ||
  ------------------
  |  Branch (956:5): [True: 0, False: 0]
  ------------------
  957|      0|				EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) != 1 ||
  ------------------
  |  Branch (957:5): [True: 0, False: 0]
  ------------------
  958|      0|				EVP_PKEY_CTX_set_signature_md(ctx, pss_md) != 1 ||
  ------------------
  |  Branch (958:5): [True: 0, False: 0]
  ------------------
  959|      0|				EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, sLen) != 1 ||
  ------------------
  |  Branch (959:5): [True: 0, False: 0]
  ------------------
  960|      0|				EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, mgf_md) != 1) {
  ------------------
  |  Branch (960:5): [True: 0, False: 0]
  ------------------
  961|      0|				sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  962|      0|				sc_evp_md_free(mgf_md);
  963|      0|				sc_evp_md_free(pss_md);
  964|      0|				free(rsa_out);
  965|      0|				EVP_PKEY_free(pkey);
  966|      0|				EVP_PKEY_CTX_free(ctx);
  967|      0|				sc_log(context, "Failed to initialize EVP_PKEY_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__
  |  |  ------------------
  ------------------
  968|      0|				return rv;
  969|      0|			}
  970|       |
  971|      0|			if (data_len == (unsigned int)EVP_MD_size(pss_md) &&
  ------------------
  |  Branch (971:8): [True: 0, False: 0]
  ------------------
  972|      0|					EVP_PKEY_verify(ctx, signat, signat_len, data, data_len) == 1) {
  ------------------
  |  Branch (972:6): [True: 0, False: 0]
  ------------------
  973|      0|				rv = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  974|      0|			} else {
  975|      0|				sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  976|      0|			}
  977|      0|			EVP_PKEY_free(pkey);
  978|      0|			EVP_PKEY_CTX_free(ctx);
  979|      0|			sc_evp_md_free(mgf_md);
  980|      0|			sc_evp_md_free(pss_md);
  981|      0|			free(rsa_out);
  982|      0|			sc_log(context, "Returning %lu", 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__
  |  |  ------------------
  ------------------
  983|      0|			return rv;
  984|      5|		} else {
  985|      5|			EVP_PKEY_free(pkey);
  986|      5|		}
  987|       |
  988|      5|		if ((unsigned int) rsa_outlen == data_len && memcmp(rsa_out, data, data_len) == 0)
  ------------------
  |  Branch (988:7): [True: 4, False: 1]
  |  Branch (988:48): [True: 0, False: 4]
  ------------------
  989|      0|			rv = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  990|      5|		else
  991|      5|			rv = CKR_SIGNATURE_INVALID;
  ------------------
  |  | 1140|      5|#define CKR_SIGNATURE_INVALID 0x000000C0UL
  ------------------
  992|      5|		free(rsa_out);
  993|      5|	}
  994|       |
  995|      5|	return rv;
  996|     44|}
openssl.c:sc_pkcs11_openssl_md_release:
  433|    195|{
  434|    195|	if (op) {
  ------------------
  |  Branch (434:6): [True: 195, False: 0]
  ------------------
  435|    195|		EVP_MD_CTX	*md_ctx = DIGEST_CTX(op);
  ------------------
  |  |  371|    195|	(op ? (EVP_MD_CTX *) (op)->priv_data : NULL)
  |  |  ------------------
  |  |  |  Branch (371:3): [True: 195, False: 0]
  |  |  ------------------
  ------------------
  436|    195|		if (md_ctx)
  ------------------
  |  Branch (436:7): [True: 194, False: 1]
  ------------------
  437|    195|			EVP_MD_CTX_destroy(md_ctx);
  438|       |		op->priv_data = NULL;
  439|    195|	}
  440|    195|}
openssl.c:sc_pkcs11_openssl_md_init:
  374|    195|{
  375|    195|	sc_pkcs11_mechanism_type_t *mt;
  376|    195|	EVP_MD_CTX	*md_ctx;
  377|    195|	EVP_MD		*md;
  378|       |
  379|    195|	if (!op || !(mt = op->type) || !(md = (EVP_MD *) mt->mech_data))
  ------------------
  |  Branch (379:6): [True: 0, False: 195]
  |  Branch (379:13): [True: 0, False: 195]
  |  Branch (379:33): [True: 1, False: 194]
  ------------------
  380|      1|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      1|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  381|       |
  382|    194|	if (!(md_ctx = EVP_MD_CTX_create())) {
  ------------------
  |  Branch (382:6): [True: 0, False: 194]
  ------------------
  383|      0|		sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  384|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  385|      0|	}
  386|    194|	if (!EVP_DigestInit(md_ctx, md)) {
  ------------------
  |  Branch (386:6): [True: 0, False: 194]
  ------------------
  387|      0|		sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  388|      0|		EVP_MD_CTX_destroy(md_ctx);
  389|      0|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  390|      0|	}
  391|    194|	op->priv_data = md_ctx;
  392|    194|	return CKR_OK;
  ------------------
  |  | 1086|    194|#define CKR_OK 0x00000000UL
  ------------------
  393|    194|}
openssl.c:sc_pkcs11_openssl_md_update:
  397|    292|{
  398|    292|	EVP_MD_CTX *md_ctx = DIGEST_CTX(op);
  ------------------
  |  |  371|    292|	(op ? (EVP_MD_CTX *) (op)->priv_data : NULL)
  |  |  ------------------
  |  |  |  Branch (371:3): [True: 292, False: 0]
  |  |  ------------------
  ------------------
  399|    292|	if (!md_ctx) {
  ------------------
  |  Branch (399:6): [True: 0, False: 292]
  ------------------
  400|      0|		sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  401|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  402|      0|	}
  403|    292|	if (!EVP_DigestUpdate(md_ctx, pData, pDataLen)) {
  ------------------
  |  Branch (403:6): [True: 0, False: 292]
  ------------------
  404|      0|		sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  405|      0|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  406|      0|	}
  407|    292|	return CKR_OK;
  ------------------
  |  | 1086|    292|#define CKR_OK 0x00000000UL
  ------------------
  408|    292|}
openssl.c:sc_pkcs11_openssl_md_final:
  412|    157|{
  413|    157|	unsigned int tmp_len = 0;
  414|    157|	EVP_MD_CTX *md_ctx = DIGEST_CTX(op);
  ------------------
  |  |  371|    157|	(op ? (EVP_MD_CTX *) (op)->priv_data : NULL)
  |  |  ------------------
  |  |  |  Branch (371:3): [True: 157, False: 0]
  |  |  ------------------
  ------------------
  415|       |
  416|    157|	if (!md_ctx)
  ------------------
  |  Branch (416:6): [True: 0, False: 157]
  ------------------
  417|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  418|    157|	if (*pulDigestLen < (unsigned) EVP_MD_CTX_size(md_ctx)) {
  ------------------
  |  Branch (418:6): [True: 1, False: 156]
  ------------------
  419|      1|		sc_log(context, "Provided buffer too small: %lu < %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__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  420|      1|		       *pulDigestLen, EVP_MD_CTX_size(md_ctx));
  |  |  ------------------
  ------------------
  420|      1|		       *pulDigestLen, EVP_MD_CTX_size(md_ctx));
  421|      1|		*pulDigestLen = EVP_MD_CTX_size(md_ctx);
  422|      1|		return CKR_BUFFER_TOO_SMALL;
  ------------------
  |  | 1165|      1|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  423|      1|	}
  424|    156|	if (!EVP_DigestFinal(md_ctx, pDigest, &tmp_len)) {
  ------------------
  |  Branch (424:6): [True: 0, False: 156]
  ------------------
  425|      0|		sc_log_openssl(context);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  426|      0|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  427|      0|	}
  428|    156|	*pulDigestLen = (CK_ULONG)tmp_len;
  429|    156|	return CKR_OK;
  ------------------
  |  | 1086|    156|#define CKR_OK 0x00000000UL
  ------------------
  430|    156|}
openssl.c:ossl_md_free:
  250|  73.0k|{
  251|  73.0k|	sc_evp_md_free((EVP_MD *)md);
  252|  73.0k|}
openssl.c:ossl_md_copy:
  238|  36.5k|{
  239|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  240|       |	int ret = EVP_MD_up_ref((EVP_MD *)src);
  241|       |	if (ret != 1) {
  242|       |		return CKR_GENERAL_ERROR;
  243|       |	}
  244|       |#endif
  245|  36.5k|	*dst = (EVP_MD *)src;
  246|  36.5k|	return CKR_OK;
  ------------------
  |  | 1086|  36.5k|#define CKR_OK 0x00000000UL
  ------------------
  247|  36.5k|}
openssl.c:dup_mem:
  230|  41.7k|{
  231|  41.7k|	void *out = malloc(in_len);
  232|  41.7k|	if (out)
  ------------------
  |  Branch (232:6): [True: 41.7k, False: 0]
  ------------------
  233|  41.7k|		memcpy(out, in, in_len);
  234|  41.7k|	return out;
  235|  41.7k|}

lookup_enum_spec:
 1337|  37.3k|{
 1338|  37.3k|	CK_ULONG i;
 1339|       |
 1340|   357k|	for(i = 0; i < spec->size; i++)
  ------------------
  |  Branch (1340:13): [True: 357k, False: 0]
  ------------------
 1341|   357k|		if(spec->specs[i].type == value)
  ------------------
  |  Branch (1341:6): [True: 37.3k, False: 320k]
  ------------------
 1342|  37.3k|			return spec->specs[i].name;
 1343|      0|	return NULL;
 1344|  37.3k|}
lookup_enum:
 1349|  37.3k|{
 1350|  37.3k|	CK_ULONG i;
 1351|       |
 1352|   410k|	for(i = 0; ck_types[i].type < ( sizeof(ck_types) / sizeof(enum_spec) ) ; i++)
  ------------------
  |  Branch (1352:13): [True: 410k, False: 0]
  ------------------
 1353|   410k|		if(ck_types[i].type == type)
  ------------------
  |  Branch (1353:6): [True: 37.3k, False: 373k]
  ------------------
 1354|  37.3k|			return lookup_enum_spec(&(ck_types[i]), value);
 1355|      0|	return NULL;
 1356|  37.3k|}

module_init:
  242|      2|{
  243|       |#ifdef _WIN32
  244|       |	InitializeCriticalSection(&c_initialize_cs);
  245|       |#endif
  246|      2|	sc_notify_init();
  247|      2|	return 1;
  248|      2|}
C_Initialize:
  292|  15.7k|{
  293|  15.7k|	CK_RV rv;
  294|  15.7k|#if !defined(_WIN32)
  295|  15.7k|	pid_t current_pid;
  296|  15.7k|#endif
  297|  15.7k|	int rc;
  298|  15.7k|	sc_context_param_t ctx_opts;
  299|       |
  300|  15.7k|#if !defined(_WIN32)
  301|       |	/* Handle fork() exception */
  302|  15.7k|	C_INITIALIZE_M_LOCK
  ------------------
  |  |   71|  15.7k|#define C_INITIALIZE_M_LOCK  pthread_mutex_lock(&c_initialize_m);
  ------------------
  303|  15.7k|	current_pid = getpid();
  304|  15.7k|	if (current_pid != initialized_pid) {
  ------------------
  |  Branch (304:6): [True: 1, False: 15.7k]
  ------------------
  305|      1|		if (context && CKR_OK == sc_pkcs11_lock()) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (305:7): [True: 0, False: 1]
  |  Branch (305:18): [True: 0, False: 0]
  ------------------
  306|      0|			context->flags |= SC_CTX_FLAG_TERMINATE;
  ------------------
  |  |  856|      0|#define SC_CTX_FLAG_TERMINATE				0x00000001
  ------------------
  307|      0|			sc_pkcs11_unlock();
  308|      0|		}
  309|      1|		C_Finalize(NULL_PTR);
  ------------------
  |  |   27|      1|#define NULL_PTR ((void *)0)
  ------------------
  310|      1|	}
  311|  15.7k|	initialized_pid = current_pid;
  312|  15.7k|	in_finalize = 0;
  313|  15.7k|	C_INITIALIZE_M_UNLOCK
  ------------------
  |  |   72|  15.7k|#define C_INITIALIZE_M_UNLOCK pthread_mutex_unlock(&c_initialize_m);
  ------------------
  314|  15.7k|#endif
  315|       |
  316|       |	/* protect from nesting */
  317|  15.7k|	C_INITIALIZE_M_LOCK
  ------------------
  |  |   71|  15.7k|#define C_INITIALIZE_M_LOCK  pthread_mutex_lock(&c_initialize_m);
  ------------------
  318|  15.7k|	nesting++;
  319|  15.7k|	if (nesting > 1) {
  ------------------
  |  Branch (319:6): [True: 0, False: 15.7k]
  ------------------
  320|      0|		nesting--;
  321|      0|		C_INITIALIZE_M_UNLOCK
  ------------------
  |  |   72|      0|#define C_INITIALIZE_M_UNLOCK pthread_mutex_unlock(&c_initialize_m);
  ------------------
  322|      0|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  323|      0|	}
  324|  15.7k|	C_INITIALIZE_M_UNLOCK
  ------------------
  |  |   72|  15.7k|#define C_INITIALIZE_M_UNLOCK pthread_mutex_unlock(&c_initialize_m);
  ------------------
  325|       |	/* protect from nesting */
  326|       |
  327|       |	/* protect from multiple threads tryng to setup locking */
  328|  15.7k|	C_INITIALIZE_M_LOCK
  ------------------
  |  |   71|  15.7k|#define C_INITIALIZE_M_LOCK  pthread_mutex_lock(&c_initialize_m);
  ------------------
  329|       |
  330|  15.7k|	if (context != NULL) {
  ------------------
  |  Branch (330:6): [True: 0, False: 15.7k]
  ------------------
  331|      0|		if (CKR_OK == sc_pkcs11_lock()) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (331:7): [True: 0, False: 0]
  ------------------
  332|      0|			sc_log(context, "C_Initialize(): Cryptoki already initialized\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__
  |  |  ------------------
  ------------------
  333|      0|			sc_pkcs11_unlock();
  334|      0|		}
  335|      0|		nesting--;
  336|      0|		C_INITIALIZE_M_UNLOCK
  ------------------
  |  |   72|      0|#define C_INITIALIZE_M_UNLOCK pthread_mutex_unlock(&c_initialize_m);
  ------------------
  337|      0|		return CKR_CRYPTOKI_ALREADY_INITIALIZED;
  ------------------
  |  | 1170|      0|#define CKR_CRYPTOKI_ALREADY_INITIALIZED 0x00000191UL
  ------------------
  338|      0|	}
  339|       |
  340|  15.7k|	rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pInitArgs);
  341|  15.7k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (341:6): [True: 0, False: 15.7k]
  ------------------
  342|      0|		goto out;
  343|       |
  344|       |	/* set context options */
  345|  15.7k|	memset(&ctx_opts, 0, sizeof(sc_context_param_t));
  346|  15.7k|	ctx_opts.ver        = 0;
  347|  15.7k|	ctx_opts.app_name   = MODULE_APP_NAME;
  ------------------
  |  |   49|  15.7k|#define MODULE_APP_NAME "opensc-pkcs11"
  ------------------
  348|  15.7k|	ctx_opts.thread_ctx = &sc_thread_ctx;
  349|       |
  350|  15.7k|	rc = sc_context_create(&context, &ctx_opts);
  351|  15.7k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (351:6): [True: 0, False: 15.7k]
  ------------------
  352|      0|		rv = CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  353|      0|		goto out;
  354|      0|	}
  355|       |
  356|       |	/* Load configuration */
  357|  15.7k|	load_pkcs11_parameters(&sc_pkcs11_conf, context);
  358|       |
  359|       |	/* List of sessions */
  360|  15.7k|	if (0 != list_init(&sessions)) {
  ------------------
  |  Branch (360:6): [True: 0, False: 15.7k]
  ------------------
  361|      0|		rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  362|      0|		goto out;
  363|      0|	}
  364|  15.7k|	list_attributes_seeker(&sessions, session_list_seeker);
  365|       |
  366|       |	/* List of slots */
  367|  15.7k|	if (0 != list_init(&virtual_slots)) {
  ------------------
  |  Branch (367:6): [True: 0, False: 15.7k]
  ------------------
  368|      0|		rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  369|      0|		goto out;
  370|      0|	}
  371|  15.7k|	list_attributes_seeker(&virtual_slots, slot_list_seeker);
  372|       |
  373|  15.7k|	card_detect_all();
  374|       |
  375|  15.7k|out:
  376|  15.7k|	if (context != NULL)
  ------------------
  |  Branch (376:6): [True: 15.7k, False: 0]
  ------------------
  377|  15.7k|		SC_LOG_RV("C_Initialize() = %s", rv);
  ------------------
  |  |  237|  15.7k|#define SC_LOG_RV(fmt, rv)\
  |  |  238|  15.7k|do {\
  |  |  239|  15.7k|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|  15.7k|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 15.7k, False: 0]
  |  |  ------------------
  |  |  241|  15.7k|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|  15.7k|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|  15.7k|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 15.7k]
  |  |  ------------------
  ------------------
  378|       |
  379|  15.7k|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (379:6): [True: 0, False: 15.7k]
  ------------------
  380|      0|		if (context != NULL) {
  ------------------
  |  Branch (380:7): [True: 0, False: 0]
  ------------------
  381|      0|			sc_release_context(context);
  382|      0|			context = NULL;
  383|      0|		}
  384|       |		/* Release and destroy the mutex */
  385|      0|		sc_pkcs11_free_lock();
  386|      0|	}
  387|       |
  388|       |	/* protect from multiple threads tryng to setup locking */
  389|  15.7k|	nesting--;
  390|  15.7k|	C_INITIALIZE_M_UNLOCK
  ------------------
  |  |   72|  15.7k|#define C_INITIALIZE_M_UNLOCK pthread_mutex_unlock(&c_initialize_m);
  ------------------
  391|       |
  392|  15.7k|	return rv;
  393|  15.7k|}
C_Finalize:
  396|  15.7k|{
  397|  15.7k|	int i;
  398|  15.7k|	void *p;
  399|  15.7k|	sc_pkcs11_slot_t *slot;
  400|  15.7k|	CK_RV rv;
  401|       |
  402|  15.7k|	if (pReserved != NULL_PTR)
  ------------------
  |  |   27|  15.7k|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (402:6): [True: 0, False: 15.7k]
  ------------------
  403|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  404|       |
  405|  15.7k|#if !defined(_WIN32)
  406|  15.7k|	sc_notify_close();
  407|  15.7k|#endif
  408|       |
  409|  15.7k|	if (context == NULL)
  ------------------
  |  Branch (409:6): [True: 1, False: 15.7k]
  ------------------
  410|      1|		return CKR_CRYPTOKI_NOT_INITIALIZED;
  ------------------
  |  | 1169|      1|#define CKR_CRYPTOKI_NOT_INITIALIZED 0x00000190UL
  ------------------
  411|       |
  412|  15.7k|	rv = sc_pkcs11_lock();
  413|  15.7k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (413:6): [True: 0, False: 15.7k]
  ------------------
  414|      0|		return rv;
  415|       |
  416|  15.7k|	sc_log(context, "C_Finalize()");
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  417|       |
  418|       |	/* cancel pending calls */
  419|  15.7k|	in_finalize = 1;
  420|  15.7k|	sc_cancel(context);
  421|       |	/* remove all cards from readers */
  422|  31.5k|	for (i=0; i < (int)sc_ctx_get_reader_count(context); i++)
  ------------------
  |  Branch (422:12): [True: 15.7k, False: 15.7k]
  ------------------
  423|  15.7k|		card_removed(sc_ctx_get_reader(context, i));
  424|       |
  425|  15.7k|	while ((p = list_fetch(&sessions)))
  ------------------
  |  Branch (425:9): [True: 0, False: 15.7k]
  ------------------
  426|      0|		free(p);
  427|  15.7k|	list_destroy(&sessions);
  428|       |
  429|  31.5k|	while ((slot = list_fetch(&virtual_slots))) {
  ------------------
  |  Branch (429:9): [True: 15.7k, False: 15.7k]
  ------------------
  430|  15.7k|		sc_wait_for_event(context, 0, NULL, NULL, 0, &slot->reader_events);
  431|  15.7k|		list_destroy(&slot->objects);
  432|  15.7k|		list_destroy(&slot->logins);
  433|  15.7k|		free(slot);
  434|  15.7k|	}
  435|  15.7k|	list_destroy(&virtual_slots);
  436|       |
  437|  15.7k|	sc_release_context(context);
  438|  15.7k|	context = NULL;
  439|       |
  440|       |	/* Release and destroy the mutex */
  441|  15.7k|	sc_pkcs11_free_lock();
  442|       |
  443|  15.7k|	return rv;
  444|  15.7k|}
C_InitToken:
  729|    248|{
  730|    248|	struct sc_pkcs11_session *session;
  731|    248|	struct sc_pkcs11_slot *slot;
  732|    248|	unsigned char *label, *cpo;
  733|    248|	CK_RV rv;
  734|    248|	unsigned int i;
  735|       |
  736|       |	/* Strip trailing whitespace and null terminate the label.
  737|       |	 * Keep the fixed-length buffer though as some other layers or drivers (SC-HSM)
  738|       |	 * might expect the length is fixed! */
  739|    248|	label = malloc(33);
  740|    248|	if (label == NULL) {
  ------------------
  |  Branch (740:6): [True: 0, False: 248]
  ------------------
  741|      0|		sc_log(context, "Failed to allocate label memory");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  742|      0|		return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  743|      0|	}
  744|    248|	memcpy(label, pLabel, 32);
  745|    248|	label[32] = 0;
  746|    248|	cpo = label + 31;
  747|  7.62k|	while ((cpo >= label) && (*cpo == ' ')) {
  ------------------
  |  Branch (747:9): [True: 7.62k, False: 1]
  |  Branch (747:27): [True: 7.38k, False: 247]
  ------------------
  748|  7.38k|		*cpo = 0;
  749|  7.38k|		cpo--;
  750|  7.38k|	}
  751|       |
  752|    248|	sc_log(context, "C_InitToken(pLabel='%s') called", label);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  753|    248|	rv = sc_pkcs11_lock();
  754|    248|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|    248|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (754:6): [True: 0, False: 248]
  ------------------
  755|      0|		free(label);
  756|      0|		return rv;
  757|      0|	}
  758|       |
  759|    248|	rv = slot_get_token(slotID, &slot);
  760|    248|	if (rv != CKR_OK)   {
  ------------------
  |  | 1086|    248|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (760:6): [True: 0, False: 248]
  ------------------
  761|      0|		sc_log(context, "C_InitToken() get token error 0x%lX", 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__
  |  |  ------------------
  ------------------
  762|      0|		goto out;
  763|      0|	}
  764|       |
  765|    248|	if (!slot->p11card || !slot->p11card->framework
  ------------------
  |  Branch (765:6): [True: 0, False: 248]
  |  Branch (765:24): [True: 0, False: 248]
  ------------------
  766|    248|		   || !slot->p11card->framework->init_token) {
  ------------------
  |  Branch (766:9): [True: 0, False: 248]
  ------------------
  767|      0|		sc_log(context, "C_InitToken() not supported by framework");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  768|      0|		rv = CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
  769|      0|		goto out;
  770|      0|	}
  771|       |
  772|       |	/* Make sure there's no open session for this token */
  773|    248|	for (i=0; i<list_size(&sessions); i++) {
  ------------------
  |  Branch (773:12): [True: 248, False: 0]
  ------------------
  774|    248|		session = (struct sc_pkcs11_session*)list_get_at(&sessions, i);
  775|    248|		if (session->slot == slot) {
  ------------------
  |  Branch (775:7): [True: 248, False: 0]
  ------------------
  776|    248|			rv = CKR_SESSION_EXISTS;
  ------------------
  |  | 1137|    248|#define CKR_SESSION_EXISTS 0x000000B6UL
  ------------------
  777|    248|			goto out;
  778|    248|		}
  779|    248|	}
  780|       |
  781|      0|	rv = slot->p11card->framework->init_token(slot, slot->fw_data, pPin, ulPinLen, label);
  782|      0|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (782:6): [True: 0, False: 0]
  ------------------
  783|       |		/* Now we should re-bind all tokens so they get the
  784|       |		 * corresponding function vector and flags */
  785|      0|	}
  786|       |
  787|    248|out:
  788|    248|	sc_pkcs11_unlock();
  789|    248|	sc_log(context, "C_InitToken(pLabel='%s') returns 0x%lX", label, rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  790|    248|	free(label);
  791|    248|	return rv;
  792|      0|}
sc_pkcs11_init_lock:
  955|  15.7k|{
  956|  15.7k|	CK_RV rv = CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  957|       |
  958|  15.7k|	int applock = 0;
  959|  15.7k|	int oslock = 0;
  960|  15.7k|	if (global_lock)
  ------------------
  |  Branch (960:6): [True: 0, False: 15.7k]
  ------------------
  961|      0|		return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  962|       |
  963|       |	/* No CK_C_INITIALIZE_ARGS pointer, no locking */
  964|  15.7k|	if (!args)
  ------------------
  |  Branch (964:6): [True: 15.7k, False: 0]
  ------------------
  965|  15.7k|		return CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  966|       |
  967|      0|	if (args->pReserved != NULL_PTR)
  ------------------
  |  |   27|      0|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (967:6): [True: 0, False: 0]
  ------------------
  968|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  969|       |
  970|      0|	app_locking = *args;
  971|       |
  972|       |	/* If the app tells us OS locking is okay,
  973|       |	 * use that. Otherwise use the supplied functions.
  974|       |	 */
  975|      0|	global_locking = NULL;
  976|      0|	if (args->CreateMutex && args->DestroyMutex &&
  ------------------
  |  Branch (976:6): [True: 0, False: 0]
  |  Branch (976:27): [True: 0, False: 0]
  ------------------
  977|      0|		   args->LockMutex   && args->UnlockMutex) {
  ------------------
  |  Branch (977:6): [True: 0, False: 0]
  |  Branch (977:27): [True: 0, False: 0]
  ------------------
  978|      0|			applock = 1;
  979|      0|	}
  980|      0|	if ((args->flags & CKF_OS_LOCKING_OK)) {
  ------------------
  |  |  341|      0|#define CKF_OS_LOCKING_OK 0x00000002UL
  ------------------
  |  Branch (980:6): [True: 0, False: 0]
  ------------------
  981|      0|		oslock = 1;
  982|      0|	}
  983|       |
  984|       |	/* Based on PKCS#11 v2.11 11.4 */
  985|      0|	if (applock && oslock) {
  ------------------
  |  Branch (985:6): [True: 0, False: 0]
  |  Branch (985:17): [True: 0, False: 0]
  ------------------
  986|       |		/* Shall be used in threaded environment, prefer app provided locking */
  987|      0|		global_locking = &app_locking;
  988|      0|	} else if (!applock && oslock) {
  ------------------
  |  Branch (988:13): [True: 0, False: 0]
  |  Branch (988:25): [True: 0, False: 0]
  ------------------
  989|       |		/* Shall be used in threaded environment, must use operating system locking */
  990|      0|		global_locking = default_mutex_funcs;
  991|      0|	} else if (applock && !oslock) {
  ------------------
  |  Branch (991:13): [True: 0, False: 0]
  |  Branch (991:24): [True: 0, False: 0]
  ------------------
  992|       |		/* Shall be used in threaded environment, must use app provided locking */
  993|      0|		global_locking = &app_locking;
  994|      0|	} else if (!applock && !oslock) {
  ------------------
  |  Branch (994:13): [True: 0, False: 0]
  |  Branch (994:25): [True: 0, False: 0]
  ------------------
  995|       |		/* Shall not be used in threaded environment, use operating system locking */
  996|      0|		global_locking = default_mutex_funcs;
  997|      0|	}
  998|       |
  999|      0|	if (global_locking != NULL) {
  ------------------
  |  Branch (999:6): [True: 0, False: 0]
  ------------------
 1000|       |		/* create mutex */
 1001|      0|		rv = global_locking->CreateMutex(&global_lock);
 1002|      0|	}
 1003|       |
 1004|      0|	return rv;
 1005|      0|}
sc_pkcs11_lock:
 1008|  57.6k|{
 1009|  57.6k|	if (context == NULL)
  ------------------
  |  Branch (1009:6): [True: 0, False: 57.6k]
  ------------------
 1010|      0|		return CKR_CRYPTOKI_NOT_INITIALIZED;
  ------------------
  |  | 1169|      0|#define CKR_CRYPTOKI_NOT_INITIALIZED 0x00000190UL
  ------------------
 1011|       |
 1012|  57.6k|	if (!global_lock)
  ------------------
  |  Branch (1012:6): [True: 57.6k, False: 0]
  ------------------
 1013|  57.6k|		return CKR_OK;
  ------------------
  |  | 1086|  57.6k|#define CKR_OK 0x00000000UL
  ------------------
 1014|      0|	if (global_locking)  {
  ------------------
  |  Branch (1014:6): [True: 0, False: 0]
  ------------------
 1015|      0|		while (global_locking->LockMutex(global_lock) != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1015:10): [True: 0, False: 0]
  ------------------
 1016|      0|			;
 1017|      0|	}
 1018|       |
 1019|      0|	return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
 1020|  57.6k|}
sc_pkcs11_unlock:
 1034|  41.8k|{
 1035|  41.8k|	__sc_pkcs11_unlock(global_lock);
 1036|  41.8k|}
sc_pkcs11_free_lock:
 1043|  15.7k|{
 1044|  15.7k|	void	*tempLock;
 1045|       |
 1046|  15.7k|	if (!(tempLock = global_lock))
  ------------------
  |  Branch (1046:6): [True: 15.7k, False: 0]
  ------------------
 1047|  15.7k|		return;
 1048|       |
 1049|       |	/* Clear the global lock pointer - once we've
 1050|       |	 * unlocked the mutex it's as good as gone */
 1051|      0|	global_lock = NULL;
 1052|       |
 1053|       |	/* Now unlock. On SMP machines the synchronization
 1054|       |	 * primitives should take care of flushing out
 1055|       |	 * all changed data to RAM */
 1056|      0|	__sc_pkcs11_unlock(tempLock);
 1057|       |
 1058|      0|	if (global_locking)
  ------------------
  |  Branch (1058:6): [True: 0, False: 0]
  ------------------
 1059|      0|		global_locking->DestroyMutex(tempLock);
 1060|       |	global_locking = NULL;
 1061|      0|}
pkcs11-global.c:sc_create_mutex:
  175|  31.5k|{
  176|  31.5k|	if (global_locking == NULL)
  ------------------
  |  Branch (176:6): [True: 31.5k, False: 0]
  ------------------
  177|  31.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  31.5k|#define SC_SUCCESS				0
  ------------------
  178|      0|	if (global_locking->CreateMutex(m) == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (178:6): [True: 0, False: 0]
  ------------------
  179|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  180|      0|	else
  181|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  182|      0|}
pkcs11-global.c:sc_lock_mutex:
  185|  1.28M|{
  186|  1.28M|	if (global_locking == NULL)
  ------------------
  |  Branch (186:6): [True: 1.28M, False: 0]
  ------------------
  187|  1.28M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.28M|#define SC_SUCCESS				0
  ------------------
  188|      0|	if (global_locking->LockMutex(m) == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (188:6): [True: 0, False: 0]
  ------------------
  189|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  190|      0|	else
  191|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  192|      0|}
pkcs11-global.c:sc_unlock_mutex:
  195|  1.28M|{
  196|  1.28M|	if (global_locking == NULL)
  ------------------
  |  Branch (196:6): [True: 1.28M, False: 0]
  ------------------
  197|  1.28M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.28M|#define SC_SUCCESS				0
  ------------------
  198|      0|	if (global_locking->UnlockMutex(m) == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (198:6): [True: 0, False: 0]
  ------------------
  199|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  200|      0|	else
  201|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  202|       |
  203|      0|}
pkcs11-global.c:session_list_seeker:
  221|  27.3k|static int session_list_seeker(const void *el, const void *key) {
  222|  27.3k|	const struct sc_pkcs11_session *session = (struct sc_pkcs11_session *)el;
  223|  27.3k|	if ((el == NULL) || (key == NULL))
  ------------------
  |  Branch (223:6): [True: 0, False: 27.3k]
  |  Branch (223:22): [True: 0, False: 27.3k]
  ------------------
  224|      0|		return 0;
  225|  27.3k|	if (session->handle == *(CK_SESSION_HANDLE*)key)
  ------------------
  |  Branch (225:6): [True: 27.3k, False: 0]
  ------------------
  226|  27.3k|		return 1;
  227|      0|	return 0;
  228|  27.3k|}
pkcs11-global.c:slot_list_seeker:
  229|  29.0k|static int slot_list_seeker(const void *el, const void *key) {
  230|  29.0k|	const struct sc_pkcs11_slot *slot = (struct sc_pkcs11_slot *)el;
  231|  29.0k|	if ((el == NULL) || (key == NULL))
  ------------------
  |  Branch (231:6): [True: 0, False: 29.0k]
  |  Branch (231:22): [True: 0, False: 29.0k]
  ------------------
  232|      0|		return 0;
  233|  29.0k|	if (slot->id == *(CK_SLOT_ID *)key)
  ------------------
  |  Branch (233:6): [True: 29.0k, False: 0]
  ------------------
  234|  29.0k|		return 1;
  235|      0|	return 0;
  236|  29.0k|}
pkcs11-global.c:__sc_pkcs11_unlock:
 1024|  41.8k|{
 1025|  41.8k|	if (!lock)
  ------------------
  |  Branch (1025:6): [True: 41.8k, False: 0]
  ------------------
 1026|  41.8k|		return;
 1027|      0|	if (global_locking) {
  ------------------
  |  Branch (1027:6): [True: 0, False: 0]
  ------------------
 1028|      0|		while (global_locking->UnlockMutex(lock) != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1028:10): [True: 0, False: 0]
  ------------------
 1029|      0|			;
 1030|      0|	}
 1031|      0|}

C_CreateObject:
  160|    310|{
  161|    310|	return sc_create_object_int(hSession, pTemplate, ulCount, phObject, 1);
  162|    310|}
C_FindObjectsInit:
  354|  1.47k|{
  355|  1.47k|	CK_RV rv;
  356|  1.47k|	CK_BBOOL is_private = TRUE;
  ------------------
  |  |   51|  1.47k|#define TRUE 1
  ------------------
  357|  1.47k|	CK_ATTRIBUTE private_attribute = { CKA_PRIVATE, &is_private, sizeof(is_private) };
  ------------------
  |  |  139|  1.47k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  358|  1.47k|	int match, hide_private;
  359|  1.47k|	unsigned int i, j;
  360|  1.47k|	struct sc_pkcs11_session *session;
  361|  1.47k|	struct sc_pkcs11_object *object;
  362|  1.47k|	struct sc_pkcs11_find_operation *operation;
  363|  1.47k|	struct sc_pkcs11_slot *slot;
  364|  1.47k|	struct sc_pkcs11_operation *op = NULL;
  365|       |
  366|  1.47k|	if (pTemplate == NULL_PTR && ulCount > 0)
  ------------------
  |  |   27|  2.95k|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (366:6): [True: 0, False: 1.47k]
  |  Branch (366:31): [True: 0, False: 0]
  ------------------
  367|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  368|       |
  369|  1.47k|	rv = sc_pkcs11_lock();
  370|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (370:6): [True: 0, False: 1.47k]
  ------------------
  371|      0|		return rv;
  372|       |
  373|  1.47k|	rv = get_session(hSession, &session);
  374|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (374:6): [True: 0, False: 1.47k]
  ------------------
  375|      0|		goto out;
  376|       |
  377|  1.47k|	sc_log(context, "C_FindObjectsInit(slot = %lu)\n", session->slot->id);
  ------------------
  |  |   71|  1.47k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  378|  1.47k|	dump_template(SC_LOG_DEBUG_NORMAL, "C_FindObjectsInit()", pTemplate, ulCount);
  ------------------
  |  |  411|  1.47k|		sc_pkcs11_print_attrs(level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  412|  1.47k|				info, pTemplate, ulCount)
  ------------------
  379|       |
  380|  1.47k|	rv = session_start_operation(session, SC_PKCS11_OPERATION_FIND,
  381|  1.47k|				     &find_mechanism, &op);
  382|  1.47k|	operation = (struct sc_pkcs11_find_operation *) op;
  383|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (383:6): [True: 0, False: 1.47k]
  ------------------
  384|      0|		goto out;
  385|       |
  386|  1.47k|	operation->current_handle = 0;
  387|  1.47k|	operation->num_handles = 0;
  388|  1.47k|	operation->allocated_handles = 0;
  389|  1.47k|	operation->handles = NULL;
  390|  1.47k|	slot = session->slot;
  391|       |
  392|       |	/* Check whether we should hide private objects */
  393|  1.47k|	hide_private = 0;
  394|  1.47k|	if ((slot->login_user == -1) && (slot->token_info.flags & CKF_LOGIN_REQUIRED))
  ------------------
  |  |  414|    760|#define CKF_LOGIN_REQUIRED 0x00000004UL
  ------------------
  |  Branch (394:6): [True: 760, False: 718]
  |  Branch (394:34): [True: 582, False: 178]
  ------------------
  395|    582|		hide_private = 1;
  396|       |
  397|       |	/* For each object in token do */
  398|  18.5k|	for (i=0; i<list_size(&slot->objects); i++) {
  ------------------
  |  Branch (398:12): [True: 17.0k, False: 1.47k]
  ------------------
  399|  17.0k|		object = (struct sc_pkcs11_object *)list_get_at(&slot->objects, i);
  400|  17.0k|		sc_log(context, "Object with handle 0x%lx", object->handle);
  ------------------
  |  |   71|  17.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__
  |  |  ------------------
  ------------------
  401|       |
  402|       |		/* User not logged in and private object? */
  403|  17.0k|		if (hide_private) {
  ------------------
  |  Branch (403:7): [True: 13.9k, False: 3.15k]
  ------------------
  404|  13.9k|			if (object->ops->get_attribute(session, object, &private_attribute) != CKR_OK)
  ------------------
  |  | 1086|  13.9k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (404:8): [True: 0, False: 13.9k]
  ------------------
  405|      0|			        continue;
  406|  13.9k|			if (is_private) {
  ------------------
  |  Branch (406:8): [True: 2.95k, False: 10.9k]
  ------------------
  407|  2.95k|				sc_log(context,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  408|  2.95k|				       "Object %lu/%lu: Private object and not logged in.",
  409|  2.95k|				       slot->id, object->handle);
  410|  2.95k|				continue;
  411|  2.95k|			}
  412|  13.9k|		}
  413|       |
  414|       |		/* Try to match every attribute */
  415|  14.0k|		match = 1;
  416|  16.6k|		for (j = 0; j < ulCount; j++) {
  ------------------
  |  Branch (416:15): [True: 15.6k, False: 979]
  ------------------
  417|  15.6k|			rv = object->ops->cmp_attribute(session, object, &pTemplate[j]);
  418|  15.6k|			if (rv == 0) {
  ------------------
  |  Branch (418:8): [True: 13.1k, False: 2.51k]
  ------------------
  419|  13.1k|				sc_log(context,
  ------------------
  |  |   71|  13.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  420|  13.1k|				       "Object %lu/%lu: Attribute 0x%lx does NOT match.",
  421|  13.1k|				       slot->id, object->handle, pTemplate[j].type);
  422|  13.1k|				match = 0;
  423|  13.1k|				break;
  424|  13.1k|			}
  425|       |
  426|  2.51k|			if (context->debug >= 4) {
  ------------------
  |  Branch (426:8): [True: 0, False: 2.51k]
  ------------------
  427|      0|				sc_log(context,
  ------------------
  |  |   71|      0|#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|      0|				       "Object %lu/%lu: Attribute 0x%lx matches.",
  429|      0|				       slot->id, object->handle, pTemplate[j].type);
  430|      0|			}
  431|  2.51k|		}
  432|       |
  433|  14.0k|		if (match) {
  ------------------
  |  Branch (433:7): [True: 979, False: 13.1k]
  ------------------
  434|    979|			sc_log(context, "Object %lu/%lu matches\n", slot->id,
  ------------------
  |  |   71|    979|#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|    979|			       object->handle);
  436|       |			/* Realloc handles - remove restriction on only 32 matching objects -dee */
  437|    979|			if (operation->num_handles >= operation->allocated_handles) {
  ------------------
  |  Branch (437:8): [True: 711, False: 268]
  ------------------
  438|    711|				operation->allocated_handles += SC_PKCS11_FIND_INC_HANDLES;
  ------------------
  |  |  370|    711|#define SC_PKCS11_FIND_INC_HANDLES	32
  ------------------
  439|    711|				sc_log(context, "realloc for %d handles", operation->allocated_handles);
  ------------------
  |  |   71|    711|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  440|    711|				operation->handles = realloc(operation->handles,
  441|    711|					sizeof(CK_OBJECT_HANDLE) * operation->allocated_handles);
  442|    711|				if (operation->handles == NULL) {
  ------------------
  |  Branch (442:9): [True: 0, False: 711]
  ------------------
  443|      0|					rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  444|      0|					goto out;
  445|      0|				}
  446|    711|			}
  447|    979|			operation->handles[operation->num_handles++] = object->handle;
  448|    979|		}
  449|  14.0k|	}
  450|  1.47k|	rv = CKR_OK;
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  451|       |
  452|  1.47k|	sc_log(context, "%d matching objects\n", operation->num_handles);
  ------------------
  |  |   71|  1.47k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  453|       |
  454|  1.47k|out:
  455|  1.47k|	sc_pkcs11_unlock();
  456|  1.47k|	return rv;
  457|  1.47k|}
C_FindObjects:
  465|  1.47k|{
  466|  1.47k|	CK_RV rv;
  467|  1.47k|	CK_ULONG to_return;
  468|  1.47k|	struct sc_pkcs11_session *session;
  469|  1.47k|	struct sc_pkcs11_find_operation *operation;
  470|  1.47k|	struct sc_pkcs11_operation *op = NULL;
  471|       |
  472|  1.47k|	if (phObject == NULL_PTR || ulMaxObjectCount == 0 || pulObjectCount == NULL_PTR)
  ------------------
  |  |   27|  2.95k|#define NULL_PTR ((void *)0)
  ------------------
              	if (phObject == NULL_PTR || ulMaxObjectCount == 0 || pulObjectCount == NULL_PTR)
  ------------------
  |  |   27|  1.47k|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (472:6): [True: 0, False: 1.47k]
  |  Branch (472:30): [True: 0, False: 1.47k]
  |  Branch (472:55): [True: 0, False: 1.47k]
  ------------------
  473|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  474|       |
  475|  1.47k|	rv = sc_pkcs11_lock();
  476|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (476:6): [True: 0, False: 1.47k]
  ------------------
  477|      0|		return rv;
  478|       |
  479|  1.47k|	rv = get_session(hSession, &session);
  480|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (480:6): [True: 0, False: 1.47k]
  ------------------
  481|      0|		goto out;
  482|       |
  483|  1.47k|	rv = session_get_operation(session, SC_PKCS11_OPERATION_FIND, &op);
  484|  1.47k|	operation = (struct sc_pkcs11_find_operation *) op;
  485|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (485:6): [True: 0, False: 1.47k]
  ------------------
  486|      0|		goto out;
  487|       |
  488|  1.47k|	to_return = (CK_ULONG) operation->num_handles - operation->current_handle;
  489|  1.47k|	if (to_return > ulMaxObjectCount)
  ------------------
  |  Branch (489:6): [True: 99, False: 1.37k]
  ------------------
  490|     99|		to_return = ulMaxObjectCount;
  491|       |
  492|  1.47k|	*pulObjectCount = to_return;
  493|       |
  494|  1.47k|	memcpy(phObject, &operation->handles[operation->current_handle], to_return * sizeof(CK_OBJECT_HANDLE));
  495|       |
  496|  1.47k|	operation->current_handle += to_return;
  497|       |
  498|  1.47k|out:	sc_pkcs11_unlock();
  499|  1.47k|	return rv;
  500|  1.47k|}
C_FindObjectsFinal:
  505|  1.47k|{
  506|  1.47k|	CK_RV rv;
  507|  1.47k|	struct sc_pkcs11_session *session;
  508|       |
  509|  1.47k|	rv = sc_pkcs11_lock();
  510|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (510:6): [True: 0, False: 1.47k]
  ------------------
  511|      0|		return rv;
  512|       |
  513|  1.47k|	rv = get_session(hSession, &session);
  514|  1.47k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (514:6): [True: 0, False: 1.47k]
  ------------------
  515|      0|		goto out;
  516|       |
  517|  1.47k|	rv = session_get_operation(session, SC_PKCS11_OPERATION_FIND, NULL);
  518|  1.47k|	if (rv == CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (518:6): [True: 1.47k, False: 0]
  ------------------
  519|  1.47k|		session_stop_operation(session, SC_PKCS11_OPERATION_FIND);
  520|       |
  521|  1.47k|out:	sc_pkcs11_unlock();
  522|  1.47k|	return rv;
  523|  1.47k|}
C_DigestInit:
  532|    248|{
  533|    248|	CK_RV rv;
  534|    248|	struct sc_pkcs11_session *session;
  535|       |
  536|    248|	if (pMechanism == NULL_PTR)
  ------------------
  |  |   27|    248|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (536:6): [True: 0, False: 248]
  ------------------
  537|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  538|       |
  539|    248|	rv = sc_pkcs11_lock();
  540|    248|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    248|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (540:6): [True: 0, False: 248]
  ------------------
  541|      0|		return rv;
  542|       |
  543|    248|	sc_log(context, "C_DigestInit(hSession=0x%lx)", hSession);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  544|    248|	rv = get_session(hSession, &session);
  545|    248|	if (rv == CKR_OK)
  ------------------
  |  | 1086|    248|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (545:6): [True: 248, False: 0]
  ------------------
  546|    248|		rv = sc_pkcs11_md_init(session, pMechanism);
  547|       |
  548|       |	SC_LOG_RV("C_DigestInit() = %s", rv);
  ------------------
  |  |  237|    248|#define SC_LOG_RV(fmt, rv)\
  |  |  238|    248|do {\
  |  |  239|    248|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|    248|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 248, False: 0]
  |  |  ------------------
  |  |  241|    248|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   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__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|    248|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|    248|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 248]
  |  |  ------------------
  ------------------
  549|    248|	sc_pkcs11_unlock();
  550|    248|	return rv;
  551|    248|}
C_Digest:
  560|      1|{
  561|      1|	CK_RV rv;
  562|      1|	struct sc_pkcs11_session *session;
  563|      1|	CK_ULONG  ulBuflen = 0;
  564|       |
  565|      1|	rv = sc_pkcs11_lock();
  566|      1|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      1|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (566:6): [True: 0, False: 1]
  ------------------
  567|      0|		return rv;
  568|       |
  569|      1|	sc_log(context, "C_Digest(hSession=0x%lx)", hSession);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  570|      1|	rv = get_session(hSession, &session);
  571|      1|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      1|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (571:6): [True: 0, False: 1]
  ------------------
  572|      0|		goto out;
  573|       |
  574|       |	/* if pDigest == NULL, buffer size request */
  575|      1|	if (pDigest) {
  ------------------
  |  Branch (575:6): [True: 1, False: 0]
  ------------------
  576|       |	    /* As per PKCS#11 2.20 we need to check if buffer too small before update */
  577|      1|	    rv = sc_pkcs11_md_final(session, NULL, &ulBuflen);
  578|      1|	    if (rv != CKR_OK)
  ------------------
  |  | 1086|      1|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (578:10): [True: 0, False: 1]
  ------------------
  579|      0|		goto out;
  580|       |
  581|      1|	    if (ulBuflen > *pulDigestLen) {
  ------------------
  |  Branch (581:10): [True: 0, False: 1]
  ------------------
  582|      0|	        *pulDigestLen = ulBuflen;
  583|      0|		rv = CKR_BUFFER_TOO_SMALL;
  ------------------
  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
  584|      0|		goto out;
  585|      0|	    }
  586|       |
  587|      1|	    rv = sc_pkcs11_md_update(session, pData, ulDataLen);
  588|      1|	}
  589|      1|	if (rv == CKR_OK)
  ------------------
  |  | 1086|      1|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (589:6): [True: 1, False: 0]
  ------------------
  590|      1|		rv = sc_pkcs11_md_final(session, pDigest, pulDigestLen);
  591|       |
  592|      1|out:
  593|       |	SC_LOG_RV("C_Digest = %s", rv);
  ------------------
  |  |  237|      1|#define SC_LOG_RV(fmt, rv)\
  |  |  238|      1|do {\
  |  |  239|      1|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|      1|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 1, False: 0]
  |  |  ------------------
  |  |  241|      1|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|      1|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 1]
  |  |  ------------------
  ------------------
  594|      1|	sc_pkcs11_unlock();
  595|      1|	return rv;
  596|      1|}
C_DigestUpdate:
  603|    100|{
  604|    100|	CK_RV rv;
  605|    100|	struct sc_pkcs11_session *session;
  606|       |
  607|    100|	rv = sc_pkcs11_lock();
  608|    100|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    100|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (608:6): [True: 0, False: 100]
  ------------------
  609|      0|		return rv;
  610|       |
  611|    100|	rv = get_session(hSession, &session);
  612|    100|	if (rv == CKR_OK)
  ------------------
  |  | 1086|    100|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (612:6): [True: 100, False: 0]
  ------------------
  613|    100|		rv = sc_pkcs11_md_update(session, pPart, ulPartLen);
  614|       |
  615|       |	SC_LOG_RV("C_DigestUpdate() = %s", rv);
  ------------------
  |  |  237|    100|#define SC_LOG_RV(fmt, rv)\
  |  |  238|    100|do {\
  |  |  239|    100|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|    100|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 100, False: 0]
  |  |  ------------------
  |  |  241|    100|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   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__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|    100|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|    100|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 100]
  |  |  ------------------
  ------------------
  616|    100|	sc_pkcs11_unlock();
  617|    100|	return rv;
  618|    100|}
C_DigestFinal:
  633|      8|{
  634|      8|	CK_RV rv;
  635|      8|	struct sc_pkcs11_session *session;
  636|       |
  637|      8|	rv = sc_pkcs11_lock();
  638|      8|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (638:6): [True: 0, False: 8]
  ------------------
  639|      0|		return rv;
  640|       |
  641|      8|	rv = get_session(hSession, &session);
  642|      8|	if (rv == CKR_OK)
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (642:6): [True: 8, False: 0]
  ------------------
  643|      8|		rv = sc_pkcs11_md_final(session, pDigest, pulDigestLen);
  644|       |
  645|       |	SC_LOG_RV("C_DigestFinal() = %s", rv);
  ------------------
  |  |  237|      8|#define SC_LOG_RV(fmt, rv)\
  |  |  238|      8|do {\
  |  |  239|      8|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|      8|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 8, False: 0]
  |  |  ------------------
  |  |  241|      8|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|      8|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|      8|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 8]
  |  |  ------------------
  ------------------
  646|      8|	sc_pkcs11_unlock();
  647|      8|	return rv;
  648|      8|}
C_SignInit:
  655|    433|{
  656|    433|	CK_BBOOL can_sign;
  657|    433|	CK_KEY_TYPE key_type;
  658|    433|	CK_ATTRIBUTE sign_attribute = { CKA_SIGN, &can_sign, sizeof(can_sign) };
  ------------------
  |  |  167|    433|#define CKA_SIGN 0x00000108UL
  ------------------
  659|    433|	CK_ATTRIBUTE key_type_attr = { CKA_KEY_TYPE, &key_type, sizeof(key_type) };
  ------------------
  |  |  159|    433|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  660|    433|	struct sc_pkcs11_session *session;
  661|    433|	struct sc_pkcs11_object *object;
  662|    433|	CK_RV rv;
  663|       |
  664|    433|	if (pMechanism == NULL_PTR)
  ------------------
  |  |   27|    433|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (664:6): [True: 0, False: 433]
  ------------------
  665|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  666|       |
  667|    433|	rv = sc_pkcs11_lock();
  668|    433|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    433|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (668:6): [True: 0, False: 433]
  ------------------
  669|      0|		return rv;
  670|       |
  671|    433|	rv = get_object_from_session(hSession, hKey, &session, &object);
  672|    433|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|    433|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (672:6): [True: 168, False: 265]
  ------------------
  673|    168|		if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|    168|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (673:7): [True: 168, False: 0]
  ------------------
  674|    168|			rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|    168|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
  675|    168|		goto out;
  676|    168|	}
  677|       |
  678|    265|	if (object->ops->sign == NULL_PTR) {
  ------------------
  |  |   27|    265|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (678:6): [True: 0, False: 265]
  ------------------
  679|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  680|      0|		goto out;
  681|      0|	}
  682|       |
  683|    265|	rv = object->ops->get_attribute(session, object, &sign_attribute);
  684|    265|	if (rv != CKR_OK || !can_sign) {
  ------------------
  |  | 1086|    530|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (684:6): [True: 0, False: 265]
  |  Branch (684:22): [True: 3, False: 262]
  ------------------
  685|      3|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      3|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  686|      3|		goto out;
  687|      3|	}
  688|    262|	rv = object->ops->get_attribute(session, object, &key_type_attr);
  689|    262|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|    262|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (689:6): [True: 0, False: 262]
  ------------------
  690|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  691|      0|		goto out;
  692|      0|	}
  693|       |
  694|    262|	rv = sc_pkcs11_sign_init(session, pMechanism, object, key_type);
  695|       |
  696|    433|out:
  697|       |	SC_LOG_RV("C_SignInit() = %s", rv);
  ------------------
  |  |  237|    433|#define SC_LOG_RV(fmt, rv)\
  |  |  238|    433|do {\
  |  |  239|    433|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|    433|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 433, False: 0]
  |  |  ------------------
  |  |  241|    433|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|    433|#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|    433|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|    433|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 433]
  |  |  ------------------
  ------------------
  698|    433|	sc_pkcs11_unlock();
  699|    433|	return rv;
  700|    262|}
C_Sign:
  709|    234|{
  710|    234|	CK_RV rv;
  711|    234|	struct sc_pkcs11_session *session;
  712|    234|	CK_ULONG length;
  713|       |
  714|    234|	rv = sc_pkcs11_lock();
  715|    234|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    234|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (715:6): [True: 0, False: 234]
  ------------------
  716|      0|		return rv;
  717|       |
  718|    234|	rv = get_session(hSession, &session);
  719|    234|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    234|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (719:6): [True: 0, False: 234]
  ------------------
  720|      0|		goto out;
  721|       |
  722|       |	/* According to the pkcs11 specs, we must not do any calls that
  723|       |	 * change our crypto state if the caller is just asking for the
  724|       |	 * signature buffer size, or if the result would be
  725|       |	 * CKR_BUFFER_TOO_SMALL. Thus we cannot do the sign_update call
  726|       |	 * below. */
  727|    234|	if ((rv = sc_pkcs11_sign_size(session, &length)) != CKR_OK)
  ------------------
  |  | 1086|    234|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (727:6): [True: 0, False: 234]
  ------------------
  728|      0|		goto out;
  729|       |
  730|    234|	if (pSignature == NULL || length > *pulSignatureLen) {
  ------------------
  |  Branch (730:6): [True: 0, False: 234]
  |  Branch (730:28): [True: 0, False: 234]
  ------------------
  731|      0|		*pulSignatureLen = length;
  732|      0|		rv = pSignature ? CKR_BUFFER_TOO_SMALL : CKR_OK;
  ------------------
  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
              		rv = pSignature ? CKR_BUFFER_TOO_SMALL : CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (732:8): [True: 0, False: 0]
  ------------------
  733|      0|		goto out;
  734|      0|	}
  735|       |
  736|    234|	rv = sc_pkcs11_sign_update(session, pData, ulDataLen);
  737|    234|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|    234|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (737:6): [True: 234, False: 0]
  ------------------
  738|    234|		rv = restore_login_state(session->slot);
  739|    234|		if (rv == CKR_OK)
  ------------------
  |  | 1086|    234|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (739:7): [True: 234, False: 0]
  ------------------
  740|    234|			rv = sc_pkcs11_sign_final(session, pSignature, pulSignatureLen);
  741|    234|		rv = reset_login_state(session->slot, rv);
  742|    234|	}
  743|       |
  744|    234|out:
  745|       |	SC_LOG_RV("C_Sign() = %s", rv);
  ------------------
  |  |  237|    234|#define SC_LOG_RV(fmt, rv)\
  |  |  238|    234|do {\
  |  |  239|    234|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|    234|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 234, False: 0]
  |  |  ------------------
  |  |  241|    234|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   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__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|    234|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|    234|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 234]
  |  |  ------------------
  ------------------
  746|    234|	sc_pkcs11_unlock();
  747|    234|	return rv;
  748|    234|}
C_SignUpdate:
  755|     12|{
  756|     12|	CK_RV rv;
  757|     12|	struct sc_pkcs11_session *session;
  758|       |
  759|     12|	rv = sc_pkcs11_lock();
  760|     12|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     12|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (760:6): [True: 0, False: 12]
  ------------------
  761|      0|		return rv;
  762|       |
  763|     12|	rv = get_session(hSession, &session);
  764|     12|	if (rv == CKR_OK)
  ------------------
  |  | 1086|     12|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (764:6): [True: 12, False: 0]
  ------------------
  765|     12|		rv = sc_pkcs11_sign_update(session, pPart, ulPartLen);
  766|       |
  767|       |	SC_LOG_RV("C_SignUpdate() = %s", rv);
  ------------------
  |  |  237|     12|#define SC_LOG_RV(fmt, rv)\
  |  |  238|     12|do {\
  |  |  239|     12|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|     12|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 12, False: 0]
  |  |  ------------------
  |  |  241|     12|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|     12|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|     12|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 12]
  |  |  ------------------
  ------------------
  768|     12|	sc_pkcs11_unlock();
  769|     12|	return rv;
  770|     12|}
C_SignFinal:
  777|      4|{
  778|      4|	struct sc_pkcs11_session *session;
  779|      4|	CK_ULONG length;
  780|      4|	CK_RV rv;
  781|       |
  782|      4|	rv = sc_pkcs11_lock();
  783|      4|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      4|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (783:6): [True: 0, False: 4]
  ------------------
  784|      0|		return rv;
  785|       |
  786|      4|	rv = get_session(hSession, &session);
  787|      4|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      4|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (787:6): [True: 0, False: 4]
  ------------------
  788|      0|		goto out;
  789|       |
  790|       |	/* According to the pkcs11 specs, we must not do any calls that
  791|       |	 * change our crypto state if the caller is just asking for the
  792|       |	 * signature buffer size, or if the result would be
  793|       |	 * CKR_BUFFER_TOO_SMALL.
  794|       |	 */
  795|      4|	if ((rv = sc_pkcs11_sign_size(session, &length)) != CKR_OK)
  ------------------
  |  | 1086|      4|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (795:6): [True: 0, False: 4]
  ------------------
  796|      0|		goto out;
  797|       |
  798|      4|	if (pSignature == NULL || length > *pulSignatureLen) {
  ------------------
  |  Branch (798:6): [True: 0, False: 4]
  |  Branch (798:28): [True: 0, False: 4]
  ------------------
  799|      0|		*pulSignatureLen = length;
  800|      0|		rv = pSignature ? CKR_BUFFER_TOO_SMALL : CKR_OK;
  ------------------
  |  | 1165|      0|#define CKR_BUFFER_TOO_SMALL 0x00000150UL
  ------------------
              		rv = pSignature ? CKR_BUFFER_TOO_SMALL : CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (800:8): [True: 0, False: 0]
  ------------------
  801|      4|	} else {
  802|      4|		rv = restore_login_state(session->slot);
  803|      4|		if (rv == CKR_OK)
  ------------------
  |  | 1086|      4|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (803:7): [True: 4, False: 0]
  ------------------
  804|      4|			rv = sc_pkcs11_sign_final(session, pSignature, pulSignatureLen);
  805|      4|		rv = reset_login_state(session->slot, rv);
  806|      4|	}
  807|       |
  808|      4|out:
  809|       |	SC_LOG_RV("C_SignFinal() = %s", rv);
  ------------------
  |  |  237|      4|#define SC_LOG_RV(fmt, rv)\
  |  |  238|      4|do {\
  |  |  239|      4|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|      4|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 4, False: 0]
  |  |  ------------------
  |  |  241|      4|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|      4|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|      4|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 4]
  |  |  ------------------
  ------------------
  810|      4|	sc_pkcs11_unlock();
  811|      4|	return rv;
  812|      4|}
C_DecryptInit:
  961|    355|{				/* handle of the decryption key */
  962|    355|	CK_BBOOL can_decrypt, can_unwrap;
  963|    355|	CK_KEY_TYPE key_type;
  964|    355|	CK_ATTRIBUTE decrypt_attribute = { CKA_DECRYPT,	&can_decrypt,	sizeof(can_decrypt) };
  ------------------
  |  |  164|    355|#define CKA_DECRYPT 0x00000105UL
  ------------------
  965|    355|	CK_ATTRIBUTE key_type_attr = { CKA_KEY_TYPE,	&key_type,	sizeof(key_type) };
  ------------------
  |  |  159|    355|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  966|    355|	CK_ATTRIBUTE unwrap_attribute = { CKA_UNWRAP,	&can_unwrap,	sizeof(can_unwrap) };
  ------------------
  |  |  166|    355|#define CKA_UNWRAP 0x00000107UL
  ------------------
  967|    355|	struct sc_pkcs11_session *session;
  968|    355|	struct sc_pkcs11_object *object;
  969|    355|	CK_RV rv;
  970|       |
  971|    355|	if (pMechanism == NULL_PTR)
  ------------------
  |  |   27|    355|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (971:6): [True: 0, False: 355]
  ------------------
  972|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  973|       |
  974|    355|	rv = sc_pkcs11_lock();
  975|    355|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    355|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (975:6): [True: 0, False: 355]
  ------------------
  976|      0|		return rv;
  977|       |
  978|    355|	rv = get_object_from_session(hSession, hKey, &session, &object);
  979|    355|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|    355|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (979:6): [True: 0, False: 355]
  ------------------
  980|      0|		if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|      0|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (980:7): [True: 0, False: 0]
  ------------------
  981|      0|			rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|      0|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
  982|      0|		goto out;
  983|      0|	}
  984|       |
  985|    355|	if (object->ops->decrypt == NULL_PTR) {
  ------------------
  |  |   27|    355|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (985:6): [True: 0, False: 355]
  ------------------
  986|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  987|      0|		goto out;
  988|      0|	}
  989|       |
  990|    355|	rv = object->ops->get_attribute(session, object, &decrypt_attribute);
  991|    355|	if (rv != CKR_OK || !can_decrypt) {
  ------------------
  |  | 1086|    710|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (991:6): [True: 0, False: 355]
  |  Branch (991:22): [True: 121, False: 234]
  ------------------
  992|       |		/* Also accept UNWRAP - apps call Decrypt when they mean Unwrap */
  993|    121|		rv = object->ops->get_attribute(session, object, &unwrap_attribute);
  994|    121|		if (rv != CKR_OK || !can_unwrap) {
  ------------------
  |  | 1086|    242|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (994:7): [True: 0, False: 121]
  |  Branch (994:23): [True: 114, False: 7]
  ------------------
  995|    114|			rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|    114|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
  996|    114|			goto out;
  997|    114|		}
  998|    121|	}
  999|    241|	rv = object->ops->get_attribute(session, object, &key_type_attr);
 1000|    241|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|    241|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1000:6): [True: 0, False: 241]
  ------------------
 1001|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1002|      0|		goto out;
 1003|      0|	}
 1004|       |
 1005|    241|	rv = sc_pkcs11_decr_init(session, pMechanism, object, key_type);
 1006|       |
 1007|    355|out:
 1008|       |	SC_LOG_RV("C_DecryptInit() = %s", rv);
  ------------------
  |  |  237|    355|#define SC_LOG_RV(fmt, rv)\
  |  |  238|    355|do {\
  |  |  239|    355|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|    355|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 355, False: 0]
  |  |  ------------------
  |  |  241|    355|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|    355|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|    355|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|    355|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 355]
  |  |  ------------------
  ------------------
 1009|    355|	sc_pkcs11_unlock();
 1010|    355|	return rv;
 1011|    241|}
C_Decrypt:
 1019|    186|{
 1020|    186|	CK_RV rv;
 1021|    186|	struct sc_pkcs11_session *session;
 1022|       |
 1023|    186|	rv = sc_pkcs11_lock();
 1024|    186|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    186|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1024:6): [True: 0, False: 186]
  ------------------
 1025|      0|		return rv;
 1026|       |
 1027|    186|	rv = get_session(hSession, &session);
 1028|    186|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|    186|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1028:6): [True: 186, False: 0]
  ------------------
 1029|    186|		rv = restore_login_state(session->slot);
 1030|    186|		if (rv == CKR_OK) {
  ------------------
  |  | 1086|    186|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1030:7): [True: 186, False: 0]
  ------------------
 1031|    186|			rv = sc_pkcs11_decr(session, pEncryptedData,
 1032|    186|					ulEncryptedDataLen, pData, pulDataLen);
 1033|    186|		}
 1034|    186|		rv = reset_login_state(session->slot, rv);
 1035|    186|	}
 1036|       |
 1037|       |	/* do not log error code to prevent side channel attack */
 1038|    186|	SC_LOG("C_Decrypt()");
  ------------------
  |  |  254|    186|	do { \
  |  |  255|    186|		sc_log(context, (fmt)); \
  |  |  ------------------
  |  |  |  |   71|    186|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  256|    186|	} while (0)
  |  |  ------------------
  |  |  |  Branch (256:11): [Folded, False: 186]
  |  |  ------------------
  ------------------
 1039|    186|	sc_pkcs11_unlock();
 1040|    186|	return rv;
 1041|    186|}
C_GenerateKeyPair:
 1150|    286|{				/* gets priv. key handle */
 1151|    286|	CK_RV rv;
 1152|    286|	struct sc_pkcs11_session *session;
 1153|    286|	struct sc_pkcs11_slot *slot;
 1154|       |
 1155|    286|	if (pMechanism == NULL_PTR
  ------------------
  |  |   27|    572|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1155:6): [True: 0, False: 286]
  ------------------
 1156|    286|			|| (pPublicKeyTemplate == NULL_PTR && ulPublicKeyAttributeCount > 0)
  ------------------
  |  |   27|    572|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1156:8): [True: 0, False: 286]
  |  Branch (1156:42): [True: 0, False: 0]
  ------------------
 1157|    286|			|| (pPrivateKeyTemplate == NULL_PTR && ulPrivateKeyAttributeCount > 0))
  ------------------
  |  |   27|    572|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1157:8): [True: 0, False: 286]
  |  Branch (1157:43): [True: 0, False: 0]
  ------------------
 1158|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1159|       |
 1160|    286|	rv = sc_pkcs11_lock();
 1161|    286|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    286|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1161:6): [True: 0, False: 286]
  ------------------
 1162|      0|		return rv;
 1163|       |
 1164|    286|	dump_template(SC_LOG_DEBUG_NORMAL, "C_GenerateKeyPair(), PrivKey attrs", pPrivateKeyTemplate, ulPrivateKeyAttributeCount);
  ------------------
  |  |  411|    286|		sc_pkcs11_print_attrs(level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  412|    286|				info, pTemplate, ulCount)
  ------------------
 1165|    286|	dump_template(SC_LOG_DEBUG_NORMAL, "C_GenerateKeyPair(), PubKey attrs", pPublicKeyTemplate, ulPublicKeyAttributeCount);
  ------------------
  |  |  411|    286|		sc_pkcs11_print_attrs(level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  412|    286|				info, pTemplate, ulCount)
  ------------------
 1166|       |
 1167|    286|	rv = get_session(hSession, &session);
 1168|    286|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    286|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1168:6): [True: 0, False: 286]
  ------------------
 1169|      0|		goto out;
 1170|       |
 1171|    286|	if (!(session->flags & CKF_RW_SESSION)) {
  ------------------
  |  |  402|    286|#define CKF_RW_SESSION 0x00000002UL
  ------------------
  |  Branch (1171:6): [True: 0, False: 286]
  ------------------
 1172|      0|		rv = CKR_SESSION_READ_ONLY;
  ------------------
  |  | 1136|      0|#define CKR_SESSION_READ_ONLY 0x000000B5UL
  ------------------
 1173|      0|		goto out;
 1174|      0|	}
 1175|       |
 1176|    286|	slot = session->slot;
 1177|    286|	if (slot == NULL || slot->p11card == NULL || slot->p11card->framework == NULL
  ------------------
  |  Branch (1177:6): [True: 0, False: 286]
  |  Branch (1177:22): [True: 0, False: 286]
  |  Branch (1177:47): [True: 0, False: 286]
  ------------------
 1178|    286|			|| slot->p11card->framework->gen_keypair == NULL)
  ------------------
  |  Branch (1178:7): [True: 0, False: 286]
  ------------------
 1179|      0|		rv = CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
 1180|    286|	else {
 1181|    286|		rv = restore_login_state(slot);
 1182|    286|		if (rv == CKR_OK)
  ------------------
  |  | 1086|    286|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1182:7): [True: 286, False: 0]
  ------------------
 1183|    286|			rv = slot->p11card->framework->gen_keypair(slot, pMechanism,
 1184|    286|					pPublicKeyTemplate, ulPublicKeyAttributeCount,
 1185|    286|					pPrivateKeyTemplate, ulPrivateKeyAttributeCount,
 1186|    286|					phPublicKey, phPrivateKey);
 1187|    286|		rv = reset_login_state(session->slot, rv);
 1188|    286|	}
 1189|       |
 1190|    286|out:
 1191|    286|	sc_pkcs11_unlock();
 1192|    286|	return rv;
 1193|    286|}
C_UnwrapKey:
 1278|      3|{				/* gets handle of recovered key */
 1279|      3|	CK_RV rv;
 1280|      3|	CK_BBOOL can_unwrap;
 1281|      3|	CK_KEY_TYPE key_type;
 1282|      3|	CK_ATTRIBUTE unwrap_attribute = { CKA_UNWRAP, &can_unwrap, sizeof(can_unwrap) };
  ------------------
  |  |  166|      3|#define CKA_UNWRAP 0x00000107UL
  ------------------
 1283|      3|	CK_ATTRIBUTE key_type_attr = { CKA_KEY_TYPE, &key_type, sizeof(key_type) };
  ------------------
  |  |  159|      3|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
 1284|      3|	struct sc_pkcs11_session *session;
 1285|      3|	struct sc_pkcs11_object *object;
 1286|      3|	struct sc_pkcs11_object *key_object;
 1287|       |
 1288|      3|	if (pMechanism == NULL_PTR)
  ------------------
  |  |   27|      3|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1288:6): [True: 0, False: 3]
  ------------------
 1289|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1290|       |
 1291|      3|	rv = sc_pkcs11_lock();
 1292|      3|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      3|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1292:6): [True: 0, False: 3]
  ------------------
 1293|      0|		return rv;
 1294|       |
 1295|      3|	rv = get_object_from_session(hSession, hUnwrappingKey, &session, &object);
 1296|      3|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|      3|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1296:6): [True: 0, False: 3]
  ------------------
 1297|      0|		if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|      0|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (1297:7): [True: 0, False: 0]
  ------------------
 1298|      0|			rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|      0|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
 1299|      0|		goto out;
 1300|      0|	}
 1301|      3|	if (object->ops->unwrap_key == NULL_PTR) {
  ------------------
  |  |   27|      3|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1301:6): [True: 0, False: 3]
  ------------------
 1302|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1303|      0|		goto out;
 1304|      0|	}
 1305|       |
 1306|      3|	rv = object->ops->get_attribute(session, object, &unwrap_attribute);
 1307|      3|	if (rv != CKR_OK || !can_unwrap) {
  ------------------
  |  | 1086|      6|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1307:6): [True: 0, False: 3]
  |  Branch (1307:22): [True: 1, False: 2]
  ------------------
 1308|      1|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      1|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1309|      1|		goto out;
 1310|      1|	}
 1311|      2|	rv = object->ops->get_attribute(session, object, &key_type_attr);
 1312|      2|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|      2|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1312:6): [True: 0, False: 2]
  ------------------
 1313|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1314|      0|		goto out;
 1315|      0|	}
 1316|       |
 1317|       |	/* Create the target object in memory */
 1318|      2|	rv = sc_create_object_int(hSession, pTemplate, ulAttributeCount, phKey, 0);
 1319|       |
 1320|      2|	if (rv != CKR_OK)
  ------------------
  |  | 1086|      2|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1320:6): [True: 2, False: 0]
  ------------------
 1321|      2|	    goto out;
 1322|       |
 1323|      0|	rv = get_object_from_session(hSession, *phKey, &session, &key_object);
 1324|      0|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1324:6): [True: 0, False: 0]
  ------------------
 1325|      0|		if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|      0|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (1325:7): [True: 0, False: 0]
  ------------------
 1326|      0|			rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|      0|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
 1327|      0|		goto out;
 1328|      0|	}
 1329|       |
 1330|      0|	rv = restore_login_state(session->slot);
 1331|      0|	if (rv == CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1331:6): [True: 0, False: 0]
  ------------------
 1332|      0|		rv = sc_pkcs11_unwrap(session, pMechanism, object, key_type,
 1333|      0|				pWrappedKey, ulWrappedKeyLen, key_object);
 1334|       |	/* TODO if (rv != CK_OK) need to destroy the object */
 1335|      0|	rv = reset_login_state(session->slot, rv);
 1336|       |
 1337|      3|out:
 1338|      3|	sc_pkcs11_unlock();
 1339|      3|	return rv;
 1340|      0|}
C_DeriveKey:
 1348|     18|{
 1349|       |/* TODO: -DEE ECDH with Cofactor  on PIV is an example */
 1350|       |/* TODO: need to do a lot of checking, will only support ECDH for now.*/
 1351|     18|	CK_RV rv;
 1352|     18|	CK_BBOOL can_derive;
 1353|     18|	CK_KEY_TYPE key_type;
 1354|     18|	CK_ATTRIBUTE derive_attribute = { CKA_DERIVE, &can_derive, sizeof(can_derive) };
  ------------------
  |  |  171|     18|#define CKA_DERIVE 0x0000010CUL
  ------------------
 1355|     18|	CK_ATTRIBUTE key_type_attr = { CKA_KEY_TYPE, &key_type, sizeof(key_type) };
  ------------------
  |  |  159|     18|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
 1356|     18|	struct sc_pkcs11_session *session;
 1357|     18|	struct sc_pkcs11_object *object;
 1358|     18|	struct sc_pkcs11_object *key_object;
 1359|       |
 1360|     18|	if (pMechanism == NULL_PTR)
  ------------------
  |  |   27|     18|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1360:6): [True: 0, False: 18]
  ------------------
 1361|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1362|       |
 1363|     18|	rv = sc_pkcs11_lock();
 1364|     18|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     18|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1364:6): [True: 0, False: 18]
  ------------------
 1365|      0|		return rv;
 1366|       |
 1367|     18|	rv = get_object_from_session(hSession, hBaseKey, &session, &object);
 1368|     18|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|     18|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1368:6): [True: 0, False: 18]
  ------------------
 1369|      0|		if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|      0|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (1369:7): [True: 0, False: 0]
  ------------------
 1370|      0|			rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|      0|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
 1371|      0|		goto out;
 1372|      0|	}
 1373|       |
 1374|     18|	if (object->ops->derive == NULL_PTR) {
  ------------------
  |  |   27|     18|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1374:6): [True: 0, False: 18]
  ------------------
 1375|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1376|      0|		goto out;
 1377|      0|	}
 1378|       |
 1379|     18|	rv = object->ops->get_attribute(session, object, &derive_attribute);
 1380|     18|	if (rv != CKR_OK || !can_derive) {
  ------------------
  |  | 1086|     36|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1380:6): [True: 0, False: 18]
  |  Branch (1380:22): [True: 1, False: 17]
  ------------------
 1381|      1|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      1|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1382|      1|		goto out;
 1383|      1|	}
 1384|     17|	rv = object->ops->get_attribute(session, object, &key_type_attr);
 1385|     17|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|     17|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1385:6): [True: 0, False: 17]
  ------------------
 1386|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1387|      0|		goto out;
 1388|      0|	}
 1389|       |	/* TODO DEE Should also check SENSITIVE, ALWAYS_SENSITIVE, EXTRACTABLE,
 1390|       |	   NEVER_EXTRACTABLE of the BaseKey against the template for the newkey.
 1391|       |	*/
 1392|       |
 1393|     17|	switch(key_type) {
 1394|     16|	    case CKK_EC:
  ------------------
  |  |  467|     16|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (1394:6): [True: 16, False: 1]
  ------------------
 1395|     16|	    case CKK_EC_MONTGOMERY:
  ------------------
  |  |  519|     16|#define CKK_EC_MONTGOMERY 0x00000041UL
  ------------------
  |  Branch (1395:6): [True: 0, False: 17]
  ------------------
 1396|       |
 1397|     16|		rv = sc_create_object_int(hSession, pTemplate, ulAttributeCount, phKey, 0);
 1398|     16|		if (rv != CKR_OK)
  ------------------
  |  | 1086|     16|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1398:7): [True: 2, False: 14]
  ------------------
 1399|      2|		    goto out;
 1400|       |
 1401|     14|		rv = get_object_from_session(hSession, *phKey, &session, &key_object);
 1402|     14|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|     14|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1402:7): [True: 0, False: 14]
  ------------------
 1403|      0|			if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|      0|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (1403:8): [True: 0, False: 0]
  ------------------
 1404|      0|				rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|      0|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
 1405|      0|			goto out;
 1406|      0|		}
 1407|       |
 1408|     14|		rv = restore_login_state(session->slot);
 1409|     14|		if (rv == CKR_OK)
  ------------------
  |  | 1086|     14|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1409:7): [True: 14, False: 0]
  ------------------
 1410|     14|			rv = sc_pkcs11_deri(session, pMechanism, object, key_type,
 1411|     14|					hSession, *phKey, key_object);
 1412|       |		/* TODO if (rv != CK_OK) need to destroy the object */
 1413|     14|		rv = reset_login_state(session->slot, rv);
 1414|       |
 1415|     14|		break;
 1416|      1|	    default:
  ------------------
  |  Branch (1416:6): [True: 1, False: 16]
  ------------------
 1417|      1|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      1|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1418|     17|	}
 1419|       |
 1420|     18|out:
 1421|     18|	sc_pkcs11_unlock();
 1422|     18|	return rv;
 1423|     17|}
C_GenerateRandom:
 1435|  6.96k|{				/* number of bytes to be generated */
 1436|  6.96k|	CK_RV rv;
 1437|  6.96k|	struct sc_pkcs11_session *session;
 1438|  6.96k|	struct sc_pkcs11_slot *slot;
 1439|       |
 1440|  6.96k|	rv = sc_pkcs11_lock();
 1441|  6.96k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  6.96k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1441:6): [True: 0, False: 6.96k]
  ------------------
 1442|      0|		return rv;
 1443|       |
 1444|  6.96k|	rv = get_session(hSession, &session);
 1445|  6.96k|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|  6.96k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1445:6): [True: 6.96k, False: 0]
  ------------------
 1446|  6.96k|		slot = session->slot;
 1447|  6.96k|		if (slot == NULL || slot->p11card == NULL || slot->p11card->framework == NULL
  ------------------
  |  Branch (1447:7): [True: 0, False: 6.96k]
  |  Branch (1447:23): [True: 0, False: 6.96k]
  |  Branch (1447:48): [True: 0, False: 6.96k]
  ------------------
 1448|  6.96k|				|| slot->p11card->framework->get_random == NULL)
  ------------------
  |  Branch (1448:8): [True: 0, False: 6.96k]
  ------------------
 1449|      0|			rv = CKR_RANDOM_NO_RNG;
  ------------------
  |  | 1162|      0|#define CKR_RANDOM_NO_RNG 0x00000121UL
  ------------------
 1450|  6.96k|		else
 1451|  6.96k|			rv = slot->p11card->framework->get_random(slot, RandomData, ulRandomLen);
 1452|  6.96k|	}
 1453|       |
 1454|       |	SC_LOG_RV("C_GenerateRandom() = %s", rv);
  ------------------
  |  |  237|  6.96k|#define SC_LOG_RV(fmt, rv)\
  |  |  238|  6.96k|do {\
  |  |  239|  6.96k|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|  6.96k|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 6.96k, False: 0]
  |  |  ------------------
  |  |  241|  6.96k|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|  6.96k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|  6.96k|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|  6.96k|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 6.96k]
  |  |  ------------------
  ------------------
 1455|  6.96k|	sc_pkcs11_unlock();
 1456|  6.96k|	return rv;
 1457|  6.96k|}
C_VerifyInit:
 1472|     70|{				/* handle of the verification key */
 1473|       |#ifndef ENABLE_OPENSSL
 1474|       |	return CKR_FUNCTION_NOT_SUPPORTED;
 1475|       |#else
 1476|     70|	CK_KEY_TYPE key_type;
 1477|     70|	CK_ATTRIBUTE key_type_attr = { CKA_KEY_TYPE, &key_type, sizeof(key_type) };
  ------------------
  |  |  159|     70|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
 1478|     70|	CK_RV rv;
 1479|     70|	struct sc_pkcs11_session *session;
 1480|     70|	struct sc_pkcs11_object *object;
 1481|       |
 1482|     70|	if (pMechanism == NULL_PTR)
  ------------------
  |  |   27|     70|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (1482:6): [True: 0, False: 70]
  ------------------
 1483|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
 1484|       |
 1485|     70|	rv = sc_pkcs11_lock();
 1486|     70|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     70|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1486:6): [True: 0, False: 70]
  ------------------
 1487|      0|		return rv;
 1488|       |
 1489|       |
 1490|     70|	rv = get_object_from_session(hSession, hKey, &session, &object);
 1491|     70|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|     70|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1491:6): [True: 0, False: 70]
  ------------------
 1492|      0|		if (rv == CKR_OBJECT_HANDLE_INVALID)
  ------------------
  |  | 1124|      0|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
  |  Branch (1492:7): [True: 0, False: 0]
  ------------------
 1493|      0|			rv = CKR_KEY_HANDLE_INVALID;
  ------------------
  |  | 1112|      0|#define CKR_KEY_HANDLE_INVALID 0x00000060UL
  ------------------
 1494|      0|		goto out;
 1495|      0|	}
 1496|     70|	rv = object->ops->get_attribute(session, object, &key_type_attr);
 1497|     70|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|     70|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1497:6): [True: 0, False: 70]
  ------------------
 1498|      0|		rv = CKR_KEY_TYPE_INCONSISTENT;
  ------------------
  |  | 1114|      0|#define CKR_KEY_TYPE_INCONSISTENT 0x00000063UL
  ------------------
 1499|      0|		goto out;
 1500|      0|	}
 1501|       |
 1502|     70|	rv = sc_pkcs11_verif_init(session, pMechanism, object, key_type);
 1503|       |
 1504|     70|out:
 1505|       |	SC_LOG_RV("C_VerifyInit() = %s", rv);
  ------------------
  |  |  237|     70|#define SC_LOG_RV(fmt, rv)\
  |  |  238|     70|do {\
  |  |  239|     70|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|     70|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 70, False: 0]
  |  |  ------------------
  |  |  241|     70|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|     70|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|     70|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|     70|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 70]
  |  |  ------------------
  ------------------
 1506|     70|	sc_pkcs11_unlock();
 1507|     70|	return rv;
 1508|     70|#endif
 1509|     70|}
C_Verify:
 1516|     50|{				/* count of bytes of signature */
 1517|       |#ifndef ENABLE_OPENSSL
 1518|       |	return CKR_FUNCTION_NOT_SUPPORTED;
 1519|       |#else
 1520|     50|	CK_RV rv;
 1521|     50|	struct sc_pkcs11_session *session;
 1522|       |
 1523|     50|	rv = sc_pkcs11_lock();
 1524|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1524:6): [True: 0, False: 50]
  ------------------
 1525|      0|		return rv;
 1526|       |
 1527|     50|	rv = get_session(hSession, &session);
 1528|     50|	if (rv != CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1528:6): [True: 0, False: 50]
  ------------------
 1529|      0|		goto out;
 1530|       |
 1531|     50|	rv = sc_pkcs11_verif_update(session, pData, ulDataLen);
 1532|     50|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1532:6): [True: 50, False: 0]
  ------------------
 1533|     50|		rv = restore_login_state(session->slot);
 1534|     50|		if (rv == CKR_OK)
  ------------------
  |  | 1086|     50|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1534:7): [True: 50, False: 0]
  ------------------
 1535|     50|			rv = sc_pkcs11_verif_final(session, pSignature, ulSignatureLen);
 1536|     50|		rv = reset_login_state(session->slot, rv);
 1537|     50|	}
 1538|       |
 1539|     50|out:
 1540|       |	SC_LOG_RV("C_Verify() = %s", rv);
  ------------------
  |  |  237|     50|#define SC_LOG_RV(fmt, rv)\
  |  |  238|     50|do {\
  |  |  239|     50|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|     50|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 50, False: 0]
  |  |  ------------------
  |  |  241|     50|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   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__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|     50|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|     50|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 50]
  |  |  ------------------
  ------------------
 1541|     50|	sc_pkcs11_unlock();
 1542|     50|	return rv;
 1543|     50|#endif
 1544|     50|}
sc_pkcs11_any_cmp_attribute:
 1909|  15.6k|{
 1910|  15.6k|	CK_RV rv;
 1911|  15.6k|	struct sc_pkcs11_object *object;
 1912|  15.6k|	u8 temp1[1024];
 1913|  15.6k|	u8 *temp2 = NULL;	/* dynamic allocation for large attributes */
 1914|  15.6k|	CK_ATTRIBUTE temp_attr;
 1915|       |
 1916|  15.6k|	object = (struct sc_pkcs11_object *)ptr;
 1917|  15.6k|	temp_attr.type = attr->type;
 1918|  15.6k|	temp_attr.pValue = NULL;
 1919|  15.6k|	temp_attr.ulValueLen = 0;
 1920|       |
 1921|       |	/* Get the length of the attribute */
 1922|  15.6k|	rv = object->ops->get_attribute(session, object, &temp_attr);
 1923|  15.6k|	if (rv != CKR_OK || temp_attr.ulValueLen != attr->ulValueLen)
  ------------------
  |  | 1086|  31.2k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1923:6): [True: 0, False: 15.6k]
  |  Branch (1923:22): [True: 108, False: 15.5k]
  ------------------
 1924|    108|		return 0;
 1925|       |
 1926|  15.5k|	if (temp_attr.ulValueLen <= sizeof(temp1))
  ------------------
  |  Branch (1926:6): [True: 15.5k, False: 0]
  ------------------
 1927|  15.5k|		temp_attr.pValue = temp1;
 1928|      0|	else {
 1929|      0|		temp2 = calloc(1, temp_attr.ulValueLen);
 1930|      0|		if (temp2 == NULL)
  ------------------
  |  Branch (1930:7): [True: 0, False: 0]
  ------------------
 1931|      0|			return 0;
 1932|      0|		temp_attr.pValue = temp2;
 1933|      0|	}
 1934|       |
 1935|       |	/* Get the attribute */
 1936|  15.5k|	rv = object->ops->get_attribute(session, object, &temp_attr);
 1937|  15.5k|	if (rv != CKR_OK) {
  ------------------
  |  | 1086|  15.5k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1937:6): [True: 0, False: 15.5k]
  ------------------
 1938|      0|		rv = 0;
 1939|      0|		goto done;
 1940|      0|	}
 1941|       |#ifdef DEBUG
 1942|       |	{
 1943|       |		char foo[64];
 1944|       |
 1945|       |		snprintf(foo, sizeof(foo), "Object %p (slot 0x%lx)", object, session->slot->id);
 1946|       |		dump_template(SC_LOG_DEBUG_NORMAL, foo, &temp_attr, 1);
 1947|       |	}
 1948|       |#endif
 1949|  15.5k|	rv = temp_attr.ulValueLen == attr->ulValueLen
  ------------------
  |  Branch (1949:7): [True: 15.5k, False: 0]
  ------------------
 1950|  15.5k|	    && !memcmp(temp_attr.pValue, attr->pValue, attr->ulValueLen);
  ------------------
  |  Branch (1950:9): [True: 2.51k, False: 13.0k]
  ------------------
 1951|       |
 1952|  15.5k|      done:
 1953|  15.5k|	if (temp2 != NULL)
  ------------------
  |  Branch (1953:6): [True: 0, False: 15.5k]
  ------------------
 1954|      0|		free(temp2);
 1955|       |
 1956|  15.5k|	return rv;
 1957|  15.5k|}
pkcs11-object.c:sc_create_object_int:
  102|    328|{
  103|    328|	CK_RV rv = CKR_OK;
  ------------------
  |  | 1086|    328|#define CKR_OK 0x00000000UL
  ------------------
  104|    328|	struct sc_pkcs11_session *session;
  105|    328|	struct sc_pkcs11_card *card;
  106|    328|	CK_BBOOL is_token = FALSE;
  ------------------
  |  |   48|    328|#define FALSE 0
  ------------------
  107|       |
  108|    328|	LOG_FUNC_CALLED(context);
  ------------------
  |  |  151|    328|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    328|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    328|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    328|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 328]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|    328|	if (pTemplate == NULL_PTR || ulCount == 0)
  ------------------
  |  |   27|    656|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (109:6): [True: 0, False: 328]
  |  Branch (109:31): [True: 0, False: 328]
  ------------------
  110|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  111|       |
  112|    328|	if (use_lock) {
  ------------------
  |  Branch (112:6): [True: 310, False: 18]
  ------------------
  113|    310|	    rv = sc_pkcs11_lock();
  114|    310|	    if (rv != CKR_OK)
  ------------------
  |  | 1086|    310|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (114:10): [True: 0, False: 310]
  ------------------
  115|      0|		return rv;
  116|    310|	}
  117|       |
  118|    328|	dump_template(SC_LOG_DEBUG_NORMAL, "C_CreateObject()", pTemplate, ulCount);
  ------------------
  |  |  411|    328|		sc_pkcs11_print_attrs(level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  412|    328|				info, pTemplate, ulCount)
  ------------------
  119|       |
  120|    328|	session = list_seek(&sessions, &hSession);
  121|    328|	if (!session) {
  ------------------
  |  Branch (121:6): [True: 0, False: 328]
  ------------------
  122|      0|		rv = CKR_SESSION_HANDLE_INVALID;
  ------------------
  |  | 1134|      0|#define CKR_SESSION_HANDLE_INVALID 0x000000B3UL
  ------------------
  123|      0|		goto out;
  124|      0|	}
  125|       |
  126|    328|	rv = attr_find(pTemplate, ulCount, CKA_TOKEN, &is_token, NULL);
  ------------------
  |  |  138|    328|#define CKA_TOKEN 0x00000001UL
  ------------------
  127|    328|	if (rv != CKR_TEMPLATE_INCOMPLETE && rv != CKR_OK) {
  ------------------
  |  | 1142|    656|#define CKR_TEMPLATE_INCOMPLETE 0x000000D0UL
  ------------------
              	if (rv != CKR_TEMPLATE_INCOMPLETE && rv != CKR_OK) {
  ------------------
  |  | 1086|    328|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (127:6): [True: 328, False: 0]
  |  Branch (127:39): [True: 0, False: 328]
  ------------------
  128|      0|		goto out;
  129|      0|	}
  130|       |
  131|    328|	if (is_token == TRUE) {
  ------------------
  |  |   51|    328|#define TRUE 1
  ------------------
  |  Branch (131:6): [True: 255, False: 73]
  ------------------
  132|    255|		if (session->slot->token_info.flags & CKF_WRITE_PROTECTED) {
  ------------------
  |  |  413|    255|#define CKF_WRITE_PROTECTED 0x00000002UL
  ------------------
  |  Branch (132:7): [True: 1, False: 254]
  ------------------
  133|      1|			rv = CKR_TOKEN_WRITE_PROTECTED;
  ------------------
  |  | 1146|      1|#define CKR_TOKEN_WRITE_PROTECTED 0x000000E2UL
  ------------------
  134|      1|			goto out;
  135|      1|		}
  136|    254|		if (!(session->flags & CKF_RW_SESSION)) {
  ------------------
  |  |  402|    254|#define CKF_RW_SESSION 0x00000002UL
  ------------------
  |  Branch (136:7): [True: 0, False: 254]
  ------------------
  137|      0|			rv = CKR_SESSION_READ_ONLY;
  ------------------
  |  | 1136|      0|#define CKR_SESSION_READ_ONLY 0x000000B5UL
  ------------------
  138|      0|			goto out;
  139|      0|		}
  140|    254|	}
  141|       |
  142|    327|	card = session->slot->p11card;
  143|    327|	if (card->framework->create_object == NULL)
  ------------------
  |  Branch (143:6): [True: 0, False: 327]
  ------------------
  144|      0|		rv = CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
  145|    327|	else
  146|    327|		rv = card->framework->create_object(session->slot, pTemplate, ulCount, phObject);
  147|       |
  148|    328|out:
  149|    328|	if (use_lock)
  ------------------
  |  Branch (149:6): [True: 310, False: 18]
  ------------------
  150|    310|		sc_pkcs11_unlock();
  151|       |
  152|    328|	return rv;
  153|    327|}
pkcs11-object.c:get_object_from_session:
   78|    893|{
   79|    893|	struct sc_pkcs11_session *sess;
   80|    893|	CK_RV rv;
   81|       |
   82|    893|	rv = get_session(hSession, &sess);
   83|    893|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    893|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (83:6): [True: 0, False: 893]
  ------------------
   84|      0|		return rv;
   85|       |
   86|    893|	*object = list_seek(&sess->slot->objects, &hObject);
   87|    893|	if (!*object)
  ------------------
  |  Branch (87:6): [True: 168, False: 725]
  ------------------
   88|    168|		return CKR_OBJECT_HANDLE_INVALID;
  ------------------
  |  | 1124|    168|#define CKR_OBJECT_HANDLE_INVALID 0x00000082UL
  ------------------
   89|    725|	*session = sess;
   90|    725|	return CKR_OK;
  ------------------
  |  | 1086|    725|#define CKR_OK 0x00000000UL
  ------------------
   91|    893|}
pkcs11-object.c:sc_find_release:
   65|  1.47k|{
   66|  1.47k|	struct sc_pkcs11_find_operation *fop = (struct sc_pkcs11_find_operation *)operation;
   67|       |
   68|  1.47k|	if (fop->handles) {
  ------------------
  |  Branch (68:6): [True: 711, False: 767]
  ------------------
   69|    711|		free(fop->handles);
   70|       |		fop->handles = NULL;
   71|    711|	}
   72|  1.47k|}

get_session:
   31|  13.4k|{
   32|  13.4k|	*session = list_seek(&sessions, &hSession);
   33|  13.4k|	if (!*session)
  ------------------
  |  Branch (33:6): [True: 0, False: 13.4k]
  ------------------
   34|      0|		return CKR_SESSION_HANDLE_INVALID;
  ------------------
  |  | 1134|      0|#define CKR_SESSION_HANDLE_INVALID 0x000000B3UL
  ------------------
   35|  13.4k|	return CKR_OK;
  ------------------
  |  | 1086|  13.4k|#define CKR_OK 0x00000000UL
  ------------------
   36|  13.4k|}
C_OpenSession:
   43|  11.5k|{				/* receives new session handle */
   44|  11.5k|	CK_RV rv;
   45|  11.5k|	struct sc_pkcs11_slot *slot;
   46|  11.5k|	struct sc_pkcs11_session *session;
   47|       |
   48|  11.5k|	if (!(flags & CKF_SERIAL_SESSION))
  ------------------
  |  |  403|  11.5k|#define CKF_SERIAL_SESSION 0x00000004UL
  ------------------
  |  Branch (48:6): [True: 0, False: 11.5k]
  ------------------
   49|      0|		return CKR_SESSION_PARALLEL_NOT_SUPPORTED;
  ------------------
  |  | 1135|      0|#define CKR_SESSION_PARALLEL_NOT_SUPPORTED 0x000000B4UL
  ------------------
   50|       |
   51|  11.5k|	if (flags & ~(CKF_SERIAL_SESSION | CKF_RW_SESSION))
  ------------------
  |  |  403|  11.5k|#define CKF_SERIAL_SESSION 0x00000004UL
  ------------------
              	if (flags & ~(CKF_SERIAL_SESSION | CKF_RW_SESSION))
  ------------------
  |  |  402|  11.5k|#define CKF_RW_SESSION 0x00000002UL
  ------------------
  |  Branch (51:6): [True: 0, False: 11.5k]
  ------------------
   52|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
   53|       |
   54|  11.5k|	rv = sc_pkcs11_lock();
   55|  11.5k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  11.5k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (55:6): [True: 0, False: 11.5k]
  ------------------
   56|      0|		return rv;
   57|       |
   58|  11.5k|	sc_log(context, "C_OpenSession(0x%lx)", slotID);
  ------------------
  |  |   71|  11.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   59|       |
   60|  11.5k|	rv = slot_get_token(slotID, &slot);
   61|  11.5k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  11.5k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (61:6): [True: 1.16k, False: 10.3k]
  ------------------
   62|  1.16k|		goto out;
   63|       |
   64|       |	/* Check that no conflicting sessions exist */
   65|  10.3k|	if (!(flags & CKF_RW_SESSION) && (slot->login_user == CKU_SO)) {
  ------------------
  |  |  402|  10.3k|#define CKF_RW_SESSION 0x00000002UL
  ------------------
              	if (!(flags & CKF_RW_SESSION) && (slot->login_user == CKU_SO)) {
  ------------------
  |  | 1210|      0|#define CKU_SO 0UL
  ------------------
  |  Branch (65:6): [True: 0, False: 10.3k]
  |  Branch (65:35): [True: 0, False: 0]
  ------------------
   66|      0|		rv = CKR_SESSION_READ_WRITE_SO_EXISTS;
  ------------------
  |  | 1139|      0|#define CKR_SESSION_READ_WRITE_SO_EXISTS 0x000000B8UL
  ------------------
   67|      0|		goto out;
   68|      0|	}
   69|       |
   70|  10.3k|	session = (struct sc_pkcs11_session *)calloc(1, sizeof(struct sc_pkcs11_session));
   71|  10.3k|	if (session == NULL) {
  ------------------
  |  Branch (71:6): [True: 0, False: 10.3k]
  ------------------
   72|      0|		rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
   73|      0|		goto out;
   74|      0|	}
   75|       |
   76|       |	/* make session handle from pointer and check its uniqueness */
   77|  10.3k|	session->handle = (CK_SESSION_HANDLE)(uintptr_t)session;
   78|  10.3k|	if (list_seek(&sessions, &session->handle) != NULL) {
  ------------------
  |  Branch (78:6): [True: 0, False: 10.3k]
  ------------------
   79|      0|		sc_log(context, "C_OpenSession handle 0x%lx already exists", session->handle);
  ------------------
  |  |   71|      0|#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|       |
   81|      0|		free(session);
   82|       |
   83|      0|		rv = CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
   84|      0|		goto out;
   85|      0|	}
   86|       |
   87|  10.3k|	session->slot = slot;
   88|  10.3k|	session->notify_callback = Notify;
   89|  10.3k|	session->notify_data = pApplication;
   90|  10.3k|	session->flags = flags;
   91|  10.3k|	slot->nsessions++;
   92|  10.3k|	list_append(&sessions, session);
   93|  10.3k|	*phSession = session->handle;
   94|  10.3k|	sc_log(context, "C_OpenSession handle: 0x%lx", session->handle);
  ------------------
  |  |   71|  10.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   95|       |
   96|  11.5k|out:
   97|       |	SC_LOG_RV("C_OpenSession() = %s", rv);
  ------------------
  |  |  237|  11.5k|#define SC_LOG_RV(fmt, rv)\
  |  |  238|  11.5k|do {\
  |  |  239|  11.5k|        const char *name = lookup_enum(RV_T, (rv));\
  |  |  240|  11.5k|        if (name)\
  |  |  ------------------
  |  |  |  Branch (240:13): [True: 11.5k, False: 0]
  |  |  ------------------
  |  |  241|  11.5k|                sc_log(context, (fmt), name);\
  |  |  ------------------
  |  |  |  |   71|  11.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  242|  11.5k|        else {\
  |  |  243|      0|                size_t needed = snprintf(NULL, 0, "0x%08lX", (rv)) + 1;\
  |  |  244|      0|                char *buffer = malloc(needed);\
  |  |  245|      0|                if (buffer) {\
  |  |  ------------------
  |  |  |  Branch (245:21): [True: 0, False: 0]
  |  |  ------------------
  |  |  246|      0|                        sprintf(buffer, "0x%08lX", (rv));\
  |  |  247|      0|                        sc_log(context, (fmt), buffer);\
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  248|      0|                        free(buffer);\
  |  |  249|      0|                }\
  |  |  250|      0|        }\
  |  |  251|  11.5k|} while(0)
  |  |  ------------------
  |  |  |  Branch (251:9): [Folded, False: 11.5k]
  |  |  ------------------
  ------------------
   98|  11.5k|	sc_pkcs11_unlock();
   99|  11.5k|	return rv;
  100|  10.3k|}
sc_pkcs11_close_all_sessions:
  141|  15.7k|{
  142|  15.7k|	CK_RV rv = CKR_OK, error;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  143|  15.7k|	struct sc_pkcs11_session *session;
  144|  15.7k|	unsigned int i;
  145|  15.7k|	sc_log(context, "real C_CloseAllSessions(0x%lx) %d", slotID, list_size(&sessions));
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  146|  15.7k|	for (i = 0; i < list_size(&sessions); i++) {
  ------------------
  |  Branch (146:14): [True: 0, False: 15.7k]
  ------------------
  147|      0|		session = list_get_at(&sessions, i);
  148|      0|		if (session->slot->id == slotID)
  ------------------
  |  Branch (148:7): [True: 0, False: 0]
  ------------------
  149|      0|			if ((error = sc_pkcs11_close_session(session->handle)) != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (149:8): [True: 0, False: 0]
  ------------------
  150|      0|				rv = error;
  151|      0|	}
  152|  15.7k|	return rv;
  153|  15.7k|}
C_CloseSession:
  156|  10.3k|{				/* the session's handle */
  157|  10.3k|	CK_RV rv;
  158|       |
  159|  10.3k|	rv = sc_pkcs11_lock();
  160|  10.3k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  10.3k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (160:6): [True: 0, False: 10.3k]
  ------------------
  161|      0|		return rv;
  162|       |
  163|  10.3k|	sc_log(context, "C_CloseSession(0x%lx)", hSession);
  ------------------
  |  |   71|  10.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  164|       |
  165|  10.3k|	rv = sc_pkcs11_close_session(hSession);
  166|       |
  167|  10.3k|	sc_pkcs11_unlock();
  168|  10.3k|	return rv;
  169|  10.3k|}
C_Login:
  330|  3.32k|{				/* the length of the PIN */
  331|  3.32k|	CK_RV rv;
  332|  3.32k|	struct sc_pkcs11_session *session;
  333|  3.32k|	struct sc_pkcs11_slot *slot;
  334|       |
  335|  3.32k|	if (pPin == NULL_PTR && ulPinLen > 0)
  ------------------
  |  |   27|  6.65k|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (335:6): [True: 0, False: 3.32k]
  |  Branch (335:26): [True: 0, False: 0]
  ------------------
  336|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  337|       |
  338|  3.32k|	rv = sc_pkcs11_lock();
  339|  3.32k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  3.32k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (339:6): [True: 0, False: 3.32k]
  ------------------
  340|      0|		return rv;
  341|       |
  342|  3.32k|	if (userType != CKU_USER && userType != CKU_SO && userType != CKU_CONTEXT_SPECIFIC) {
  ------------------
  |  | 1211|  6.65k|#define CKU_USER 1UL
  ------------------
              	if (userType != CKU_USER && userType != CKU_SO && userType != CKU_CONTEXT_SPECIFIC) {
  ------------------
  |  | 1210|  6.01k|#define CKU_SO 0UL
  ------------------
              	if (userType != CKU_USER && userType != CKU_SO && userType != CKU_CONTEXT_SPECIFIC) {
  ------------------
  |  | 1212|  1.68k|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  |  Branch (342:6): [True: 2.68k, False: 638]
  |  Branch (342:30): [True: 1.68k, False: 1.00k]
  |  Branch (342:52): [True: 1.23k, False: 446]
  ------------------
  343|  1.23k|		rv = CKR_USER_TYPE_INVALID;
  ------------------
  |  | 1153|  1.23k|#define CKR_USER_TYPE_INVALID 0x00000103UL
  ------------------
  344|  1.23k|		goto out;
  345|  1.23k|	}
  346|  2.09k|	session = list_seek(&sessions, &hSession);
  347|  2.09k|	if (!session) {
  ------------------
  |  Branch (347:6): [True: 0, False: 2.09k]
  ------------------
  348|      0|		rv = CKR_SESSION_HANDLE_INVALID;
  ------------------
  |  | 1134|      0|#define CKR_SESSION_HANDLE_INVALID 0x000000B3UL
  ------------------
  349|      0|		goto out;
  350|      0|	}
  351|       |
  352|  2.09k|	sc_log(context, "C_Login(0x%lx, %lu)", hSession, userType);
  ------------------
  |  |   71|  2.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  353|       |
  354|  2.09k|	slot = session->slot;
  355|       |
  356|  2.09k|	if (!(slot->token_info.flags & CKF_USER_PIN_INITIALIZED) && userType == CKU_USER) {
  ------------------
  |  |  415|  2.09k|#define CKF_USER_PIN_INITIALIZED 0x00000008UL
  ------------------
              	if (!(slot->token_info.flags & CKF_USER_PIN_INITIALIZED) && userType == CKU_USER) {
  ------------------
  |  | 1211|    575|#define CKU_USER 1UL
  ------------------
  |  Branch (356:6): [True: 575, False: 1.51k]
  |  Branch (356:62): [True: 300, False: 275]
  ------------------
  357|    300|		rv = CKR_USER_PIN_NOT_INITIALIZED;
  ------------------
  |  | 1152|    300|#define CKR_USER_PIN_NOT_INITIALIZED 0x00000102UL
  ------------------
  358|    300|		goto out;
  359|    300|	}
  360|       |
  361|       |	/* TODO: check if context specific is valid */
  362|  1.79k|	if (userType == CKU_CONTEXT_SPECIFIC) {
  ------------------
  |  | 1212|  1.79k|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  |  Branch (362:6): [True: 446, False: 1.34k]
  ------------------
  363|    446|		if (slot->login_user == -1) {
  ------------------
  |  Branch (363:7): [True: 34, False: 412]
  ------------------
  364|     34|			rv = CKR_OPERATION_NOT_INITIALIZED;
  ------------------
  |  | 1126|     34|#define CKR_OPERATION_NOT_INITIALIZED 0x00000091UL
  ------------------
  365|     34|		}
  366|    412|		else   {
  367|    412|			rv = restore_login_state(slot);
  368|    412|			if (rv == CKR_OK && slot->p11card && slot->p11card->framework)
  ------------------
  |  | 1086|    824|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (368:8): [True: 412, False: 0]
  |  Branch (368:24): [True: 412, False: 0]
  |  Branch (368:41): [True: 412, False: 0]
  ------------------
  369|    412|				rv = slot->p11card->framework->login(slot, userType, pPin, ulPinLen);
  370|    412|			rv = reset_login_state(slot, rv);
  371|    412|		}
  372|    446|	}
  373|  1.34k|	else {
  374|  1.34k|		sc_log(context, "C_Login() slot->login_user %i", slot->login_user);
  ------------------
  |  |   71|  1.34k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  375|  1.34k|		if (slot->login_user >= 0) {
  ------------------
  |  Branch (375:7): [True: 0, False: 1.34k]
  ------------------
  376|      0|			if ((CK_USER_TYPE) slot->login_user == userType)
  ------------------
  |  Branch (376:8): [True: 0, False: 0]
  ------------------
  377|      0|				rv = CKR_USER_ALREADY_LOGGED_IN;
  ------------------
  |  | 1150|      0|#define CKR_USER_ALREADY_LOGGED_IN 0x00000100UL
  ------------------
  378|      0|			else
  379|      0|				rv = CKR_USER_ANOTHER_ALREADY_LOGGED_IN;
  ------------------
  |  | 1154|      0|#define CKR_USER_ANOTHER_ALREADY_LOGGED_IN 0x00000104UL
  ------------------
  380|      0|			goto out;
  381|      0|		}
  382|       |
  383|  1.34k|		rv = restore_login_state(slot);
  384|  1.34k|		if (rv == CKR_OK) {
  ------------------
  |  | 1086|  1.34k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (384:7): [True: 1.34k, False: 0]
  ------------------
  385|  1.34k|			sc_log(context, "C_Login() userType %li", userType);
  ------------------
  |  |   71|  1.34k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  386|  1.34k|			if (slot->p11card == NULL)
  ------------------
  |  Branch (386:8): [True: 0, False: 1.34k]
  ------------------
  387|      0|				return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  388|  1.34k|			rv = slot->p11card->framework->login(slot, userType, pPin, ulPinLen);
  389|  1.34k|			sc_log(context, "fLogin() rv %li", rv);
  ------------------
  |  |   71|  1.34k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  390|  1.34k|		}
  391|  1.34k|		if (rv == CKR_OK)
  ------------------
  |  | 1086|  1.34k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (391:7): [True: 865, False: 481]
  ------------------
  392|    865|			rv = push_login_state(slot, userType, pPin, ulPinLen);
  393|  1.34k|		if (rv == CKR_OK) {
  ------------------
  |  | 1086|  1.34k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (393:7): [True: 865, False: 481]
  ------------------
  394|    865|			slot->login_user = (int) userType;
  395|    865|		}
  396|  1.34k|		rv = reset_login_state(slot, rv);
  397|  1.34k|	}
  398|       |
  399|  3.32k|out:
  400|  3.32k|	sc_pkcs11_unlock();
  401|  3.32k|	return rv;
  402|  1.79k|}
C_InitPIN:
  453|    305|{
  454|    305|	CK_RV rv;
  455|    305|	struct sc_pkcs11_session *session;
  456|    305|	struct sc_pkcs11_slot *slot;
  457|       |
  458|    305|	sc_log(context, "C_InitPIN() called, pin '%s'", pPin ? (char *) pPin : "<null>");
  ------------------
  |  |   71|    610|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 305, False: 0]
  |  |  ------------------
  ------------------
  459|    305|	if (pPin == NULL_PTR && ulPinLen > 0)
  ------------------
  |  |   27|    610|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (459:6): [True: 0, False: 305]
  |  Branch (459:26): [True: 0, False: 0]
  ------------------
  460|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  461|       |
  462|    305|	rv = sc_pkcs11_lock();
  463|    305|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    305|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (463:6): [True: 0, False: 305]
  ------------------
  464|      0|		return rv;
  465|       |
  466|    305|	session = list_seek(&sessions, &hSession);
  467|    305|	if (!session) {
  ------------------
  |  Branch (467:6): [True: 0, False: 305]
  ------------------
  468|      0|		rv = CKR_SESSION_HANDLE_INVALID;
  ------------------
  |  | 1134|      0|#define CKR_SESSION_HANDLE_INVALID 0x000000B3UL
  ------------------
  469|      0|		goto out;
  470|      0|	}
  471|       |
  472|    305|	if (!(session->flags & CKF_RW_SESSION)) {
  ------------------
  |  |  402|    305|#define CKF_RW_SESSION 0x00000002UL
  ------------------
  |  Branch (472:6): [True: 0, False: 305]
  ------------------
  473|      0|		rv = CKR_SESSION_READ_ONLY;
  ------------------
  |  | 1136|      0|#define CKR_SESSION_READ_ONLY 0x000000B5UL
  ------------------
  474|      0|		goto out;
  475|      0|	}
  476|       |
  477|    305|	slot = session->slot;
  478|    305|	if (slot->login_user != CKU_SO) {
  ------------------
  |  | 1210|    305|#define CKU_SO 0UL
  ------------------
  |  Branch (478:6): [True: 160, False: 145]
  ------------------
  479|    160|		rv = CKR_USER_NOT_LOGGED_IN;
  ------------------
  |  | 1151|    160|#define CKR_USER_NOT_LOGGED_IN 0x00000101UL
  ------------------
  480|    160|	} else if (slot->p11card == NULL || slot->p11card->framework->init_pin == NULL) {
  ------------------
  |  Branch (480:13): [True: 0, False: 145]
  |  Branch (480:38): [True: 0, False: 145]
  ------------------
  481|      0|		rv = CKR_FUNCTION_NOT_SUPPORTED;
  ------------------
  |  | 1111|      0|#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054UL
  ------------------
  482|    145|	} else {
  483|    145|		rv = restore_login_state(slot);
  484|    145|		if (rv == CKR_OK) {
  ------------------
  |  | 1086|    145|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (484:7): [True: 145, False: 0]
  ------------------
  485|    145|			rv = slot->p11card->framework->init_pin(slot, pPin, ulPinLen);
  486|    145|			sc_log(context, "C_InitPIN() init-pin result %li", rv);
  ------------------
  |  |   71|    145|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  487|    145|		}
  488|    145|		rv = reset_login_state(slot, rv);
  489|    145|	}
  490|       |
  491|    305|out:
  492|    305|	sc_pkcs11_unlock();
  493|    305|	return rv;
  494|    305|}
C_SetPIN:
  498|    816|{
  499|    816|	CK_RV rv;
  500|    816|	struct sc_pkcs11_session *session;
  501|    816|	struct sc_pkcs11_slot *slot;
  502|       |
  503|    816|	if ((pOldPin == NULL_PTR && ulOldLen > 0) || (pNewPin == NULL_PTR && ulNewLen > 0))
  ------------------
  |  |   27|  1.63k|#define NULL_PTR ((void *)0)
  ------------------
              	if ((pOldPin == NULL_PTR && ulOldLen > 0) || (pNewPin == NULL_PTR && ulNewLen > 0))
  ------------------
  |  |   27|  1.63k|#define NULL_PTR ((void *)0)
  ------------------
  |  Branch (503:7): [True: 0, False: 816]
  |  Branch (503:30): [True: 0, False: 0]
  |  Branch (503:48): [True: 0, False: 816]
  |  Branch (503:71): [True: 0, False: 0]
  ------------------
  504|      0|		return CKR_ARGUMENTS_BAD;
  ------------------
  |  | 1092|      0|#define CKR_ARGUMENTS_BAD 0x00000007UL
  ------------------
  505|       |
  506|    816|	rv = sc_pkcs11_lock();
  507|    816|	if (rv != CKR_OK)
  ------------------
  |  | 1086|    816|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (507:6): [True: 0, False: 816]
  ------------------
  508|      0|		return rv;
  509|       |
  510|    816|	session = list_seek(&sessions, &hSession);
  511|    816|	if (!session) {
  ------------------
  |  Branch (511:6): [True: 0, False: 816]
  ------------------
  512|      0|		rv = CKR_SESSION_HANDLE_INVALID;
  ------------------
  |  | 1134|      0|#define CKR_SESSION_HANDLE_INVALID 0x000000B3UL
  ------------------
  513|      0|		goto out;
  514|      0|	}
  515|       |
  516|    816|	slot = session->slot;
  517|    816|	sc_log(context, "Changing PIN (session 0x%lx; login user %d)", hSession, slot->login_user);
  ------------------
  |  |   71|    816|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  518|       |
  519|    816|	if (!(session->flags & CKF_RW_SESSION)) {
  ------------------
  |  |  402|    816|#define CKF_RW_SESSION 0x00000002UL
  ------------------
  |  Branch (519:6): [True: 0, False: 816]
  ------------------
  520|      0|		rv = CKR_SESSION_READ_ONLY;
  ------------------
  |  | 1136|      0|#define CKR_SESSION_READ_ONLY 0x000000B5UL
  ------------------
  521|      0|		goto out;
  522|      0|	}
  523|       |
  524|    816|	rv = restore_login_state(slot);
  525|    816|	if (rv == CKR_OK) {
  ------------------
  |  | 1086|    816|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (525:6): [True: 816, False: 0]
  ------------------
  526|    816|		if (slot->p11card == NULL)
  ------------------
  |  Branch (526:7): [True: 0, False: 816]
  ------------------
  527|      0|			return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  528|    816|		rv = slot->p11card->framework->change_pin(slot, pOldPin, ulOldLen, pNewPin, ulNewLen);
  529|    816|	}
  530|    816|	rv = reset_login_state(slot, rv);
  531|       |
  532|    816|out:
  533|    816|	sc_pkcs11_unlock();
  534|    816|	return rv;
  535|    816|}
pkcs11-session.c:sc_pkcs11_close_session:
  105|  10.3k|{
  106|  10.3k|	struct sc_pkcs11_slot *slot;
  107|  10.3k|	struct sc_pkcs11_session *session;
  108|       |
  109|  10.3k|	sc_log(context, "real C_CloseSession(0x%lx)", hSession);
  ------------------
  |  |   71|  10.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  110|       |
  111|  10.3k|	session = list_seek(&sessions, &hSession);
  112|  10.3k|	if (!session)
  ------------------
  |  Branch (112:6): [True: 0, False: 10.3k]
  ------------------
  113|      0|		return CKR_SESSION_HANDLE_INVALID;
  ------------------
  |  | 1134|      0|#define CKR_SESSION_HANDLE_INVALID 0x000000B3UL
  ------------------
  114|       |
  115|       |	/* If we're the last session using this slot, make sure
  116|       |	 * we log out */
  117|  10.3k|	slot = session->slot;
  118|  10.3k|	slot->nsessions--;
  119|  10.3k|	if (slot->nsessions == 0 && slot->login_user >= 0) {
  ------------------
  |  Branch (119:6): [True: 10.3k, False: 0]
  |  Branch (119:30): [True: 858, False: 9.50k]
  ------------------
  120|    858|		slot->login_user = -1;
  121|    858|		if (sc_pkcs11_conf.atomic)
  ------------------
  |  Branch (121:7): [True: 0, False: 858]
  ------------------
  122|      0|			pop_all_login_states(slot);
  123|    858|		else {
  124|    858|			if (slot->p11card == NULL)
  ------------------
  |  Branch (124:8): [True: 0, False: 858]
  ------------------
  125|      0|				return CKR_TOKEN_NOT_RECOGNIZED;
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  126|    858|			slot->p11card->framework->logout(slot);
  127|    858|		}
  128|    858|	}
  129|   103k|	for (size_t i = 0; i < SC_PKCS11_OPERATION_MAX; i++)
  ------------------
  |  Branch (129:21): [True: 93.2k, False: 10.3k]
  ------------------
  130|  93.2k|		sc_pkcs11_release_operation(&session->operation[i]);
  131|       |
  132|  10.3k|	if (list_delete(&sessions, session) != 0)
  ------------------
  |  Branch (132:6): [True: 0, False: 10.3k]
  ------------------
  133|      0|		sc_log(context, "Could not delete session from list!");
  ------------------
  |  |   71|      0|#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|  10.3k|	free(session);
  135|  10.3k|	return CKR_OK;
  ------------------
  |  | 1086|  10.3k|#define CKR_OK 0x00000000UL
  ------------------
  136|  10.3k|}

_debug_virtual_slots:
   32|  15.7k|{
   33|  15.7k|	int i, vs_size;
   34|  15.7k|	sc_pkcs11_slot_t * slot;
   35|       |
   36|  15.7k|	vs_size = list_size(&virtual_slots);
   37|  15.7k|	_sc_debug(context, 10,
   38|  15.7k|			"VSS size:%d", vs_size);
   39|  15.7k|	_sc_debug(context, 10,
   40|  15.7k|			"VSS  [i] id   flags LU events nsessions slot_info.flags reader p11card description");
   41|  31.5k|	for (i = 0; i < vs_size; i++) {
  ------------------
  |  Branch (41:14): [True: 15.7k, False: 15.7k]
  ------------------
   42|  15.7k|		slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
   43|  15.7k|		if (slot) {
  ------------------
  |  Branch (43:7): [True: 15.7k, False: 0]
  ------------------
   44|  15.7k|			_sc_debug(context, 10,
   45|  15.7k|				"VSS %s[%d] 0x%2.2lx 0x%4.4x %d  %d  %d %4.4lx  %p %p %.64s",
   46|  15.7k|				((slot == p) ? "*" : " "),
  ------------------
  |  Branch (46:6): [True: 15.7k, False: 0]
  ------------------
   47|  15.7k|				i, slot->id, slot->flags, slot->login_user, slot->events, slot->nsessions,
   48|  15.7k|				slot->slot_info.flags,
   49|  15.7k|				slot->reader, slot->p11card,
   50|  15.7k|				slot->slot_info.slotDescription);
   51|  15.7k|		}
   52|  15.7k|	}
   53|  15.7k|	_sc_debug(context, 10, "VSS END");
   54|  15.7k|}
init_slot_info:
   92|  28.5k|{
   93|  28.5k|	if (reader) {
  ------------------
  |  Branch (93:6): [True: 28.5k, False: 0]
  ------------------
   94|  28.5k|		strcpy_bp(pInfo->slotDescription, reader->name, 64);
   95|  28.5k|		strcpy_bp(pInfo->manufacturerID, reader->vendor, 32);
   96|  28.5k|		pInfo->hardwareVersion.major = reader->version_major;
   97|  28.5k|		pInfo->hardwareVersion.minor = reader->version_minor;
   98|  28.5k|	} else {
   99|      0|		strcpy_bp(pInfo->slotDescription, "Virtual hotplug slot", 64);
  100|      0|		strcpy_bp(pInfo->manufacturerID, OPENSC_VS_FF_COMPANY_NAME, 32);
  ------------------
  |  |  244|      0|#define OPENSC_VS_FF_COMPANY_NAME "OpenSC Project"
  ------------------
  101|      0|		pInfo->hardwareVersion.major = OPENSC_VERSION_MAJOR;
  ------------------
  |  |  232|      0|#define OPENSC_VERSION_MAJOR 0
  ------------------
  102|      0|		pInfo->hardwareVersion.minor = OPENSC_VERSION_MINOR;
  ------------------
  |  |  235|      0|#define OPENSC_VERSION_MINOR 27
  ------------------
  103|      0|	}
  104|  28.5k|	pInfo->flags = CKF_REMOVABLE_DEVICE | CKF_HW_SLOT;
  ------------------
  |  |  408|  28.5k|#define CKF_REMOVABLE_DEVICE 0x00000002UL
  ------------------
              	pInfo->flags = CKF_REMOVABLE_DEVICE | CKF_HW_SLOT;
  ------------------
  |  |  409|  28.5k|#define CKF_HW_SLOT 0x00000004UL
  ------------------
  105|  28.5k|	pInfo->firmwareVersion.major = 0;
  106|  28.5k|	pInfo->firmwareVersion.minor = 0;
  107|  28.5k|}
create_slot:
  122|  15.7k|{
  123|  15.7k|	unsigned int events;
  124|  15.7k|	sc_reader_t *found;
  125|       |	/* find unused slots previously allocated for the same reader */
  126|  15.7k|	struct sc_pkcs11_slot *slot = reader_reclaim_slot(reader);
  127|       |
  128|       |	/* create a new slot if no empty slot is available */
  129|  15.7k|	if (!slot) {
  ------------------
  |  Branch (129:6): [True: 15.7k, False: 0]
  ------------------
  130|  15.7k|		sc_log(context, "Creating new slot");
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  131|  15.7k|		if (list_size(&virtual_slots) >= sc_pkcs11_conf.max_virtual_slots)
  ------------------
  |  Branch (131:7): [True: 0, False: 15.7k]
  ------------------
  132|      0|			return CKR_FUNCTION_FAILED;
  ------------------
  |  | 1091|      0|#define CKR_FUNCTION_FAILED 0x00000006UL
  ------------------
  133|       |
  134|  15.7k|		slot = (struct sc_pkcs11_slot *)calloc(1, sizeof(struct sc_pkcs11_slot));
  135|  15.7k|		if (!slot)
  ------------------
  |  Branch (135:7): [True: 0, False: 15.7k]
  ------------------
  136|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  137|       |
  138|  15.7k|		list_append(&virtual_slots, slot);
  139|  15.7k|		if (0 != list_init(&slot->objects)) {
  ------------------
  |  Branch (139:7): [True: 0, False: 15.7k]
  ------------------
  140|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  141|      0|		}
  142|  15.7k|		list_attributes_seeker(&slot->objects, object_list_seeker);
  143|       |
  144|  15.7k|		if (0 != list_init(&slot->logins)) {
  ------------------
  |  Branch (144:7): [True: 0, False: 15.7k]
  ------------------
  145|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  146|      0|		}
  147|  15.7k|	} else {
  148|      0|		DEBUG_VSS(slot, "Reusing this old slot");
  ------------------
  |  |  260|      0|#define DEBUG_VSS(S, ...) do { sc_log(context,"VSS " __VA_ARGS__); _debug_virtual_slots(S); } while (0)
  |  |  ------------------
  |  |  |  |   71|      0|#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 (260:102): [Folded, False: 0]
  |  |  ------------------
  ------------------
  149|       |
  150|       |		/* reuse the old list of logins/objects since they should be empty */
  151|      0|		list_t logins = slot->logins;
  152|      0|		list_t objects = slot->objects;
  153|       |
  154|      0|		memset(slot, 0, sizeof *slot);
  155|       |
  156|      0|		slot->logins = logins;
  157|      0|		slot->objects = objects;
  158|      0|	}
  159|       |
  160|  15.7k|	slot->login_user = -1;
  161|  15.7k|	slot->id = (CK_SLOT_ID) list_locate(&virtual_slots, slot);
  162|  15.7k|	init_slot_info(&slot->slot_info, reader);
  163|  15.7k|	slot->reader = reader;
  164|  15.7k|	sc_wait_for_event(context, SC_EVENT_CARD_EVENTS | SC_EVENT_READER_EVENTS, &found, &events, 0, &slot->reader_events);
  ------------------
  |  |  215|  15.7k|#define SC_EVENT_CARD_EVENTS		(SC_EVENT_CARD_INSERTED|SC_EVENT_CARD_REMOVED)
  |  |  ------------------
  |  |  |  |  213|  15.7k|#define SC_EVENT_CARD_INSERTED		0x0001
  |  |  ------------------
  |  |               #define SC_EVENT_CARD_EVENTS		(SC_EVENT_CARD_INSERTED|SC_EVENT_CARD_REMOVED)
  |  |  ------------------
  |  |  |  |  214|  15.7k|#define SC_EVENT_CARD_REMOVED		0x0002
  |  |  ------------------
  ------------------
              	sc_wait_for_event(context, SC_EVENT_CARD_EVENTS | SC_EVENT_READER_EVENTS, &found, &events, 0, &slot->reader_events);
  ------------------
  |  |  218|  15.7k|#define SC_EVENT_READER_EVENTS		(SC_EVENT_READER_ATTACHED|SC_EVENT_READER_DETACHED)
  |  |  ------------------
  |  |  |  |  216|  15.7k|#define SC_EVENT_READER_ATTACHED	0x0004
  |  |  ------------------
  |  |               #define SC_EVENT_READER_EVENTS		(SC_EVENT_READER_ATTACHED|SC_EVENT_READER_DETACHED)
  |  |  ------------------
  |  |  |  |  217|  15.7k|#define SC_EVENT_READER_DETACHED	0x0008
  |  |  ------------------
  ------------------
  165|       |
  166|  15.7k|	DEBUG_VSS(slot, "Finished initializing this slot");
  ------------------
  |  |  260|  15.7k|#define DEBUG_VSS(S, ...) do { sc_log(context,"VSS " __VA_ARGS__); _debug_virtual_slots(S); } while (0)
  |  |  ------------------
  |  |  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (260:102): [Folded, False: 15.7k]
  |  |  ------------------
  ------------------
  167|       |
  168|  15.7k|	return CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  169|  15.7k|}
sc_pkcs11_card_free:
  172|  21.1k|{
  173|  21.1k|	if (p11card) {
  ------------------
  |  Branch (173:6): [True: 15.7k, False: 5.40k]
  ------------------
  174|  15.7k|		size_t i;
  175|  15.7k|		if (p11card->framework && p11card->framework->unbind)
  ------------------
  |  Branch (175:7): [True: 12.7k, False: 3.02k]
  |  Branch (175:29): [True: 12.7k, False: 0]
  ------------------
  176|  12.7k|			p11card->framework->unbind(p11card);
  177|  15.7k|		sc_disconnect_card(p11card->card);
  178|   140k|		for (i=0; i < p11card->nmechanisms; ++i) {
  ------------------
  |  Branch (178:13): [True: 125k, False: 15.7k]
  ------------------
  179|   125k|			if (p11card->mechanisms[i]->free_mech_data) {
  ------------------
  |  Branch (179:8): [True: 94.7k, False: 30.3k]
  ------------------
  180|  94.7k|				p11card->mechanisms[i]->free_mech_data(p11card->mechanisms[i]->mech_data);
  181|  94.7k|			}
  182|   125k|			free(p11card->mechanisms[i]);
  183|   125k|		}
  184|  15.7k|		free(p11card->mechanisms);
  185|  15.7k|		free(p11card);
  186|  15.7k|	}
  187|  21.1k|}
card_removed:
  190|  15.7k|{
  191|  15.7k|	unsigned int i;
  192|  15.7k|	struct sc_pkcs11_card *p11card = NULL;
  193|       |	/* Mark all slots as "token not present" */
  194|  15.7k|	sc_log(context, "%s: card removed", reader->name);
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  195|       |
  196|       |
  197|  31.5k|	for (i=0; i < list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (197:12): [True: 15.7k, False: 15.7k]
  ------------------
  198|  15.7k|		sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
  199|  15.7k|		if (slot->reader == reader) {
  ------------------
  |  Branch (199:7): [True: 15.7k, False: 0]
  ------------------
  200|       |			/* Save the "card" object */
  201|  15.7k|			if (slot->p11card)
  ------------------
  |  Branch (201:8): [True: 10.3k, False: 5.40k]
  ------------------
  202|  10.3k|				p11card = slot->p11card;
  203|  15.7k|			slot_token_removed(slot->id);
  204|  15.7k|		}
  205|  15.7k|	}
  206|       |
  207|  15.7k|	sc_pkcs11_card_free(p11card);
  208|       |
  209|  15.7k|	return CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  210|  15.7k|}
card_detect:
  214|  1.16k|{
  215|  1.16k|	struct sc_pkcs11_card *p11card = NULL;
  216|  1.16k|	int free_p11card = 0;
  217|  1.16k|	int rc;
  218|  1.16k|	int no_change = 0;
  219|  1.16k|	CK_RV rv;
  220|  1.16k|	unsigned int i;
  221|  1.16k|	int j;
  222|  1.16k|	static int retry = 3;
  223|       |
  224|  1.16k|	sc_log(context, "%s: Detecting smart card", reader->name);
  ------------------
  |  |   71|  1.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  225|       |	/* Check if someone inserted a card */
  226|       |
  227|  1.16k|	if (reader_states != NULL) {
  ------------------
  |  Branch (227:6): [True: 0, False: 1.16k]
  ------------------
  228|       |		/* check if any event has occurred since last invocation of `card_detect()` */
  229|      0|		unsigned int mask, events;
  230|      0|		sc_reader_t *event_reader;
  231|       |		/* Detect card and reader events */
  232|      0|		mask = SC_EVENT_CARD_EVENTS | SC_EVENT_READER_EVENTS;
  ------------------
  |  |  215|      0|#define SC_EVENT_CARD_EVENTS		(SC_EVENT_CARD_INSERTED|SC_EVENT_CARD_REMOVED)
  |  |  ------------------
  |  |  |  |  213|      0|#define SC_EVENT_CARD_INSERTED		0x0001
  |  |  ------------------
  |  |               #define SC_EVENT_CARD_EVENTS		(SC_EVENT_CARD_INSERTED|SC_EVENT_CARD_REMOVED)
  |  |  ------------------
  |  |  |  |  214|      0|#define SC_EVENT_CARD_REMOVED		0x0002
  |  |  ------------------
  ------------------
              		mask = SC_EVENT_CARD_EVENTS | SC_EVENT_READER_EVENTS;
  ------------------
  |  |  218|      0|#define SC_EVENT_READER_EVENTS		(SC_EVENT_READER_ATTACHED|SC_EVENT_READER_DETACHED)
  |  |  ------------------
  |  |  |  |  216|      0|#define SC_EVENT_READER_ATTACHED	0x0004
  |  |  ------------------
  |  |               #define SC_EVENT_READER_EVENTS		(SC_EVENT_READER_ATTACHED|SC_EVENT_READER_DETACHED)
  |  |  ------------------
  |  |  |  |  217|      0|#define SC_EVENT_READER_DETACHED	0x0008
  |  |  ------------------
  ------------------
  233|      0|		int r = sc_wait_for_event(context, mask, &event_reader, &events, 0, &reader_states);
  234|      0|		if (r == SC_ERROR_EVENT_TIMEOUT || reader != event_reader)
  ------------------
  |  |   43|      0|#define SC_ERROR_EVENT_TIMEOUT			-1112
  ------------------
  |  Branch (234:7): [True: 0, False: 0]
  |  Branch (234:38): [True: 0, False: 0]
  ------------------
  235|       |			/* no change happened */
  236|      0|			no_change = 1;
  237|      0|		else
  238|       |			/* if some error occurred or there actually was a change, continue with detection routine */
  239|      0|			no_change = 0;
  240|      0|	}
  241|       |
  242|  1.16k|again:
  243|  1.16k|	rc = sc_detect_card_presence(reader);
  244|  1.16k|	if (rc < 0) {
  ------------------
  |  Branch (244:6): [True: 1.16k, False: 0]
  ------------------
  245|  1.16k|		sc_log(context, "%s: failed, %s", reader->name, sc_strerror(rc));
  ------------------
  |  |   71|  1.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  246|  1.16k|		return sc_to_cryptoki_error(rc, NULL);
  247|  1.16k|	}
  248|      0|	if (rc == 0) {
  ------------------
  |  Branch (248:6): [True: 0, False: 0]
  ------------------
  249|      0|		sc_log(context, "%s: card absent", reader->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__
  |  |  ------------------
  ------------------
  250|      0|		card_removed(reader);	/* Release all resources */
  251|      0|		return CKR_TOKEN_NOT_PRESENT;
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
  252|      0|	}
  253|       |
  254|      0|	if (no_change == 1) {
  ------------------
  |  Branch (254:6): [True: 0, False: 0]
  ------------------
  255|      0|		sc_log(context, "%s: card present, no change detected", reader->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__
  |  |  ------------------
  ------------------
  256|      0|		return CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  257|      0|	}
  258|       |
  259|       |	/* If the card was changed, disconnect the current one */
  260|      0|	if (rc & SC_READER_CARD_CHANGED) {
  ------------------
  |  |  367|      0|#define SC_READER_CARD_CHANGED		0x00000002
  ------------------
  |  Branch (260:6): [True: 0, False: 0]
  ------------------
  261|      0|		sc_log(context, "%s: Card changed", reader->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__
  |  |  ------------------
  ------------------
  262|       |		/* The following should never happen - but if it
  263|       |		 * does we'll be stuck in an endless loop.
  264|       |		 * So better be fussy.*/
  265|      0|		card_removed(reader);
  266|      0|		if (!retry--) {
  ------------------
  |  Branch (266:7): [True: 0, False: 0]
  ------------------
  267|      0|			retry = 3;
  268|      0|			return CKR_TOKEN_NOT_PRESENT;
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
  269|      0|		}
  270|      0|		goto again;
  271|      0|	}
  272|       |
  273|       |	/* Locate a slot related to the reader */
  274|      0|	for (i=0; i<list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (274:12): [True: 0, False: 0]
  ------------------
  275|      0|		sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
  276|      0|		if (slot->reader == reader) {
  ------------------
  |  Branch (276:7): [True: 0, False: 0]
  ------------------
  277|      0|			p11card = slot->p11card;
  278|      0|			break;
  279|      0|		}
  280|      0|	}
  281|       |
  282|       |	/* Detect the card if it's not known already */
  283|      0|	if (p11card == NULL) {
  ------------------
  |  Branch (283:6): [True: 0, False: 0]
  ------------------
  284|      0|		sc_log(context, "%s: First seen the card ", reader->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|		p11card = (struct sc_pkcs11_card *)calloc(1, sizeof(struct sc_pkcs11_card));
  286|      0|		if (!p11card)
  ------------------
  |  Branch (286:7): [True: 0, False: 0]
  ------------------
  287|      0|			return CKR_HOST_MEMORY;
  ------------------
  |  | 1088|      0|#define CKR_HOST_MEMORY 0x00000002UL
  ------------------
  288|      0|		free_p11card = 1;
  289|      0|		p11card->reader = reader;
  290|      0|	}
  291|       |
  292|      0|	if (p11card->card == NULL) {
  ------------------
  |  Branch (292:6): [True: 0, False: 0]
  ------------------
  293|      0|		sc_log(context, "%s: Connecting ... ", reader->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__
  |  |  ------------------
  ------------------
  294|      0|		rc = sc_connect_card(reader, &p11card->card);
  295|      0|		if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (295:7): [True: 0, False: 0]
  ------------------
  296|      0|			sc_log(context, "%s: SC connect card error %i", reader->name, rc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  297|      0|			rv = sc_to_cryptoki_error(rc, NULL);
  298|      0|			goto fail;
  299|      0|		}
  300|       |
  301|       |		/* escape commands are only guaranteed to be working with a card
  302|       |		 * inserted. That's why by now, after sc_connect_card() the reader's
  303|       |		 * metadata may have changed. We re-initialize the metadata for every
  304|       |		 * slot of this reader here. */
  305|      0|		if (reader->flags & SC_READER_ENABLE_ESCAPE) {
  ------------------
  |  |  372|      0|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (305:7): [True: 0, False: 0]
  ------------------
  306|      0|			for (i = 0; i<list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (306:16): [True: 0, False: 0]
  ------------------
  307|      0|				sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
  308|      0|				if (slot->reader == reader)
  ------------------
  |  Branch (308:9): [True: 0, False: 0]
  ------------------
  309|      0|					init_slot_info(&slot->slot_info, reader);
  310|      0|			}
  311|      0|		}
  312|       |
  313|      0|		sc_log(context, "%s: Connected SC card %p", reader->name, p11card->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__
  |  |  ------------------
  ------------------
  314|      0|	}
  315|       |
  316|       |	/* Detect the framework */
  317|      0|	if (p11card->framework == NULL) {
  ------------------
  |  Branch (317:6): [True: 0, False: 0]
  ------------------
  318|      0|		struct sc_app_info *app_generic = sc_pkcs15_get_application_by_type(p11card->card, "generic");
  319|       |
  320|      0|		sc_log(context, "%s: Detecting Framework. %i on-card applications", reader->name, p11card->card->app_count);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  321|      0|		sc_log(context, "%s: generic application %s", reader->name, app_generic ? app_generic->label : "<none>");
  ------------------
  |  |   71|      0|#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]
  |  |  ------------------
  ------------------
  322|       |
  323|      0|		for (i = 0; frameworks[i]; i++)
  ------------------
  |  Branch (323:15): [True: 0, False: 0]
  ------------------
  324|      0|			if (frameworks[i]->bind != NULL)
  ------------------
  |  Branch (324:8): [True: 0, False: 0]
  ------------------
  325|      0|				break;
  326|       |		/*TODO: only first framework is used: pkcs15init framework is not reachable here */
  327|      0|		if (frameworks[i] == NULL) {
  ------------------
  |  Branch (327:7): [True: 0, False: 0]
  ------------------
  328|      0|			rv = CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|      0|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  329|      0|			goto fail;
  330|      0|		}
  331|       |
  332|      0|		p11card->framework = frameworks[i];
  333|       |
  334|       |		/* Initialize framework */
  335|      0|		sc_log(context, "%s: Detected framework %d. Creating tokens.", reader->name, 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__
  |  |  ------------------
  ------------------
  336|       |		/* Bind 'generic' application or (emulated?) card without applications */
  337|      0|		if (app_generic || !p11card->card->app_count)   {
  ------------------
  |  Branch (337:7): [True: 0, False: 0]
  |  Branch (337:22): [True: 0, False: 0]
  ------------------
  338|      0|			scconf_block *conf_block = NULL;
  339|      0|			int enable_InitToken = 0;
  340|       |
  341|      0|			conf_block = sc_match_atr_block(p11card->card->ctx, NULL,
  342|      0|				&p11card->reader->atr);
  343|      0|			if (!conf_block) /* check default block */
  ------------------
  |  Branch (343:8): [True: 0, False: 0]
  ------------------
  344|      0|				conf_block = sc_get_conf_block(context,
  345|      0|					"framework", "pkcs15", 1);
  346|       |
  347|      0|			enable_InitToken = scconf_get_bool(conf_block,
  348|      0|				"pkcs11_enable_InitToken", 0);
  349|       |
  350|      0|			sc_log(context, "%s: Try to bind 'generic' token.", reader->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__
  |  |  ------------------
  ------------------
  351|      0|			rv = frameworks[i]->bind(p11card, app_generic);
  352|      0|			if (rv == CKR_TOKEN_NOT_RECOGNIZED && enable_InitToken)   {
  ------------------
  |  | 1145|      0|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
  |  Branch (352:8): [True: 0, False: 0]
  |  Branch (352:42): [True: 0, False: 0]
  ------------------
  353|      0|				sc_log(context, "%s: 'InitToken' enabled -- accept non-binded card", reader->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__
  |  |  ------------------
  ------------------
  354|      0|				rv = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  355|      0|			}
  356|      0|			if (rv != CKR_OK)   {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (356:8): [True: 0, False: 0]
  ------------------
  357|      0|				sc_log(context,
  ------------------
  |  |   71|      0|#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|      0|				       "%s: cannot bind 'generic' token: rv 0x%lX",
  359|      0|				       reader->name, rv);
  360|      0|				goto fail;
  361|      0|			}
  362|       |
  363|      0|			sc_log(context, "%s: Creating 'generic' token.", reader->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__
  |  |  ------------------
  ------------------
  364|      0|			rv = frameworks[i]->create_tokens(p11card, app_generic);
  365|      0|			if (rv != CKR_OK)   {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (365:8): [True: 0, False: 0]
  ------------------
  366|      0|				sc_log(context,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  367|      0|				       "%s: create 'generic' token error 0x%lX",
  368|      0|				       reader->name, rv);
  369|      0|				goto fail;
  370|      0|			}
  371|       |			/* p11card is now bound to some slot */
  372|      0|			free_p11card = 0;
  373|      0|		}
  374|       |
  375|       |		/* Now bind the rest of applications that are not 'generic' */
  376|      0|		for (j = 0; j < p11card->card->app_count; j++)   {
  ------------------
  |  Branch (376:15): [True: 0, False: 0]
  ------------------
  377|      0|			struct sc_app_info *app_info = p11card->card->app[j];
  378|      0|			char *app_name = app_info ? app_info->label : "<anonymous>";
  ------------------
  |  Branch (378:21): [True: 0, False: 0]
  ------------------
  379|       |
  380|      0|			if (app_generic && app_generic == p11card->card->app[j])
  ------------------
  |  Branch (380:8): [True: 0, False: 0]
  |  Branch (380:23): [True: 0, False: 0]
  ------------------
  381|      0|				continue;
  382|       |
  383|      0|			sc_log(context, "%s: Binding %s token.", reader->name, app_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__
  |  |  ------------------
  ------------------
  384|      0|			rv = frameworks[i]->bind(p11card, app_info);
  385|      0|			if (rv != CKR_OK)   {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (385:8): [True: 0, False: 0]
  ------------------
  386|      0|				sc_log(context, "%s: bind %s token error Ox%lX",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  387|      0|				       reader->name, app_name, rv);
  388|      0|				continue;
  389|      0|			}
  390|       |
  391|      0|			sc_log(context, "%s: Creating %s token.", reader->name, app_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__
  |  |  ------------------
  ------------------
  392|      0|			rv = frameworks[i]->create_tokens(p11card, app_info);
  393|      0|			if (rv != CKR_OK)   {
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (393:8): [True: 0, False: 0]
  ------------------
  394|      0|				sc_log(context,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  395|      0|				       "%s: create %s token error 0x%lX",
  396|      0|				       reader->name, app_name, rv);
  397|      0|				goto fail;
  398|      0|			}
  399|       |			/* p11card is now bound to some slot */
  400|      0|			free_p11card = 0;
  401|      0|		}
  402|      0|	}
  403|       |
  404|      0|	sc_log(context, "%s: Detection ended", reader->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__
  |  |  ------------------
  ------------------
  405|      0|	rv = CKR_OK;
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  406|       |
  407|      0|fail:
  408|      0|	if (free_p11card) {
  ------------------
  |  Branch (408:6): [True: 0, False: 0]
  ------------------
  409|      0|		sc_pkcs11_card_free(p11card);
  410|      0|	}
  411|       |
  412|      0|	return rv;
  413|      0|}
card_detect_all:
  418|  15.7k|{
  419|  15.7k|	unsigned int i, j;
  420|       |
  421|  15.7k|	sc_log(context, "Detect all cards");
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  422|       |	/* Detect cards in all initialized readers */
  423|  15.7k|	for (i=0; i< sc_ctx_get_reader_count(context); i++) {
  ------------------
  |  Branch (423:12): [True: 0, False: 15.7k]
  ------------------
  424|      0|		sc_reader_t *reader = sc_ctx_get_reader(context, i);
  425|       |
  426|      0|		if (reader->flags & SC_READER_REMOVED) {
  ------------------
  |  |  371|      0|#define SC_READER_REMOVED			0x00000020
  ------------------
  |  Branch (426:7): [True: 0, False: 0]
  ------------------
  427|      0|			card_removed(reader);
  428|       |			/* do not remove slots related to this reader which would be
  429|       |			 * possible according to PKCS#11 2.20 and later, because NSS can't
  430|       |			 * handle a shrinking slot list
  431|       |			 * https://bugzilla.mozilla.org/show_bug.cgi?id=1613632 */
  432|       |
  433|       |			/* Instead, remove the relation between reader and slot */
  434|      0|			for (j = 0; j<list_size(&virtual_slots); j++) {
  ------------------
  |  Branch (434:16): [True: 0, False: 0]
  ------------------
  435|      0|				sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, j);
  436|      0|				if (slot->reader == reader) {
  ------------------
  |  Branch (436:9): [True: 0, False: 0]
  ------------------
  437|      0|					slot->reader = NULL;
  438|      0|					sc_wait_for_event(context, 0, NULL, NULL, 0, &slot->reader_events);
  439|      0|				}
  440|      0|			}
  441|      0|		} else {
  442|       |			/* Locate a slot related to the reader */
  443|      0|			int found = 0;
  444|      0|			for (j = 0; j<list_size(&virtual_slots); j++) {
  ------------------
  |  Branch (444:16): [True: 0, False: 0]
  ------------------
  445|      0|				sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, j);
  446|      0|				if (slot->reader == reader) {
  ------------------
  |  Branch (446:9): [True: 0, False: 0]
  ------------------
  447|      0|					found = 1;
  448|      0|					card_detect(slot->reader, slot->reader_events);
  449|      0|					break;
  450|      0|				}
  451|      0|			}
  452|      0|			if (!found) {
  ------------------
  |  Branch (452:8): [True: 0, False: 0]
  ------------------
  453|      0|				for (j = 0; j < sc_pkcs11_conf.slots_per_card; j++) {
  ------------------
  |  Branch (453:17): [True: 0, False: 0]
  ------------------
  454|      0|					CK_RV rv = create_slot(reader);
  455|      0|					if (rv != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (455:10): [True: 0, False: 0]
  ------------------
  456|      0|						return rv;
  457|      0|				}
  458|      0|				card_detect(reader, NULL);
  459|      0|			}
  460|      0|		}
  461|      0|	}
  462|  15.7k|	sc_log(context, "All cards detected");
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  463|  15.7k|	return CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  464|  15.7k|}
slot_allocate:
  468|  10.7k|{
  469|  10.7k|	unsigned int i;
  470|  10.7k|	struct sc_pkcs11_slot *tmp_slot = NULL;
  471|       |
  472|       |	/* Locate a free slot for this reader */
  473|  11.1k|	for (i=0; i< list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (473:12): [True: 10.7k, False: 407]
  ------------------
  474|  10.7k|		tmp_slot = (struct sc_pkcs11_slot *)list_get_at(&virtual_slots, i);
  475|  10.7k|		if (tmp_slot->reader == p11card->reader && tmp_slot->p11card == NULL)
  ------------------
  |  Branch (475:7): [True: 10.7k, False: 0]
  |  Branch (475:46): [True: 10.3k, False: 407]
  ------------------
  476|  10.3k|			break;
  477|  10.7k|	}
  478|  10.7k|	if (!tmp_slot || (i == list_size(&virtual_slots)))
  ------------------
  |  Branch (478:6): [True: 0, False: 10.7k]
  |  Branch (478:19): [True: 407, False: 10.3k]
  ------------------
  479|    407|		return CKR_FUNCTION_FAILED;
  ------------------
  |  | 1091|    407|#define CKR_FUNCTION_FAILED 0x00000006UL
  ------------------
  480|  10.3k|	sc_log(context, "Allocated slot 0x%lx for card in reader %s", tmp_slot->id, p11card->reader->name);
  ------------------
  |  |   71|  10.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  481|  10.3k|	tmp_slot->p11card = p11card;
  482|  10.3k|	tmp_slot->events = SC_EVENT_CARD_INSERTED;
  ------------------
  |  |  213|  10.3k|#define SC_EVENT_CARD_INSERTED		0x0001
  ------------------
  483|  10.3k|	*slot = tmp_slot;
  484|  10.3k|	return CKR_OK;
  ------------------
  |  | 1086|  10.3k|#define CKR_OK 0x00000000UL
  ------------------
  485|  10.7k|}
slot_get_slot:
  488|  29.0k|{
  489|  29.0k|	if (context == NULL)
  ------------------
  |  Branch (489:6): [True: 0, False: 29.0k]
  ------------------
  490|      0|		return CKR_CRYPTOKI_NOT_INITIALIZED;
  ------------------
  |  | 1169|      0|#define CKR_CRYPTOKI_NOT_INITIALIZED 0x00000190UL
  ------------------
  491|       |
  492|  29.0k|	*slot = list_seek(&virtual_slots, &id);	/* FIXME: check for null? */
  493|  29.0k|	if (!*slot)
  ------------------
  |  Branch (493:6): [True: 0, False: 29.0k]
  ------------------
  494|      0|		return CKR_SLOT_ID_INVALID;
  ------------------
  |  | 1089|      0|#define CKR_SLOT_ID_INVALID 0x00000003UL
  ------------------
  495|  29.0k|	return CKR_OK;
  ------------------
  |  | 1086|  29.0k|#define CKR_OK 0x00000000UL
  ------------------
  496|  29.0k|}
slot_get_token:
  499|  13.3k|{
  500|  13.3k|	CK_RV rv;
  501|       |
  502|  13.3k|	sc_log(context, "Slot(id=0x%lX): get token", id);
  ------------------
  |  |   71|  13.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__
  |  |  ------------------
  ------------------
  503|  13.3k|	rv = slot_get_slot(id, slot);
  504|  13.3k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  13.3k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (504:6): [True: 0, False: 13.3k]
  ------------------
  505|      0|		return rv;
  506|       |
  507|  13.3k|	if (!((*slot)->slot_info.flags & CKF_TOKEN_PRESENT)) {
  ------------------
  |  |  407|  13.3k|#define CKF_TOKEN_PRESENT 0x00000001UL
  ------------------
  |  Branch (507:6): [True: 1.16k, False: 12.1k]
  ------------------
  508|  1.16k|		if ((*slot)->reader == NULL)
  ------------------
  |  Branch (508:7): [True: 0, False: 1.16k]
  ------------------
  509|      0|			return CKR_TOKEN_NOT_PRESENT;
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
  510|  1.16k|		sc_log(context, "Slot(id=0x%lX): get token: now detect card", id);
  ------------------
  |  |   71|  1.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  511|  1.16k|		rv = card_detect((*slot)->reader, (*slot)->reader_events);
  512|  1.16k|		if (rv != CKR_OK)
  ------------------
  |  | 1086|  1.16k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (512:7): [True: 1.16k, False: 0]
  ------------------
  513|  1.16k|			return rv;
  514|  1.16k|	}
  515|       |
  516|  12.1k|	if (!((*slot)->slot_info.flags & CKF_TOKEN_PRESENT)) {
  ------------------
  |  |  407|  12.1k|#define CKF_TOKEN_PRESENT 0x00000001UL
  ------------------
  |  Branch (516:6): [True: 0, False: 12.1k]
  ------------------
  517|      0|		sc_log(context, "card detected, but slot not presenting token");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  518|      0|		return CKR_TOKEN_NOT_PRESENT;
  ------------------
  |  | 1144|      0|#define CKR_TOKEN_NOT_PRESENT 0x000000E0UL
  ------------------
  519|      0|	}
  520|  12.1k|	sc_log(context, "Slot-get-token returns OK");
  ------------------
  |  |   71|  12.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  521|  12.1k|	return CKR_OK;
  ------------------
  |  | 1086|  12.1k|#define CKR_OK 0x00000000UL
  ------------------
  522|  12.1k|}
slot_token_removed:
  525|  15.7k|{
  526|  15.7k|	CK_RV rv;
  527|  15.7k|	int token_was_present;
  528|  15.7k|	struct sc_pkcs11_slot *slot;
  529|  15.7k|	struct sc_pkcs11_object *object;
  530|       |
  531|  15.7k|	sc_log(context, "slot_token_removed(0x%lx)", id);
  ------------------
  |  |   71|  15.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  532|  15.7k|	rv = slot_get_slot(id, &slot);
  533|  15.7k|	if (rv != CKR_OK)
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (533:6): [True: 0, False: 15.7k]
  ------------------
  534|      0|		return rv;
  535|       |
  536|  15.7k|	token_was_present = (slot->slot_info.flags & CKF_TOKEN_PRESENT);
  ------------------
  |  |  407|  15.7k|#define CKF_TOKEN_PRESENT 0x00000001UL
  ------------------
  537|       |
  538|       |	/* Terminate active sessions */
  539|  15.7k|	sc_pkcs11_close_all_sessions(id);
  540|       |
  541|  42.6k|	while ((object = list_fetch(&slot->objects))) {
  ------------------
  |  Branch (541:9): [True: 26.8k, False: 15.7k]
  ------------------
  542|  26.8k|		if (object->ops->release)
  ------------------
  |  Branch (542:7): [True: 26.8k, False: 0]
  ------------------
  543|  26.8k|			object->ops->release(object);
  544|  26.8k|	}
  545|       |
  546|       |	/* Release framework stuff */
  547|  15.7k|	if (slot->p11card != NULL) {
  ------------------
  |  Branch (547:6): [True: 10.3k, False: 5.40k]
  ------------------
  548|  10.3k|		if (slot->fw_data != NULL && slot->p11card->framework != NULL
  ------------------
  |  Branch (548:7): [True: 5.18k, False: 5.17k]
  |  Branch (548:32): [True: 5.18k, False: 0]
  ------------------
  549|  5.18k|				&& slot->p11card->framework->release_token != NULL) {
  ------------------
  |  Branch (549:8): [True: 5.18k, False: 0]
  ------------------
  550|  5.18k|			slot->p11card->framework->release_token(slot->p11card, slot->fw_data);
  551|  5.18k|			slot->fw_data = NULL;
  552|  5.18k|		}
  553|  10.3k|		slot->p11card = NULL;
  554|  10.3k|	}
  555|       |
  556|       |	/* Reset relevant slot properties */
  557|  15.7k|	slot->slot_info.flags &= ~CKF_TOKEN_PRESENT;
  ------------------
  |  |  407|  15.7k|#define CKF_TOKEN_PRESENT 0x00000001UL
  ------------------
  558|  15.7k|	slot->login_user = -1;
  559|  15.7k|	slot->profile = NULL;
  560|  15.7k|	pop_all_login_states(slot);
  561|       |
  562|  15.7k|	if (token_was_present)
  ------------------
  |  Branch (562:6): [True: 10.3k, False: 5.40k]
  ------------------
  563|  10.3k|		slot->events = SC_EVENT_CARD_REMOVED;
  ------------------
  |  |  214|  10.3k|#define SC_EVENT_CARD_REMOVED		0x0002
  ------------------
  564|       |
  565|  15.7k|	memset(&slot->token_info, 0, sizeof slot->token_info);
  566|       |
  567|  15.7k|	return CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  568|  15.7k|}
slot.c:reader_reclaim_slot:
   67|  15.7k|{
   68|  15.7k|	unsigned int i;
   69|  15.7k|	CK_UTF8CHAR slotDescription[64];
   70|  15.7k|	CK_UTF8CHAR manufacturerID[32];
   71|       |
   72|  15.7k|	if (reader == NULL)
  ------------------
  |  Branch (72:6): [True: 0, False: 15.7k]
  ------------------
   73|      0|		return NULL;
   74|  15.7k|	strcpy_bp(slotDescription, reader->name, 64);
   75|  15.7k|	strcpy_bp(manufacturerID, reader->vendor, 32);
   76|       |
   77|       |	/* Locate a slot related to the reader */
   78|  15.7k|	for (i = 0; i<list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (78:14): [True: 0, False: 15.7k]
  ------------------
   79|      0|		sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
   80|      0|		if (slot->reader == NULL
  ------------------
  |  Branch (80:7): [True: 0, False: 0]
  ------------------
   81|      0|				&& 0 == memcmp(slot->slot_info.slotDescription, slotDescription, 64)
  ------------------
  |  Branch (81:8): [True: 0, False: 0]
  ------------------
   82|      0|				&& 0 == memcmp(slot->slot_info.manufacturerID, manufacturerID, 32)
  ------------------
  |  Branch (82:8): [True: 0, False: 0]
  ------------------
   83|      0|				&& slot->slot_info.hardwareVersion.major == reader->version_major
  ------------------
  |  Branch (83:8): [True: 0, False: 0]
  ------------------
   84|      0|				&& slot->slot_info.hardwareVersion.minor == reader->version_minor) {
  ------------------
  |  Branch (84:8): [True: 0, False: 0]
  ------------------
   85|      0|			return slot;
   86|      0|		}
   87|      0|	}
   88|  15.7k|	return NULL;
   89|  15.7k|}
slot.c:object_list_seeker:
  111|  2.05k|{
  112|  2.05k|	const struct sc_pkcs11_object *object = (struct sc_pkcs11_object *)el;
  113|       |
  114|  2.05k|	if ((el == NULL) || (key == NULL))
  ------------------
  |  Branch (114:6): [True: 0, False: 2.05k]
  |  Branch (114:22): [True: 0, False: 2.05k]
  ------------------
  115|      0|		return 0;
  116|  2.05k|	if (object->handle == *(CK_OBJECT_HANDLE*)key)
  ------------------
  |  Branch (116:6): [True: 725, False: 1.32k]
  ------------------
  117|    725|		return 1;
  118|  1.32k|	return 0;
  119|  2.05k|}

sc_pkcs15init_get_authentic_ops:
  925|     12|{
  926|     12|	return &sc_pkcs15init_authentic_operations;
  927|     12|}

sc_pkcs15init_get_cardos_ops:
  943|      5|{
  944|      5|	return &sc_pkcs15init_cardos_operations;
  945|      5|}

sc_pkcs15init_get_cryptoflex_ops:
  953|      2|{
  954|      2|	return &sc_pkcs15init_cryptoflex_operations;
  955|      2|}

sc_pkcs15init_get_entersafe_ops:
  532|      3|{
  533|      3|	return &sc_pkcs15init_entersafe_operations;
  534|      3|}

sc_pkcs15init_get_epass2003_ops:
  780|      6|{
  781|      6|	return &sc_pkcs15init_epass2003_operations;
  782|      6|}

sc_pkcs15init_get_gids_ops:
  190|      5|{
  191|      5|	return &sc_pkcs15init_gids_operations;
  192|      5|}

sc_pkcs15init_get_iasecc_ops:
 1896|      2|{
 1897|      2|	return &sc_pkcs15init_iasecc_operations;
 1898|      2|}

sc_pkcs15init_get_isoApplet_ops:
  804|      2|{
  805|      2|	return &sc_pkcs15init_isoApplet_operations;
  806|      2|}

sc_pkcs15init_bind:
  307|    243|{
  308|    243|	struct sc_context *ctx = card->ctx;
  309|    243|	struct sc_profile *profile;
  310|    243|	struct sc_pkcs15init_operations * (* func)(void) = NULL;
  311|    243|	const char	*driver = card->driver->short_name;
  312|    243|	char		card_profile[PATH_MAX];
  313|    243|	int		r, i;
  314|       |
  315|    243|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|       |	/* Put the card into administrative mode */
  317|    243|	r = sc_pkcs15init_set_lifecycle(card, SC_CARDCTRL_LIFECYCLE_ADMIN);
  318|    243|	if (r < 0 && r != SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|    240|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (318:6): [True: 240, False: 3]
  |  Branch (318:15): [True: 14, False: 226]
  ------------------
  319|    243|		LOG_TEST_RET(ctx, r, "Set lifecycle error");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  320|       |
  321|    229|	profile = sc_profile_new();
  322|    229|	profile->card = card;
  323|       |
  324|  3.14k|	for (i = 0; profile_operations[i].name; i++) {
  ------------------
  |  Branch (324:14): [True: 3.07k, False: 65]
  ------------------
  325|  3.07k|		if (!strcasecmp(driver, profile_operations[i].name)) {
  ------------------
  |  Branch (325:7): [True: 164, False: 2.91k]
  ------------------
  326|    164|			func = (struct sc_pkcs15init_operations *(*)(void)) profile_operations[i].func;
  327|    164|			break;
  328|    164|		}
  329|  3.07k|	}
  330|    229|	if (!func) {
  ------------------
  |  Branch (330:6): [True: 65, False: 164]
  ------------------
  331|       |		/* no builtin support for this driver => look if there's a
  332|       |		 * dynamic module for this card */
  333|     65|		func = (struct sc_pkcs15init_operations *(*)(void)) load_dynamic_driver(card->ctx, &profile->dll, driver);
  334|     65|	}
  335|    229|	if (func) {
  ------------------
  |  Branch (335:6): [True: 164, False: 65]
  ------------------
  336|    164|		profile->ops = func();
  337|    164|	}
  338|     65|	else {
  339|     65|		sc_log(ctx, "Unsupported card driver %s", driver);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  340|     65|		sc_profile_free(profile);
  341|     65|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported card driver");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|     65|	}
  343|       |
  344|       |	/* Massage the main profile name to see if there are
  345|       |	 * any options in there
  346|       |	 */
  347|    164|	profile->name = strdup(name);
  348|    164|	if (strchr(profile->name, '+') != NULL) {
  ------------------
  |  Branch (348:6): [True: 0, False: 164]
  ------------------
  349|      0|		char	*s;
  350|       |
  351|      0|		i = 0;
  352|      0|		(void) strtok(profile->name, "+");
  353|      0|		while ((s = strtok(NULL, "+")) != NULL) {
  ------------------
  |  Branch (353:10): [True: 0, False: 0]
  ------------------
  354|      0|			if (i < SC_PKCS15INIT_MAX_OPTIONS-1)
  ------------------
  |  |   95|      0|#define SC_PKCS15INIT_MAX_OPTIONS 16
  ------------------
  |  Branch (354:8): [True: 0, False: 0]
  ------------------
  355|      0|				profile->options[i++] = strdup(s);
  356|      0|		}
  357|      0|	}
  358|       |
  359|    164|	r = sc_pkcs15init_read_info(card, profile);
  360|    164|	if (r < 0) {
  ------------------
  |  Branch (360:6): [True: 28, False: 136]
  ------------------
  361|     28|		sc_profile_free(profile);
  362|     28|		LOG_TEST_RET(ctx, r, "Read info 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|     28|	}
  364|       |
  365|       |	/* Check the config file for a profile name.
  366|       |	 * If none is defined, use the default profile name.
  367|       |	 */
  368|    136|	if (!get_profile_from_config(card, card_profile, sizeof(card_profile)))
  ------------------
  |  Branch (368:6): [True: 136, False: 0]
  ------------------
  369|    136|		strlcpy(card_profile, driver, sizeof card_profile);
  ------------------
  |  |   43|    136|#define strlcpy _strlcpy
  ------------------
  370|    136|	if (profile_option != NULL)
  ------------------
  |  Branch (370:6): [True: 0, False: 136]
  ------------------
  371|      0|		strlcpy(card_profile, profile_option, sizeof(card_profile));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  372|       |
  373|    136|	do   {
  374|    136|		r = sc_profile_load(profile, profile->name);
  375|    136|		if (r < 0)   {
  ------------------
  |  Branch (375:7): [True: 136, False: 0]
  ------------------
  376|    136|			sc_log(ctx, "Failed to load profile '%s': %s", profile->name, sc_strerror(r));
  ------------------
  |  |   71|    136|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  377|    136|			break;
  378|    136|		}
  379|       |
  380|      0|		r = sc_profile_load(profile, card_profile);
  381|      0|		if (r < 0)   {
  ------------------
  |  Branch (381:7): [True: 0, False: 0]
  ------------------
  382|      0|			sc_log(ctx, "Failed to load profile '%s': %s", card_profile, 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__
  |  |  ------------------
  ------------------
  383|      0|			break;
  384|      0|		}
  385|       |
  386|      0|		r = sc_profile_finish(profile, app_info);
  387|      0|		if (r < 0)
  ------------------
  |  Branch (387:7): [True: 0, False: 0]
  ------------------
  388|      0|			sc_log(ctx, "Failed to finalize profile: %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__
  |  |  ------------------
  ------------------
  389|      0|	}  while (0);
  ------------------
  |  Branch (389:12): [Folded, False: 0]
  ------------------
  390|       |
  391|    136|	if (r < 0) {
  ------------------
  |  Branch (391:6): [True: 136, False: 0]
  ------------------
  392|    136|		sc_profile_free(profile);
  393|    136|		LOG_TEST_RET(ctx, r, "Load profile error");
  ------------------
  |  |  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: 136, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    136|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    136|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    136|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    136|		return _ret; \
  |  |  |  |  172|    136|	} \
  |  |  |  |  173|    136|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|    136|	}
  395|       |
  396|      0|	if (app_info && app_info->aid.len)   {
  ------------------
  |  Branch (396:6): [True: 0, False: 0]
  |  Branch (396:18): [True: 0, False: 0]
  ------------------
  397|      0|		struct sc_path path;
  398|       |
  399|      0|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (399:7): [True: 0, False: 0]
  |  Branch (399:23): [True: 0, False: 0]
  ------------------
  400|      0|			sc_log(ctx, "sc_pkcs15init_bind() select MF using EF.ATR 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__
  |  |  ------------------
  ------------------
  401|      0|			memset(&path, 0, sizeof(struct sc_path));
  402|      0|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  403|      0|			path.aid = card->ef_atr->aid;
  404|      0|			r = sc_select_file(card, &path, NULL);
  405|      0|			if (r)
  ------------------
  |  Branch (405:8): [True: 0, False: 0]
  ------------------
  406|      0|				return r;
  407|      0|		}
  408|       |
  409|      0|		if (app_info->path.len)   {
  ------------------
  |  Branch (409:7): [True: 0, False: 0]
  ------------------
  410|      0|			path = app_info->path;
  411|      0|		}
  412|      0|		else   {
  413|      0|			memset(&path, 0, sizeof(struct sc_path));
  414|      0|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  415|      0|			path.aid = app_info->aid;
  416|      0|		}
  417|      0|		sc_log(ctx, "sc_pkcs15init_bind() select application path(type:%X) '%s'", path.type, sc_print_path(&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__
  |  |  ------------------
  ------------------
  418|      0|		r = sc_select_file(card, &path, NULL);
  419|      0|	}
  420|       |
  421|      0|	*result = profile;
  422|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  423|      0|}
sc_pkcs15init_set_lifecycle:
  492|    243|{
  493|    243|	return sc_card_ctl(card, SC_CARDCTL_LIFECYCLE_SET, &lcycle);
  494|    243|}
sc_pkcs15init_store_certificate:
 2158|      1|{
 2159|      1|	struct sc_context *ctx = p15card->card->ctx;
 2160|      1|	struct sc_pkcs15_cert_info *cert_info = NULL;
 2161|      1|	struct sc_pkcs15_object *object = NULL;
 2162|      1|	struct sc_pkcs15_object *key_object = NULL;
 2163|      1|	struct sc_path existing_path;
 2164|      1|	const char *label = NULL;
 2165|      1|	int		r;
 2166|       |
 2167|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2168|       |
 2169|      1|	memset(&existing_path, 0, sizeof(struct sc_path));
 2170|       |
 2171|      1|	label = args->label;
 2172|      1|	if (!label)
  ------------------
  |  Branch (2172:6): [True: 1, False: 0]
  ------------------
 2173|      1|		label = "Certificate";
 2174|       |
 2175|      1|	r = sc_pkcs15init_select_intrinsic_id(p15card, profile, SC_PKCS15_TYPE_CERT_X509,
  ------------------
  |  |  439|      1|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
 2176|      1|			&args->id, &args->der_encoded);
 2177|      1|	LOG_TEST_RET(ctx, r, "Get certificate 'intrinsic ID' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2178|      0|	sc_log(ctx, "Cert(ID:%s) rv %i", sc_pkcs15_print_id(&args->id), 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__
  |  |  ------------------
  ------------------
 2179|       |
 2180|       |	/* Select an ID if the user didn't specify one, otherwise make sure it's unique */
 2181|      0|	r = select_id(p15card, SC_PKCS15_TYPE_CERT, &args->id);
  ------------------
  |  |  438|      0|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 2182|      0|	if (r == SC_ERROR_NON_UNIQUE_ID && args->update)   {
  ------------------
  |  |  107|      0|#define SC_ERROR_NON_UNIQUE_ID			-1505
  ------------------
  |  Branch (2182:6): [True: 0, False: 0]
  |  Branch (2182:37): [True: 0, False: 0]
  ------------------
 2183|      0|		struct sc_pkcs15_object *existing_obj = NULL;
 2184|       |
 2185|      0|		r = sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, &args->id, &existing_obj);
  ------------------
  |  |  438|      0|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 2186|      0|		if (!r)   {
  ------------------
  |  Branch (2186:7): [True: 0, False: 0]
  ------------------
 2187|      0|			sc_log(ctx, "Found cert(ID:%s)", sc_pkcs15_print_id(&args->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__
  |  |  ------------------
  ------------------
 2188|      0|			existing_path = ((struct sc_pkcs15_cert_info *)existing_obj->data)->path;
 2189|       |
 2190|      0|			sc_pkcs15_remove_object(p15card, existing_obj);
 2191|      0|			sc_pkcs15_free_object(existing_obj);
 2192|      0|		}
 2193|       |
 2194|      0|		r = select_id(p15card, SC_PKCS15_TYPE_CERT, &args->id);
  ------------------
  |  |  438|      0|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 2195|      0|	}
 2196|      0|	sc_log(ctx, "Select ID Cert(ID:%s) rv %i", sc_pkcs15_print_id(&args->id), 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__
  |  |  ------------------
  ------------------
 2197|      0|	LOG_TEST_RET(ctx, r, "Select certificate ID 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2198|       |
 2199|      0|	object = sc_pkcs15init_new_object(SC_PKCS15_TYPE_CERT_X509, label, NULL, NULL);
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
 2200|      0|	if (object == NULL)
  ------------------
  |  Branch (2200:6): [True: 0, False: 0]
  ------------------
 2201|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Failed to allocate certificate 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2202|      0|	cert_info = (struct sc_pkcs15_cert_info *) object->data;
 2203|      0|	cert_info->id = args->id;
 2204|      0|	cert_info->authority = args->authority;
 2205|      0|	sc_der_copy(&object->content, &args->der_encoded);
 2206|      0|	sc_der_copy(&cert_info->value, &args->der_encoded);
 2207|       |
 2208|      0|	if (existing_path.len)   {
  ------------------
  |  Branch (2208:6): [True: 0, False: 0]
  ------------------
 2209|      0|		sc_log(ctx, "Using existing path %s", sc_print_path(&existing_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__
  |  |  ------------------
  ------------------
 2210|      0|		cert_info->path = existing_path;
 2211|      0|	}
 2212|       |
 2213|      0|	sc_log(ctx, "Store cert(%.*s,ID:%s,der(%p,%zu))", (int)sizeof(object->label), object->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__
  |  |  ------------------
  ------------------
 2214|      0|			sc_pkcs15_print_id(&cert_info->id), args->der_encoded.value, args->der_encoded.len);
 2215|       |
 2216|      0|	if (!profile->pkcs15.direct_certificates)
  ------------------
  |  Branch (2216:6): [True: 0, False: 0]
  ------------------
 2217|      0|		r = sc_pkcs15init_store_data(p15card, profile, object, &args->der_encoded, &cert_info->path);
 2218|       |
 2219|       |	/* Now update the CDF */
 2220|      0|	if (r >= 0)   {
  ------------------
  |  Branch (2220:6): [True: 0, False: 0]
  ------------------
 2221|      0|		r = sc_pkcs15init_add_object(p15card, profile, SC_PKCS15_CDF, object);
  ------------------
  |  |  492|      0|#define SC_PKCS15_CDF			4
  ------------------
 2222|       |		/* TODO: update private key PKCS#15 object with the certificate's attributes */
 2223|      0|	}
 2224|       |
 2225|      0|	if (r >= 0)   {
  ------------------
  |  Branch (2225:6): [True: 0, False: 0]
  ------------------
 2226|      0|		r = sc_pkcs15_prkey_attrs_from_cert(p15card, object, &key_object);
 2227|      0|		if (r)   {
  ------------------
  |  Branch (2227:7): [True: 0, False: 0]
  ------------------
 2228|      0|			r = 0;
 2229|      0|		}
 2230|      0|		else if (key_object) {
  ------------------
  |  Branch (2230:12): [True: 0, False: 0]
  ------------------
 2231|      0|			if (profile->ops->emu_update_any_df) {
  ------------------
  |  Branch (2231:8): [True: 0, False: 0]
  ------------------
 2232|      0|				r = profile->ops->emu_update_any_df(profile, p15card, SC_AC_OP_UPDATE, key_object);
  ------------------
  |  |  189|      0|#define SC_AC_OP_UPDATE			23
  ------------------
 2233|      0|				if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (2233:9): [True: 0, False: 0]
  ------------------
 2234|      0|					r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2235|      0|			}
 2236|      0|			else {
 2237|      0|				r = sc_pkcs15init_update_any_df(p15card, profile, key_object->df, 0);
 2238|      0|				sc_log(ctx, "update_any_df returned %i", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2239|      0|			}
 2240|      0|		}
 2241|      0|	}
 2242|       |
 2243|      0|	if (r < 0)   {
  ------------------
  |  Branch (2243:6): [True: 0, False: 0]
  ------------------
 2244|      0|		sc_pkcs15_remove_object(p15card, object);
 2245|      0|		sc_pkcs15_free_object(object);
 2246|      0|	}
 2247|      0|	else if (res_obj)   {
  ------------------
  |  Branch (2247:11): [True: 0, False: 0]
  ------------------
 2248|      0|		*res_obj = object;
 2249|      0|	}
 2250|       |
 2251|      0|	profile->dirty = 1;
 2252|       |
 2253|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2254|      0|}
sc_pkcs15init_store_data_object:
 2265|     26|{
 2266|     26|	struct sc_context *ctx = p15card->card->ctx;
 2267|     26|	struct sc_pkcs15_data_info *data_object_info;
 2268|     26|	struct sc_pkcs15_object *object;
 2269|     26|	struct sc_pkcs15_object *objs[32];
 2270|     26|	const char	*label;
 2271|     26|	int		r, i;
 2272|     26|	unsigned int    tid = 0x01;
 2273|       |
 2274|     26|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     26|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     26|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     26|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     26|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2275|     26|	if (!profile)
  ------------------
  |  Branch (2275:6): [True: 26, False: 0]
  ------------------
 2276|     26|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Missing profile");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2277|      0|	label = args->label;
 2278|       |
 2279|      0|	if (!args->id.len) {
  ------------------
  |  Branch (2279:6): [True: 0, False: 0]
  ------------------
 2280|       |		/* Select an ID if the user didn't specify one, otherwise
 2281|       |		 * make sure it's unique (even though data objects doesn't
 2282|       |		 * have a pkcs15 id we need one here to create a unique
 2283|       |		 * file id from the data file template */
 2284|      0|		r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT, objs, 32);
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
 2285|      0|		LOG_TEST_RET(ctx, r, "Get 'DATA' objects 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2286|       |
 2287|      0|		for (i = 0; i < r; i++) {
  ------------------
  |  Branch (2287:15): [True: 0, False: 0]
  ------------------
 2288|      0|			unsigned char cid;
 2289|      0|			struct sc_pkcs15_data_info *cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
 2290|      0|			if (!cinfo->path.len)
  ------------------
  |  Branch (2290:8): [True: 0, False: 0]
  ------------------
 2291|      0|				continue;
 2292|      0|			cid = cinfo->path.value[cinfo->path.len - 1];
 2293|      0|			if (cid >= tid)
  ------------------
  |  Branch (2293:8): [True: 0, False: 0]
  ------------------
 2294|      0|				tid = cid + 1;
 2295|      0|		}
 2296|      0|		if (tid > 0xff)
  ------------------
  |  Branch (2296:7): [True: 0, False: 0]
  ------------------
 2297|       |			/* too many data objects ... */
 2298|      0|			return SC_ERROR_TOO_MANY_OBJECTS;
  ------------------
  |  |   86|      0|#define SC_ERROR_TOO_MANY_OBJECTS		-1405
  ------------------
 2299|      0|		args->id.len = 1;
 2300|      0|		args->id.value[0] = tid;
 2301|      0|	}
 2302|      0|	else   {
 2303|       |		/* in case the user specifies an id it should be at most
 2304|       |		 * one byte long */
 2305|      0|		if (args->id.len > 1)
  ------------------
  |  Branch (2305:7): [True: 0, False: 0]
  ------------------
 2306|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2307|      0|	}
 2308|       |
 2309|      0|	object = sc_pkcs15init_new_object(SC_PKCS15_TYPE_DATA_OBJECT, label, &args->auth_id, NULL);
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
 2310|      0|	if (object == NULL)
  ------------------
  |  Branch (2310:6): [True: 0, False: 0]
  ------------------
 2311|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2312|       |
 2313|      0|	data_object_info = (struct sc_pkcs15_data_info *) object->data;
 2314|      0|	if (args->app_label != NULL)
  ------------------
  |  Branch (2314:6): [True: 0, False: 0]
  ------------------
 2315|      0|		strlcpy(data_object_info->app_label, args->app_label, sizeof(data_object_info->app_label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 2316|      0|	else if (label != NULL)
  ------------------
  |  Branch (2316:11): [True: 0, False: 0]
  ------------------
 2317|      0|		strlcpy(data_object_info->app_label, label, sizeof(data_object_info->app_label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 2318|       |
 2319|      0|	data_object_info->app_oid = args->app_oid;
 2320|      0|	sc_der_copy(&data_object_info->data, &args->der_encoded);
 2321|       |
 2322|      0|	r = sc_pkcs15init_store_data(p15card, profile, object, &args->der_encoded, &data_object_info->path);
 2323|      0|	LOG_TEST_GOTO_ERR(ctx, r, "Store 'DATA' object 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2324|       |
 2325|       |	/* Now update the DDF */
 2326|      0|	r = sc_pkcs15init_add_object(p15card, profile, SC_PKCS15_DODF, object);
  ------------------
  |  |  495|      0|#define SC_PKCS15_DODF			7
  ------------------
 2327|      0|	LOG_TEST_GOTO_ERR(ctx, r, "'DODF' update 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2328|       |
 2329|      0|	if (r >= 0 && res_obj)
  ------------------
  |  Branch (2329:6): [True: 0, False: 0]
  |  Branch (2329:16): [True: 0, False: 0]
  ------------------
 2330|      0|		*res_obj = object;
 2331|      0|	object = NULL;
 2332|       |
 2333|      0|	profile->dirty = 1;
 2334|       |
 2335|      0|err:
 2336|      0|	sc_pkcs15_free_object(object);
 2337|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2338|      0|}
sc_pkcs15init_select_intrinsic_id:
 2837|      1|{
 2838|       |#ifndef ENABLE_OPENSSL
 2839|       |	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
 2840|       |#else
 2841|      1|	struct sc_context *ctx = p15card->card->ctx;
 2842|      1|	struct sc_pkcs15_pubkey *pubkey = NULL;
 2843|      1|	unsigned id_style;
 2844|      1|	struct sc_pkcs15_id id;
 2845|      1|	unsigned char *id_data = NULL;
 2846|      1|	size_t id_data_len = 0;
 2847|      1|	int rv, allocated = 0;
 2848|       |
 2849|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2850|       |
 2851|      1|	if (!id_out || !profile)
  ------------------
  |  Branch (2851:6): [True: 0, False: 1]
  |  Branch (2851:17): [True: 1, False: 0]
  ------------------
 2852|      1|		LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2853|       |
 2854|      0|	id_style = profile->id_style;
 2855|       |
 2856|       |	/* ID already exists */
 2857|      0|	if (id_out->len)
  ------------------
  |  Branch (2857:6): [True: 0, False: 0]
  ------------------
 2858|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2859|       |
 2860|       |	/* Native ID style is not intrinsic one */
 2861|      0|	if (id_style == SC_PKCS15INIT_ID_STYLE_NATIVE)
  ------------------
  |  |  165|      0|#define SC_PKCS15INIT_ID_STYLE_NATIVE		0
  ------------------
  |  Branch (2861:6): [True: 0, False: 0]
  ------------------
 2862|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2863|       |
 2864|      0|	memset(&id, 0, sizeof(id));
 2865|       |	/* Get PKCS15 public key */
 2866|      0|	switch(type)   {
 2867|      0|	case SC_PKCS15_TYPE_CERT_X509:
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  |  Branch (2867:2): [True: 0, False: 0]
  ------------------
 2868|      0|		rv = sc_pkcs15_pubkey_from_cert(ctx, (struct sc_pkcs15_der *)data, &pubkey);
 2869|      0|		LOG_TEST_RET(ctx, rv, "X509 parse 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2870|      0|		allocated = 1;
 2871|      0|		break;
 2872|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2872:2): [True: 0, False: 0]
  ------------------
 2873|      0|		rv = sc_pkcs15_pubkey_from_prvkey(ctx, (struct sc_pkcs15_prkey *)data, &pubkey);
 2874|      0|		LOG_TEST_RET(ctx, rv, "Cannot get public 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2875|      0|		allocated = 1;
 2876|      0|		break;
 2877|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (2877:2): [True: 0, False: 0]
  ------------------
 2878|      0|		pubkey = (struct sc_pkcs15_pubkey *)data;
 2879|      0|		allocated = 0;
 2880|      0|		break;
 2881|      0|	default:
  ------------------
  |  Branch (2881:2): [True: 0, False: 0]
  ------------------
 2882|      0|		sc_log(ctx, "Intrinsic ID is not implemented for the object type 0x%X", 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__
  |  |  ------------------
  ------------------
 2883|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2884|      0|	}
 2885|       |
 2886|       |	/* Skip silently if key is not initialized. */
 2887|      0|	if (pubkey->algorithm == SC_ALGORITHM_RSA && !pubkey->u.rsa.modulus.len)
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2887:6): [True: 0, False: 0]
  |  Branch (2887:47): [True: 0, False: 0]
  ------------------
 2888|      0|		goto done;
 2889|      0|	else if (pubkey->algorithm == SC_ALGORITHM_GOSTR3410 &&
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (2889:11): [True: 0, False: 0]
  ------------------
 2890|      0|			!pubkey->u.gostr3410.xy.data)
  ------------------
  |  Branch (2890:4): [True: 0, False: 0]
  ------------------
 2891|      0|		goto done;
 2892|      0|	else if (pubkey->algorithm == SC_ALGORITHM_EC && !pubkey->u.ec.ecpointQ.value)
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2892:11): [True: 0, False: 0]
  |  Branch (2892:51): [True: 0, False: 0]
  ------------------
 2893|      0|		goto done;
 2894|       |
 2895|       |	/* In Mozilla 'GOST R 34.10' is not yet supported.
 2896|       |	 * So, switch to the ID recommended by RFC2459 */
 2897|      0|	if (pubkey->algorithm == SC_ALGORITHM_GOSTR3410 && id_style == SC_PKCS15INIT_ID_STYLE_MOZILLA)
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
              	if (pubkey->algorithm == SC_ALGORITHM_GOSTR3410 && id_style == SC_PKCS15INIT_ID_STYLE_MOZILLA)
  ------------------
  |  |  166|      0|#define SC_PKCS15INIT_ID_STYLE_MOZILLA		1
  ------------------
  |  Branch (2897:6): [True: 0, False: 0]
  |  Branch (2897:53): [True: 0, False: 0]
  ------------------
 2898|      0|		id_style = SC_PKCS15INIT_ID_STYLE_RFC2459;
  ------------------
  |  |  167|      0|#define SC_PKCS15INIT_ID_STYLE_RFC2459		2
  ------------------
 2899|       |
 2900|      0|	switch (id_style)  {
 2901|      0|	case SC_PKCS15INIT_ID_STYLE_MOZILLA:
  ------------------
  |  |  166|      0|#define SC_PKCS15INIT_ID_STYLE_MOZILLA		1
  ------------------
  |  Branch (2901:2): [True: 0, False: 0]
  ------------------
 2902|      0|		if (pubkey->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2902:7): [True: 0, False: 0]
  ------------------
 2903|      0|			SHA1(pubkey->u.rsa.modulus.data, pubkey->u.rsa.modulus.len, id.value);
 2904|      0|		else if (pubkey->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2904:12): [True: 0, False: 0]
  ------------------
 2905|       |			/* ID should be SHA1 of the X coordinate according to PKCS#15 v1.1 */
 2906|       |			/* skip the 04 tag and get the X component */
 2907|      0|			SHA1(pubkey->u.ec.ecpointQ.value+1, (pubkey->u.ec.ecpointQ.len - 1) / 2, id.value);
 2908|      0|		else
 2909|      0|			goto done;
 2910|       |
 2911|      0|		id.len = SHA_DIGEST_LENGTH;
 2912|      0|		break;
 2913|      0|	case SC_PKCS15INIT_ID_STYLE_RFC2459:
  ------------------
  |  |  167|      0|#define SC_PKCS15INIT_ID_STYLE_RFC2459		2
  ------------------
  |  Branch (2913:2): [True: 0, False: 0]
  ------------------
 2914|      0|		rv = sc_pkcs15_encode_pubkey(ctx, pubkey, &id_data, &id_data_len);
 2915|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Encoding 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2916|       |
 2917|      0|		if (!id_data || !id_data_len) {
  ------------------
  |  Branch (2917:7): [True: 0, False: 0]
  |  Branch (2917:19): [True: 0, False: 0]
  ------------------
 2918|      0|			rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2919|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "Encoding 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2920|      0|		}
 2921|       |
 2922|      0|		SHA1(id_data, id_data_len, id.value);
 2923|      0|		id.len = SHA_DIGEST_LENGTH;
 2924|       |
 2925|      0|		break;
 2926|      0|	default:
  ------------------
  |  Branch (2926:2): [True: 0, False: 0]
  ------------------
 2927|      0|		sc_log(ctx, "Unsupported ID style: %i", id_style);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2928|      0|		rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2929|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Non supported ID style");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2930|      0|	}
 2931|       |
 2932|      0|done:
 2933|      0|	memcpy(id_out, &id, sizeof(*id_out));
 2934|      0|	rv = (int)id_out->len;
 2935|       |
 2936|      0|err:
 2937|      0|	if (id_data)
  ------------------
  |  Branch (2937:6): [True: 0, False: 0]
  ------------------
 2938|      0|		free(id_data);
 2939|      0|	if (allocated)
  ------------------
  |  Branch (2939:6): [True: 0, False: 0]
  ------------------
 2940|      0|		sc_pkcs15_free_pubkey(pubkey);
 2941|       |
 2942|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2943|      0|#endif
 2944|      0|}
pkcs15-lib.c:load_dynamic_driver:
  264|     65|{
  265|     65|	const char *version, *libname;
  266|     65|	void *handle;
  267|     65|	void *(*modinit)(const char *)  = NULL;
  268|     65|	const char *(*modversion)(void) = NULL;
  269|       |
  270|     65|	libname = find_library(ctx, name);
  271|     65|	if (!libname)
  ------------------
  |  Branch (271:6): [True: 65, False: 0]
  ------------------
  272|     65|		return NULL;
  273|      0|	handle = sc_dlopen(libname);
  274|      0|	if (handle == NULL) {
  ------------------
  |  Branch (274:6): [True: 0, False: 0]
  ------------------
  275|      0|		sc_log(ctx, "Module %s: cannot load '%s' library: %s", name, libname, sc_dlerror());
  ------------------
  |  |   71|      0|#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|      0|		return NULL;
  277|      0|	}
  278|       |
  279|       |	/* verify correctness of module */
  280|      0|	modinit    = (void *(*)(const char *)) sc_dlsym(handle, "sc_module_init");
  281|      0|	modversion = (const char *(*)(void)) sc_dlsym(handle, "sc_driver_version");
  282|      0|	if (modinit == NULL || modversion == NULL) {
  ------------------
  |  Branch (282:6): [True: 0, False: 0]
  |  Branch (282:25): [True: 0, False: 0]
  ------------------
  283|      0|		sc_log(ctx, "dynamic library '%s' is not a OpenSC module",libname);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  284|      0|		sc_dlclose(handle);
  285|      0|		return NULL;
  286|      0|	}
  287|       |	/* verify module version */
  288|      0|	version = modversion();
  289|      0|	if (version == NULL || strncmp(version, "0.9.", strlen("0.9.")) > 0) {
  ------------------
  |  Branch (289:6): [True: 0, False: 0]
  |  Branch (289:25): [True: 0, False: 0]
  ------------------
  290|      0|		sc_log(ctx,"dynamic library '%s': invalid module version",libname);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  291|      0|		sc_dlclose(handle);
  292|      0|		return NULL;
  293|      0|	}
  294|      0|	*dll = handle;
  295|      0|	sc_log(ctx, "successfully loaded pkcs15init driver '%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__
  |  |  ------------------
  ------------------
  296|       |
  297|      0|	return modinit(name);
  298|      0|}
pkcs15-lib.c:find_library:
  231|     65|{
  232|     65|	int          i;
  233|     65|	const char   *libname = NULL;
  234|     65|	scconf_block *blk, **blocks;
  235|       |
  236|    130|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (236:14): [True: 65, False: 65]
  ------------------
  237|     65|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], "framework", "pkcs15");
  238|     65|		if (!blocks)
  ------------------
  |  Branch (238:7): [True: 0, False: 65]
  ------------------
  239|      0|			continue;
  240|     65|		blk = blocks[0];
  241|     65|		free(blocks);
  242|     65|		if (blk == NULL)
  ------------------
  |  Branch (242:7): [True: 65, False: 0]
  ------------------
  243|     65|			continue;
  244|      0|		blocks = scconf_find_blocks(ctx->conf, blk, "pkcs15init", name);
  245|      0|		if (!blocks)
  ------------------
  |  Branch (245:7): [True: 0, False: 0]
  ------------------
  246|      0|			continue;
  247|      0|		blk = blocks[0];
  248|      0|		free(blocks);
  249|      0|		if (blk == NULL)
  ------------------
  |  Branch (249:7): [True: 0, False: 0]
  ------------------
  250|      0|			continue;
  251|      0|		libname = scconf_get_str(blk, "module", NULL);
  252|      0|		break;
  253|      0|	}
  254|     65|	if (!libname) {
  ------------------
  |  Branch (254:6): [True: 65, False: 0]
  ------------------
  255|     65|		sc_log(ctx, "unable to locate pkcs15init driver for '%s'", name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  256|     65|	}
  257|     65|	return libname;
  258|     65|}
pkcs15-lib.c:get_profile_from_config:
  201|    136|{
  202|    136|	struct sc_context *ctx = card->ctx;
  203|    136|	const char *tmp;
  204|    136|	scconf_block **blocks, *blk;
  205|    136|	int i;
  206|       |
  207|    272|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (207:14): [True: 136, False: 136]
  ------------------
  208|    136|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  209|    136|					"card_driver",
  210|    136|					card->driver->short_name);
  211|    136|		if (!blocks)
  ------------------
  |  Branch (211:7): [True: 0, False: 136]
  ------------------
  212|      0|			continue;
  213|    136|		blk = blocks[0];
  214|    136|		free(blocks);
  215|    136|		if (blk == NULL)
  ------------------
  |  Branch (215:7): [True: 136, False: 0]
  ------------------
  216|    136|			continue;
  217|       |
  218|      0|		tmp = scconf_get_str(blk, "profile", NULL);
  219|      0|		if (tmp != NULL) {
  ------------------
  |  Branch (219:7): [True: 0, False: 0]
  ------------------
  220|      0|			strlcpy(buffer, tmp, size);
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  221|      0|			return 1;
  222|      0|		}
  223|      0|	}
  224|       |
  225|    136|	return 0;
  226|    136|}
pkcs15-lib.c:sc_pkcs15init_read_info:
 4519|    164|{
 4520|    164|	struct sc_path	path;
 4521|    164|	struct sc_file	*file = NULL;
 4522|    164|	unsigned char	*mem = NULL;
 4523|    164|	size_t		len = 0;
 4524|    164|	int		r;
 4525|       |
 4526|    164|	sc_format_path(OPENSC_INFO_FILEPATH, &path);
  ------------------
  |  |   71|    164|#define OPENSC_INFO_FILEPATH		"3F0050154946"
  ------------------
 4527|    164|	r = sc_select_file(card, &path, &file);
 4528|    164|	if (r >= 0) {
  ------------------
  |  Branch (4528:6): [True: 61, False: 103]
  ------------------
 4529|     61|		len = file->size;
 4530|     61|		sc_file_free(file);
 4531|     61|		if (len > MAX_FILE_SIZE)
  ------------------
  |  |  220|     61|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (4531:7): [True: 0, False: 61]
  ------------------
 4532|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4533|     61|		mem = malloc(len);
 4534|     61|		if (mem != NULL)
  ------------------
  |  Branch (4534:7): [True: 61, False: 0]
  ------------------
 4535|     61|			r = sc_read_binary(card, 0, mem, len, 0);
 4536|      0|		else
 4537|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 4538|     61|	}
 4539|    103|	else   {
 4540|    103|		r = 0;
 4541|    103|		sc_file_free(file);
 4542|    103|	}
 4543|       |
 4544|    164|	if (r >= 0)
  ------------------
  |  Branch (4544:6): [True: 151, False: 13]
  ------------------
 4545|    151|		r = sc_pkcs15init_parse_info(card, mem, r, profile);
 4546|       |
 4547|    164|	if (mem)
  ------------------
  |  Branch (4547:6): [True: 61, False: 103]
  ------------------
 4548|     61|		free(mem);
 4549|    164|	return r;
 4550|    164|}
pkcs15-lib.c:sc_pkcs15init_parse_info:
 4580|    151|{
 4581|    151|	unsigned char	tag;
 4582|    151|	const unsigned char *end;
 4583|    151|	unsigned int	nopts = 0;
 4584|    151|	size_t		n;
 4585|    151|	int	r = 0;
 4586|       |
 4587|    151|	if ((p == NULL) || (len == 0))
  ------------------
  |  Branch (4587:6): [True: 103, False: 48]
  |  Branch (4587:21): [True: 4, False: 44]
  ------------------
 4588|    107|		return 0;
 4589|       |
 4590|     44|	end = p + (len - 1);
 4591|    589|	while (p < end) {	/* more bytes to look at */
  ------------------
  |  Branch (4591:9): [True: 583, False: 6]
  ------------------
 4592|    583|		r = 0;
 4593|       |
 4594|    583|		tag = *p; p++;
 4595|    583|		if ((tag == 0) || (tag == 0xff) || (p >= end))
  ------------------
  |  Branch (4595:7): [True: 17, False: 566]
  |  Branch (4595:21): [True: 1, False: 565]
  |  Branch (4595:38): [True: 5, False: 560]
  ------------------
 4596|     23|			break;
 4597|       |
 4598|    560|		n = *p;
 4599|    560|		p++;
 4600|       |
 4601|    560|		if (p >= end || p + n > end) { /* invalid length byte n */
  ------------------
  |  Branch (4601:7): [True: 6, False: 554]
  |  Branch (4601:19): [True: 8, False: 546]
  ------------------
 4602|     14|			r = SC_ERROR_PKCS15INIT;
  ------------------
  |  |  102|     14|#define SC_ERROR_PKCS15INIT			-1500
  ------------------
 4603|     14|			goto error;
 4604|     14|		}
 4605|       |
 4606|    546|		switch (tag) {
 4607|    256|		case OPENSC_INFO_TAG_PROFILE:
  ------------------
  |  |   73|    256|#define OPENSC_INFO_TAG_PROFILE		0x01
  ------------------
  |  Branch (4607:3): [True: 256, False: 290]
  ------------------
 4608|    256|			r = set_info_string(&profile->name, p, n);
 4609|    256|			if (r < 0)
  ------------------
  |  Branch (4609:8): [True: 0, False: 256]
  ------------------
 4610|      0|				goto error;
 4611|    256|			break;
 4612|    256|		case OPENSC_INFO_TAG_OPTION:
  ------------------
  |  |   74|     58|#define OPENSC_INFO_TAG_OPTION		0x02
  ------------------
  |  Branch (4612:3): [True: 58, False: 488]
  ------------------
 4613|     58|			if (nopts >= SC_PKCS15INIT_MAX_OPTIONS - 1) {
  ------------------
  |  |   95|     58|#define SC_PKCS15INIT_MAX_OPTIONS 16
  ------------------
  |  Branch (4613:8): [True: 1, False: 57]
  ------------------
 4614|      1|				sc_log(card->ctx, "Too many options in OpenSC Info file");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4615|      1|				r = SC_ERROR_PKCS15INIT;
  ------------------
  |  |  102|      1|#define SC_ERROR_PKCS15INIT			-1500
  ------------------
 4616|      1|				goto error;
 4617|      1|			}
 4618|     57|			r = set_info_string(&profile->options[nopts], p, n);
 4619|     57|			if (r < 0)
  ------------------
  |  Branch (4619:8): [True: 0, False: 57]
  ------------------
 4620|      0|				goto error;
 4621|     57|			profile->options[++nopts] = NULL;
 4622|     57|			break;
 4623|    232|		default:
  ------------------
  |  Branch (4623:3): [True: 232, False: 314]
  ------------------
 4624|    232|			/* Unknown options ignored */ ;
 4625|    546|		}
 4626|    545|		p += n;
 4627|    545|	}
 4628|     29|	return 0;
 4629|       |
 4630|     15|error:
 4631|     15|	sc_log(card->ctx, "OpenSC info file corrupted");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4632|     15|	if (profile->name) {
  ------------------
  |  Branch (4632:6): [True: 15, False: 0]
  ------------------
 4633|     15|		free(profile->name);
 4634|     15|		profile->name = NULL;
 4635|     15|	}
 4636|     48|	for (size_t i = 0; i < nopts; i++) {
  ------------------
  |  Branch (4636:21): [True: 33, False: 15]
  ------------------
 4637|     33|		if (profile->options[i])
  ------------------
  |  Branch (4637:7): [True: 33, False: 0]
  ------------------
 4638|     33|			free(profile->options[i]);
 4639|       |		profile->options[i] = NULL;
 4640|     33|	}
 4641|     15|	return r;
 4642|     44|}
pkcs15-lib.c:set_info_string:
 4555|    313|{
 4556|    313|	char	*s;
 4557|       |
 4558|    313|	if (!(s = malloc(len+1)))
  ------------------
  |  Branch (4558:6): [True: 0, False: 313]
  ------------------
 4559|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 4560|    313|	memcpy(s, p, len);
 4561|    313|	s[len] = '\0';
 4562|    313|	if (*strp)
  ------------------
  |  Branch (4562:6): [True: 256, False: 57]
  ------------------
 4563|    256|		free(*strp);
 4564|    313|	*strp = s;
 4565|    313|	return SC_SUCCESS;
  ------------------
  |  |   28|    313|#define SC_SUCCESS				0
  ------------------
 4566|    313|}

sc_pkcs15init_get_muscle_ops:
  322|      7|{
  323|      7|	return &sc_pkcs15init_muscle_operations;
  324|      7|}

sc_pkcs15init_get_myeid_ops:
  974|      2|struct sc_pkcs15init_operations *sc_pkcs15init_get_myeid_ops(void) {
  975|      2|	return &sc_pkcs15init_myeid_operations;
  976|      2|}

sc_pkcs15init_get_oberthur_ops:
  936|      1|{
  937|      1|	return &sc_pkcs15init_oberthur_operations;
  938|      1|}

sc_pkcs15init_get_openpgp_ops:
  620|      8|{
  621|      8|	return &sc_pkcs15init_openpgp_operations;
  622|      8|}

sc_pkcs15init_get_rtecp_ops:
  714|      6|{
  715|      6|	return &sc_pkcs15init_rtecp_operations;
  716|      6|}

sc_pkcs15init_get_rutoken_ops:
  324|      2|{
  325|      2|	return &sc_pkcs15init_rutoken_operations;
  326|      2|}

sc_pkcs15init_get_sc_hsm_ops:
  646|      8|{
  647|      8|	return &sc_pkcs15init_sc_hsm_operations;
  648|      8|}

sc_pkcs15init_get_setcos_ops:
  633|     69|{
  634|     69|	return &sc_pkcs15init_setcos_operations;
  635|     69|}

sc_pkcs15init_get_starcos_ops:
  964|     24|{
  965|     24|	return &sc_pkcs15init_starcos_operations;
  966|     24|}

sc_profile_new:
  291|    229|{
  292|    229|	struct sc_pkcs15_card *p15card;
  293|    229|	struct sc_profile *pro;
  294|       |
  295|    229|	pro = calloc(1, sizeof(*pro));
  296|    229|	if (pro == NULL)
  ------------------
  |  Branch (296:6): [True: 0, False: 229]
  ------------------
  297|      0|		return NULL;
  298|    229|	pro->p15_spec = p15card = sc_pkcs15_card_new();
  299|       |
  300|    229|	pro->pkcs15.do_last_update = 1;
  301|       |
  302|    229|	if (p15card) {
  ------------------
  |  Branch (302:6): [True: 229, False: 0]
  ------------------
  303|    229|		p15card->tokeninfo->label = strdup("OpenSC Card");
  304|    229|		p15card->tokeninfo->manufacturer_id = strdup("OpenSC Project");
  305|    229|		p15card->tokeninfo->serial_number = strdup("0000");
  306|    229|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_EID_COMPLIANT;
  ------------------
  |  |  598|    229|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  307|    229|		p15card->tokeninfo->version = 0;
  308|       |
  309|       |		/* Set up EF(TokenInfo) and EF(ODF) */
  310|    229|		p15card->file_tokeninfo = init_file(SC_FILE_TYPE_WORKING_EF);
  ------------------
  |  |  216|    229|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  311|    229|		p15card->file_odf = init_file(SC_FILE_TYPE_WORKING_EF);
  ------------------
  |  |  216|    229|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  312|    229|		p15card->file_unusedspace = init_file(SC_FILE_TYPE_WORKING_EF);
  ------------------
  |  |  216|    229|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  313|    229|	}
  314|       |
  315|       |	/* Assume card does RSA natively */
  316|    229|	pro->rsa_access_flags = DEF_PRKEY_RSA_ACCESS;
  ------------------
  |  |   53|    229|#define DEF_PRKEY_RSA_ACCESS	0x1D
  ------------------
  317|    229|	pro->pin_encoding = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    229|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  318|    229|	pro->pin_minlen = 4;
  319|    229|	pro->pin_maxlen = 8;
  320|    229|	pro->id_style = SC_PKCS15INIT_ID_STYLE_NATIVE;
  ------------------
  |  |  165|    229|#define SC_PKCS15INIT_ID_STYLE_NATIVE		0
  ------------------
  321|       |
  322|    229|	return pro;
  323|    229|}
sc_profile_load:
  327|    136|{
  328|    136|	struct sc_context *ctx = profile->card->ctx;
  329|    136|	scconf_context	*conf;
  330|    136|	const char *profile_dir = NULL;
  331|    136|	char path[PATH_MAX];
  332|    136|	int res = 0, i;
  333|       |#ifdef _WIN32
  334|       |	char temp_path[PATH_MAX];
  335|       |	size_t temp_len;
  336|       |#endif
  337|       |
  338|    136|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    136|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    136|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    136|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    136|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 136]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  339|    272|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (339:14): [True: 136, False: 136]
  ------------------
  340|    136|		profile_dir = scconf_get_str(ctx->conf_blocks[i], "profile_dir", NULL);
  341|    136|		if (profile_dir)
  ------------------
  |  Branch (341:7): [True: 0, False: 136]
  ------------------
  342|      0|			break;
  343|    136|	}
  344|       |
  345|    136|	if (!profile_dir) {
  ------------------
  |  Branch (345:6): [True: 136, False: 0]
  ------------------
  346|       |#ifdef _WIN32
  347|       |		temp_len = PATH_MAX - 1;
  348|       |		res = sc_ctx_win32_get_config_value(NULL, "ProfileDir", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
  349|       |				temp_path, &temp_len);
  350|       |		if (res)
  351|       |			LOG_FUNC_RETURN(ctx, res);
  352|       |		temp_path[temp_len] = '\0';
  353|       |		profile_dir = temp_path;
  354|       |#else
  355|    136|		profile_dir = SC_PKCS15_PROFILE_DIRECTORY;
  356|    136|#endif
  357|    136|	}
  358|    136|	sc_log(ctx, "Using profile directory '%s'.", profile_dir);
  ------------------
  |  |   71|    136|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  359|       |
  360|       |#ifdef _WIN32
  361|       |	snprintf(path, sizeof(path), "%s\\%s.%s", profile_dir, filename, SC_PKCS15_PROFILE_SUFFIX);
  362|       |#else /* _WIN32 */
  363|    136|	snprintf(path, sizeof(path), "%s/%s.%s", profile_dir, filename, SC_PKCS15_PROFILE_SUFFIX);
  ------------------
  |  |   31|    136|#define SC_PKCS15_PROFILE_SUFFIX	"profile"
  ------------------
  364|    136|#endif /* _WIN32 */
  365|       |
  366|    136|	sc_log(ctx, "Trying profile file %s", path);
  ------------------
  |  |   71|    136|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  367|       |
  368|    136|	conf = scconf_new(path);
  369|    136|	res = scconf_parse(conf);
  370|       |
  371|    136|	sc_log(ctx, "profile %s loaded ok", path);
  ------------------
  |  |   71|    136|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  372|       |
  373|    136|	if (res < 0) {
  ------------------
  |  Branch (373:6): [True: 136, False: 0]
  ------------------
  374|    136|		scconf_free(conf);
  375|    136|		LOG_FUNC_RETURN(ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|    136|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    136|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    136|	int _ret = r; \
  |  |  |  |  155|    136|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 136, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    136|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    136|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 136, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    136|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    136|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    136|	return _ret; \
  |  |  |  |  163|    136|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    136|	}
  377|       |
  378|      0|	if (res == 0) {
  ------------------
  |  Branch (378:6): [True: 0, False: 0]
  ------------------
  379|      0|		scconf_free(conf);
  380|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_SYNTAX_ERROR);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|      0|	}
  382|       |
  383|      0|	res = process_conf(profile, conf);
  384|      0|	scconf_free(conf);
  385|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|      0|}
sc_profile_free:
  449|    229|{
  450|    229|	struct auth_info *ai;
  451|    229|	struct pin_info *pi;
  452|    229|	sc_macro_t	*mi;
  453|    229|	sc_template_t	*ti;
  454|       |
  455|    229|	if (profile->name)
  ------------------
  |  Branch (455:6): [True: 149, False: 80]
  ------------------
  456|    149|		free(profile->name);
  457|    229|	if (profile->driver)
  ------------------
  |  Branch (457:6): [True: 0, False: 229]
  ------------------
  458|      0|		free(profile->driver);
  459|       |
  460|    229|	free_file_list(&profile->ef_list);
  461|       |
  462|    229|	while ((ai = profile->auth_list) != NULL) {
  ------------------
  |  Branch (462:9): [True: 0, False: 229]
  ------------------
  463|      0|		profile->auth_list = ai->next;
  464|      0|		free(ai);
  465|      0|	}
  466|       |
  467|    229|	while ((ti = profile->template_list) != NULL) {
  ------------------
  |  Branch (467:9): [True: 0, False: 229]
  ------------------
  468|      0|		profile->template_list = ti->next;
  469|      0|		if (ti->data)
  ------------------
  |  Branch (469:7): [True: 0, False: 0]
  ------------------
  470|      0|			sc_profile_free(ti->data);
  471|      0|		if (ti->name)
  ------------------
  |  Branch (471:7): [True: 0, False: 0]
  ------------------
  472|      0|			free(ti->name);
  473|      0|		free(ti);
  474|      0|	}
  475|       |
  476|    229|	while ((mi = profile->macro_list) != NULL) {
  ------------------
  |  Branch (476:9): [True: 0, False: 229]
  ------------------
  477|      0|		profile->macro_list = mi->next;
  478|      0|		if (mi->name)
  ------------------
  |  Branch (478:7): [True: 0, False: 0]
  ------------------
  479|      0|			free(mi->name);
  480|      0|		free(mi);
  481|      0|	}
  482|       |
  483|    229|	while ((pi = profile->pin_list) != NULL) {
  ------------------
  |  Branch (483:9): [True: 0, False: 229]
  ------------------
  484|      0|		profile->pin_list = pi->next;
  485|      0|		if (pi->file_name)
  ------------------
  |  Branch (485:7): [True: 0, False: 0]
  ------------------
  486|      0|			free(pi->file_name);
  487|      0|		free(pi);
  488|      0|	}
  489|       |
  490|    253|	for (int i = 0; profile->options[i]; i++) {
  ------------------
  |  Branch (490:18): [True: 24, False: 229]
  ------------------
  491|     24|		free(profile->options[i]);
  492|     24|	}
  493|       |
  494|    229|	if (profile->p15_spec)
  ------------------
  |  Branch (494:6): [True: 229, False: 0]
  ------------------
  495|    229|		sc_pkcs15_card_free(profile->p15_spec);
  496|       |
  497|    229|	if (profile->dll)
  ------------------
  |  Branch (497:6): [True: 0, False: 229]
  ------------------
  498|      0|		sc_dlclose(profile->dll);
  499|       |
  500|    229|	free(profile);
  501|    229|}
profile.c:init_file:
  271|    687|{
  272|    687|	struct sc_file	*file;
  273|    687|	unsigned int	op;
  274|       |
  275|    687|	file = sc_file_new();
  276|  21.9k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|  21.9k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (276:15): [True: 21.2k, False: 687]
  ------------------
  277|  21.2k|		sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|  21.2k|#define SC_AC_NONE			0x00000000
  ------------------
  278|  21.2k|	}
  279|    687|	file->type = type;
  280|    687|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    687|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  281|    687|	if (file->type != SC_FILE_TYPE_DF && file->type != SC_FILE_TYPE_BSO)
  ------------------
  |  |  214|  1.37k|#define SC_FILE_TYPE_DF			0x04
  ------------------
              	if (file->type != SC_FILE_TYPE_DF && file->type != SC_FILE_TYPE_BSO)
  ------------------
  |  |  217|    687|#define SC_FILE_TYPE_BSO		0x10
  ------------------
  |  Branch (281:6): [True: 687, False: 0]
  |  Branch (281:39): [True: 687, False: 0]
  ------------------
  282|    687|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    687|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  283|    687|	return file;
  284|    687|}
profile.c:free_file_list:
 1213|    229|{
 1214|    229|	struct file_info	*fi;
 1215|       |
 1216|    229|	while ((fi = *list) != NULL) {
  ------------------
  |  Branch (1216:9): [True: 0, False: 229]
  ------------------
 1217|      0|		*list = fi->next;
 1218|       |
 1219|      0|		if (fi->dont_free == 0)
  ------------------
  |  Branch (1219:7): [True: 0, False: 0]
  ------------------
 1220|      0|			sc_file_free(fi->file);
 1221|      0|		free(fi->profile_extension);
 1222|      0|		free(fi->ident);
 1223|      0|		free(fi);
 1224|      0|	}
 1225|    229|}

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

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

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

test_digest:
  332|     93|{
  333|     93|	CK_SESSION_HANDLE session;
  334|     93|	const uint8_t    *ptr = NULL;
  335|     93|	unsigned char    *dig_data = NULL;
  336|     93|	size_t            dig_size = 0;
  337|     93|	CK_MECHANISM      mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|     93|#define NULL_PTR ((void *)0)
  ------------------
  338|     93|	unsigned char     buffer[64] = {0};
  339|     93|	CK_ULONG          hash_len = sizeof(buffer);
  340|       |
  341|     93|	if (set_mechanism(&data, &size, &mech))
  ------------------
  |  Branch (341:6): [True: 0, False: 93]
  ------------------
  342|      0|		return;
  343|       |
  344|       |	/* Copy data for hashing*/
  345|     93|	ptr = data;
  346|     93|	if ((dig_size = get_buffer(&ptr, size, &data, &size, 6000)) == 0)
  ------------------
  |  Branch (346:6): [True: 1, False: 92]
  ------------------
  347|      1|		return;
  348|     92|	if (!(dig_data = malloc(dig_size)))
  ------------------
  |  Branch (348:6): [True: 0, False: 92]
  ------------------
  349|      0|		return;
  350|     92|	memcpy(dig_data, ptr, dig_size);
  351|       |
  352|     92|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|     92|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (352:6): [True: 34, False: 58]
  ------------------
  353|     34|		goto end;
  354|       |
  355|     58|	if (p11->C_DigestInit(session, &mech) == CKR_OK)
  ------------------
  |  | 1086|     58|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (355:6): [True: 1, False: 57]
  ------------------
  356|      1|		p11->C_Digest(session, dig_data, dig_size, buffer, &hash_len);
  357|       |
  358|     58|	p11->C_CloseSession(session);
  359|     58|	p11->C_Finalize(NULL);
  360|     92|end:
  361|     92|	free(dig_data);
  362|     92|}
fill_bool_attr:
  638|  3.63k|{
  639|  3.63k|	if (value) {
  ------------------
  |  Branch (639:6): [True: 2.54k, False: 1.09k]
  ------------------
  640|  2.54k|		FILL_ATTR((*keyTemplate)[*n_attr], type, &_true, sizeof(_true));
  ------------------
  |  |  631|  2.54k|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|  2.54k|	(attr).type=(typ); \
  |  |  633|  2.54k|	(attr).pValue=(val); \
  |  |  634|  2.54k|	(attr).ulValueLen=len; \
  |  |  635|  2.54k|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 2.54k]
  |  |  ------------------
  ------------------
  641|  2.54k|	}
  642|  1.09k|	else {
  643|  1.09k|		FILL_ATTR((*keyTemplate)[*n_attr], type, &_false, sizeof(_false));
  ------------------
  |  |  631|  1.09k|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|  1.09k|	(attr).type=(typ); \
  |  |  633|  1.09k|	(attr).pValue=(val); \
  |  |  634|  1.09k|	(attr).ulValueLen=len; \
  |  |  635|  1.09k|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
  644|  1.09k|	}
  645|       |	
  646|  3.63k|	++(*n_attr);
  647|  3.63k|}
fill_key_template:
  650|    989|{
  651|    989|	const unsigned char *ptr = NULL;
  652|    989|	size_t               ecparams_size = 0;
  653|    989|	size_t               opt_object_label_size = 0;
  654|    989|	size_t               opt_object_id_len = 0;
  655|    989|	size_t               opt_allowed_mechanisms_len = 0;
  656|    989|	int bool_types[] = {CKA_MODULUS_BITS, CKA_PUBLIC_EXPONENT, CKA_VERIFY, CKA_SENSITIVE,
  ------------------
  |  |  175|    989|#define CKA_MODULUS_BITS 0x00000121UL
  ------------------
              	int bool_types[] = {CKA_MODULUS_BITS, CKA_PUBLIC_EXPONENT, CKA_VERIFY, CKA_SENSITIVE,
  ------------------
  |  |  176|    989|#define CKA_PUBLIC_EXPONENT 0x00000122UL
  ------------------
              	int bool_types[] = {CKA_MODULUS_BITS, CKA_PUBLIC_EXPONENT, CKA_VERIFY, CKA_SENSITIVE,
  ------------------
  |  |  169|    989|#define CKA_VERIFY 0x0000010AUL
  ------------------
              	int bool_types[] = {CKA_MODULUS_BITS, CKA_PUBLIC_EXPONENT, CKA_VERIFY, CKA_SENSITIVE,
  ------------------
  |  |  162|    989|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  657|    989|						CKA_SIGN, CKA_ENCRYPT, CKA_DECRYPT, CKA_WRAP, CKA_UNWRAP,
  ------------------
  |  |  167|    989|#define CKA_SIGN 0x00000108UL
  ------------------
              						CKA_SIGN, CKA_ENCRYPT, CKA_DECRYPT, CKA_WRAP, CKA_UNWRAP,
  ------------------
  |  |  163|    989|#define CKA_ENCRYPT 0x00000104UL
  ------------------
              						CKA_SIGN, CKA_ENCRYPT, CKA_DECRYPT, CKA_WRAP, CKA_UNWRAP,
  ------------------
  |  |  164|    989|#define CKA_DECRYPT 0x00000105UL
  ------------------
              						CKA_SIGN, CKA_ENCRYPT, CKA_DECRYPT, CKA_WRAP, CKA_UNWRAP,
  ------------------
  |  |  165|    989|#define CKA_WRAP 0x00000106UL
  ------------------
              						CKA_SIGN, CKA_ENCRYPT, CKA_DECRYPT, CKA_WRAP, CKA_UNWRAP,
  ------------------
  |  |  166|    989|#define CKA_UNWRAP 0x00000107UL
  ------------------
  658|    989|						CKA_DERIVE, CKA_PRIVATE, CKA_ALWAYS_AUTHENTICATE, CKA_EXTRACTABLE};
  ------------------
  |  |  171|    989|#define CKA_DERIVE 0x0000010CUL
  ------------------
              						CKA_DERIVE, CKA_PRIVATE, CKA_ALWAYS_AUTHENTICATE, CKA_EXTRACTABLE};
  ------------------
  |  |  139|    989|#define CKA_PRIVATE 0x00000002UL
  ------------------
              						CKA_DERIVE, CKA_PRIVATE, CKA_ALWAYS_AUTHENTICATE, CKA_EXTRACTABLE};
  ------------------
  |  |  202|    989|#define CKA_ALWAYS_AUTHENTICATE 0x00000202UL
  ------------------
              						CKA_DERIVE, CKA_PRIVATE, CKA_ALWAYS_AUTHENTICATE, CKA_EXTRACTABLE};
  ------------------
  |  |  192|    989|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  659|       |
  660|    989|	if (!(*keyTemplate = malloc(20 * sizeof(CK_ATTRIBUTE))))
  ------------------
  |  Branch (660:6): [True: 0, False: 989]
  ------------------
  661|      0|		return 1;
  662|    989|	memset(*keyTemplate, 0, 20 * sizeof(CK_ATTRIBUTE));
  663|    989|	FILL_ATTR((*keyTemplate)[0], CKA_CLASS, class, sizeof(CKA_CLASS));
  ------------------
  |  |  631|    989|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|    989|	(attr).type=(typ); \
  |  |  633|    989|	(attr).pValue=(val); \
  |  |  634|    989|	(attr).ulValueLen=len; \
  |  |  635|    989|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 989]
  |  |  ------------------
  ------------------
  664|    989|	*n_attr = 1;
  665|    989|	fill_bool_attr(keyTemplate, n_attr, CKA_TOKEN, token);
  ------------------
  |  |  138|    989|#define CKA_TOKEN 0x00000001UL
  ------------------
  666|       |
  667|  13.5k|	for (int i = 0; i < 13; i++) {
  ------------------
  |  Branch (667:18): [True: 12.6k, False: 963]
  ------------------
  668|       |		/* ... | present -> 0/1 | value | ...*/
  669|  12.6k|		if (*size < 3)
  ------------------
  |  Branch (669:7): [True: 26, False: 12.6k]
  ------------------
  670|     26|			return 1;
  671|  12.6k|		if ((*data)[0] % 2) {
  ------------------
  |  Branch (671:7): [True: 2.19k, False: 10.4k]
  ------------------
  672|  2.19k|			fill_bool_attr(keyTemplate, n_attr, bool_types[i], (*data)[1] % 2);
  673|  2.19k|			(*data)++; (*size)--;
  674|  2.19k|		}
  675|  12.6k|		(*data)++; (*size)--;
  676|  12.6k|	}
  677|       |
  678|    963|	if (*size > 2 && (*data)[0] % 2 && *n_attr < 20){
  ------------------
  |  Branch (678:6): [True: 957, False: 6]
  |  Branch (678:19): [True: 176, False: 781]
  |  Branch (678:37): [True: 176, False: 0]
  ------------------
  679|       |		/* ... | present -> 0/1 | value | ...*/
  680|    176|		key_type = (CK_ULONG) (*data)[1];
  681|    176|		FILL_ATTR((*keyTemplate)[*n_attr], CKA_KEY_TYPE, &key_type, sizeof(key_type));
  ------------------
  |  |  631|    176|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|    176|	(attr).type=(typ); \
  |  |  633|    176|	(attr).pValue=(val); \
  |  |  634|    176|	(attr).ulValueLen=len; \
  |  |  635|    176|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 176]
  |  |  ------------------
  ------------------
  682|    176|		++(*n_attr);
  683|    176|		(*data) += 2;
  684|    176|		(*size) -= 2;
  685|    176|	}
  686|       |
  687|    963|	if (*size > 3 && (*data)[0] % 2 && *n_attr < 20){
  ------------------
  |  Branch (687:6): [True: 944, False: 19]
  |  Branch (687:19): [True: 93, False: 851]
  |  Branch (687:37): [True: 93, False: 0]
  ------------------
  688|       |		/* ... | present -> 0/1 | len | len | data | ... */
  689|     93|		(*data)++; (*size)--;
  690|     93|		ptr = *data;
  691|     93|		if ((ecparams_size = get_buffer(&ptr, *size, data, size, 256)) == 0)
  ------------------
  |  Branch (691:7): [True: 2, False: 91]
  ------------------
  692|      2|			return 1;
  693|     91|		memcpy(ecparams, ptr, ecparams_size);
  694|     91|		FILL_ATTR((*keyTemplate)[*n_attr], CKA_EC_PARAMS, ecparams, ecparams_size);
  ------------------
  |  |  631|     91|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     91|	(attr).type=(typ); \
  |  |  633|     91|	(attr).pValue=(val); \
  |  |  634|     91|	(attr).ulValueLen=len; \
  |  |  635|     91|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 91]
  |  |  ------------------
  ------------------
  695|     91|		++(*n_attr);
  696|     91|	}
  697|       |
  698|    961|	if (*size > 3 && (*data)[0] % 2 && *n_attr < 20){
  ------------------
  |  Branch (698:6): [True: 937, False: 24]
  |  Branch (698:19): [True: 72, False: 865]
  |  Branch (698:37): [True: 72, False: 0]
  ------------------
  699|       |		/* ... | present -> 0/1 | len | len | data | ... */
  700|     72|		(*data)++; (*size)--;
  701|     72|		ptr = *data;
  702|     72|		if ((opt_object_label_size = get_buffer(&ptr, *size, data, size, 128)) == 0)
  ------------------
  |  Branch (702:7): [True: 4, False: 68]
  ------------------
  703|      4|			return 1;
  704|     68|		memcpy(opt_object_label, ptr, opt_object_label_size);
  705|     68|		FILL_ATTR((*keyTemplate)[*n_attr], CKA_LABEL, opt_object_label, opt_object_label_size);
  ------------------
  |  |  631|     68|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     68|	(attr).type=(typ); \
  |  |  633|     68|	(attr).pValue=(val); \
  |  |  634|     68|	(attr).ulValueLen=len; \
  |  |  635|     68|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 68]
  |  |  ------------------
  ------------------
  706|     68|		++(*n_attr);
  707|     68|	}
  708|       |
  709|    957|	if (*size > 3 && (*data)[0] % 2 && *n_attr < 20){
  ------------------
  |  Branch (709:6): [True: 931, False: 26]
  |  Branch (709:19): [True: 56, False: 875]
  |  Branch (709:37): [True: 56, False: 0]
  ------------------
  710|       |		/* ... | present -> 0/1 | len | len | data | ... */
  711|     56|		(*data)++; (*size)--;
  712|     56|		ptr = *data;
  713|     56|		if ((opt_object_id_len = get_buffer(&ptr, *size, data, size, 100)) == 0)
  ------------------
  |  Branch (713:7): [True: 3, False: 53]
  ------------------
  714|      3|			return 1;
  715|     53|		memcpy(opt_object_id, ptr, opt_object_id_len);
  716|     53|		FILL_ATTR((*keyTemplate)[*n_attr], CKA_ID, opt_object_id, opt_object_id_len);
  ------------------
  |  |  631|     53|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     53|	(attr).type=(typ); \
  |  |  633|     53|	(attr).pValue=(val); \
  |  |  634|     53|	(attr).ulValueLen=len; \
  |  |  635|     53|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 53]
  |  |  ------------------
  ------------------
  717|     53|		++(*n_attr);
  718|     53|	}
  719|    954|	if (*size > 4 && (*data)[0]  % 2 && *n_attr < 20){
  ------------------
  |  Branch (719:6): [True: 921, False: 33]
  |  Branch (719:19): [True: 41, False: 880]
  |  Branch (719:38): [True: 41, False: 0]
  ------------------
  720|       |		/* ... | present -> 0/1 | len | mech1 | mech2 | ... | mechn | ... */
  721|     41|		opt_allowed_mechanisms_len = (*data)[1] > 20 ? 20 : (*data)[1];
  ------------------
  |  Branch (721:32): [True: 21, False: 20]
  ------------------
  722|     41|		(*data) += 2;
  723|     41|		(*size) -= 2;
  724|    369|		for (size_t i = 0; i < opt_allowed_mechanisms_len; i++) {
  ------------------
  |  Branch (724:22): [True: 337, False: 32]
  ------------------
  725|    337|			if (*size <= sizeof(unsigned int))
  ------------------
  |  Branch (725:8): [True: 9, False: 328]
  ------------------
  726|      9|				return 1;
  727|    328|			opt_allowed_mechanisms[i] = *((unsigned int *)data);
  728|    328|			(*data) += sizeof(unsigned int);
  729|    328|			(*size) -= sizeof(unsigned int);
  730|    328|		}
  731|     32|		FILL_ATTR((*keyTemplate)[*n_attr], CKA_ALLOWED_MECHANISMS, opt_allowed_mechanisms, opt_allowed_mechanisms_len);
  ------------------
  |  |  631|     32|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     32|	(attr).type=(typ); \
  |  |  633|     32|	(attr).pValue=(val); \
  |  |  634|     32|	(attr).ulValueLen=len; \
  |  |  635|     32|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 32]
  |  |  ------------------
  ------------------
  732|     32|		++(*n_attr);
  733|     32|	}
  734|    945|	if (*size == 0)
  ------------------
  |  Branch (734:6): [True: 0, False: 945]
  ------------------
  735|      0|		return 1;
  736|    945|	return 0;
  737|    945|}
LLVMFuzzerTestOneInput:
 1056|  15.9k|{
 1057|  15.9k|	uint8_t operation = 0;
 1058|  15.9k|	void (*func_ptr[])(const uint8_t*, size_t) = {
 1059|  15.9k|		test_change_pin,
 1060|  15.9k|		test_init_pin,
 1061|  15.9k|		test_init_token,
 1062|  15.9k|		test_random,
 1063|  15.9k|		test_digest_update,
 1064|  15.9k|		test_digest,
 1065|  15.9k|		test_sign,
 1066|  15.9k|		test_verify,
 1067|  15.9k|		test_decrypt,
 1068|  15.9k|		test_wrap,
 1069|  15.9k|		test_unwrap,
 1070|  15.9k|		test_derive,
 1071|  15.9k|		test_genkeypair,
 1072|  15.9k|		test_store_data,
 1073|  15.9k|		test_store_cert,
 1074|  15.9k|		test_store_key
 1075|  15.9k|	};
 1076|       |
 1077|  15.9k|	if (size < 10)
  ------------------
  |  Branch (1077:6): [True: 6, False: 15.9k]
  ------------------
 1078|      6|		return 0;
 1079|       |
 1080|  15.9k|	operation = *data % 16;
 1081|  15.9k|	data++;
 1082|  15.9k|	size--;
 1083|       |
 1084|  15.9k|	func_ptr[operation](data, size);
 1085|       |
 1086|  15.9k|	return 0;
 1087|  15.9k|}
fuzz_pkcs11.c:set_mechanism:
  176|  1.97k|{
  177|  1.97k|	if (*size < sizeof(unsigned long int))
  ------------------
  |  Branch (177:6): [True: 0, False: 1.97k]
  ------------------
  178|      0|		return 1;
  179|       |
  180|  1.97k|	memset(mech, 0, sizeof(*mech));
  181|  1.97k|	(*mech).mechanism = *((unsigned long int *)*data);
  182|  1.97k|	*data += sizeof(unsigned long int);
  183|  1.97k|	*size -= sizeof(unsigned long int);
  184|  1.97k|	return 0;
  185|  1.97k|}
fuzz_pkcs11.c:fuzz_pkcs11_initialize:
  152|  15.7k|{
  153|  15.7k|	p11 = &pkcs11_function_list_3_0;
  154|       |
  155|  15.7k|	context = NULL;
  156|  15.7k|	memset(&sc_pkcs11_conf, 0, sizeof(struct sc_pkcs11_config));
  157|       |
  158|  15.7k|	p11->C_Initialize(NULL);
  159|       |
  160|  15.7k|	#if FUZZING
  161|       |	/* fuzz target can connect to real card via C_Initialize */
  162|  15.7k|	if (fuzz_card_connect(data, size, slot_out) != CKR_OK) {
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (162:6): [True: 4.24k, False: 11.5k]
  ------------------
  163|  4.24k|		p11->C_Finalize(NULL);
  164|  4.24k|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|  4.24k|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  165|  4.24k|	}
  166|  11.5k|	#endif
  167|       |
  168|  11.5k|	if (p11->C_OpenSession(0, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL, NULL, session) != CKR_OK) {
  ------------------
  |  |  403|  11.5k|#define CKF_SERIAL_SESSION 0x00000004UL
  ------------------
              	if (p11->C_OpenSession(0, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL, NULL, session) != CKR_OK) {
  ------------------
  |  |  402|  11.5k|#define CKF_RW_SESSION 0x00000002UL
  ------------------
              	if (p11->C_OpenSession(0, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL, NULL, session) != CKR_OK) {
  ------------------
  |  | 1086|  11.5k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (168:6): [True: 1.16k, False: 10.3k]
  ------------------
  169|  1.16k|		p11->C_Finalize(NULL);
  170|  1.16k|		return CKR_GENERAL_ERROR;
  ------------------
  |  | 1090|  1.16k|#define CKR_GENERAL_ERROR 0x00000005UL
  ------------------
  171|  1.16k|	}
  172|  10.3k|	return CKR_OK;
  ------------------
  |  | 1086|  10.3k|#define CKR_OK 0x00000000UL
  ------------------
  173|  11.5k|}
fuzz_pkcs11.c:fuzz_card_connect:
   53|  15.7k|{
   54|       |	/* Works in the same manner as card_detect() for only one slot and card with virtual reader */
   55|  15.7k|	struct sc_pkcs11_card *p11card = NULL;
   56|  15.7k|	struct sc_reader *reader = NULL;
   57|  15.7k|	struct sc_app_info *app_generic = NULL;
   58|  15.7k|	sc_pkcs11_slot_t *slot = NULL;
   59|  15.7k|	CK_RV rv = CKR_OK;
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
   60|  15.7k|	int free_p11card = 0;
   61|       |
   62|       |	/* Erase possible virtual slots*/
   63|  15.7k|	list_clear(&virtual_slots);
   64|       |
   65|       |	/* Erase possible readers from context */
   66|  15.7k|	while (list_size(&context->readers)) {
  ------------------
  |  Branch (66:9): [True: 0, False: 15.7k]
  ------------------
   67|      0|		sc_reader_t *rdr = (sc_reader_t *) list_get_at(&context->readers, 0);
   68|      0|		_sc_delete_reader(context, rdr);
   69|      0|	}
   70|  15.7k|	if (context->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (70:6): [True: 15.7k, False: 0]
  ------------------
   71|  15.7k|		context->reader_driver->ops->finish(context);
   72|       |
   73|       |	/* Create virtual reader */
   74|  15.7k|	context->reader_driver = sc_get_fuzz_driver();
   75|  15.7k|	fuzz_add_reader(context, data, size);
   76|  15.7k|	reader = sc_ctx_get_reader(context, 0);
   77|       |
   78|       |	/* Add slot for reader */
   79|  15.7k|	if (create_slot(reader) != CKR_OK) {
  ------------------
  |  | 1086|  15.7k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (79:6): [True: 0, False: 15.7k]
  ------------------
   80|      0|		goto fail;
   81|      0|	}
   82|       |
   83|       |	/* Locate a slot related to the reader */
   84|  15.7k|	for (size_t i = 0; i < list_size(&virtual_slots); i++) {
  ------------------
  |  Branch (84:21): [True: 15.7k, False: 0]
  ------------------
   85|  15.7k|		slot = (sc_pkcs11_slot_t *)list_get_at(&virtual_slots, (int)i);
   86|  15.7k|		if (slot->reader == reader) {
  ------------------
  |  Branch (86:7): [True: 15.7k, False: 0]
  ------------------
   87|  15.7k|			p11card = slot->p11card;
   88|  15.7k|			break;
   89|  15.7k|		}
   90|  15.7k|	}
   91|       |
   92|       |	/* Create p11card */
   93|  15.7k|	p11card = (struct sc_pkcs11_card *)calloc(1, sizeof(struct sc_pkcs11_card));
   94|  15.7k|	p11card->reader = reader;
   95|  15.7k|	free_p11card = 1;
   96|       |
   97|       |	/* Connect card to reader */
   98|  15.7k|	if ((rv = sc_connect_card(reader, &p11card->card)) != SC_SUCCESS) {
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (98:6): [True: 3.02k, False: 12.7k]
  ------------------
   99|  3.02k|		goto fail;
  100|  3.02k|	}
  101|  12.7k|	init_slot_info(&slot->slot_info, reader);
  102|       |
  103|       |	/* Instead of detecting framework*/
  104|  12.7k|	p11card->framework = &framework_pkcs15;
  105|       |
  106|       |	/* Bind 'generic' application or (emulated?) card without applications */
  107|  12.7k|	app_generic = sc_pkcs15_get_application_by_type(p11card->card, "generic");
  108|  12.7k|	if (app_generic || !p11card->card->app_count) {
  ------------------
  |  Branch (108:6): [True: 0, False: 12.7k]
  |  Branch (108:21): [True: 11.3k, False: 1.43k]
  ------------------
  109|  11.3k|		scconf_block *conf_block = NULL;
  110|       |
  111|  11.3k|		conf_block = sc_match_atr_block(p11card->card->ctx, NULL, &p11card->reader->atr);
  112|  11.3k|		if (!conf_block) /* check default block */
  ------------------
  |  Branch (112:7): [True: 11.3k, False: 0]
  ------------------
  113|  11.3k|			conf_block = sc_get_conf_block(context, "framework", "pkcs15", 1);
  114|       |
  115|  11.3k|		rv = p11card->framework->bind(p11card, app_generic);
  116|  11.3k|		if (rv != CKR_TOKEN_NOT_RECOGNIZED && rv != CKR_OK)
  ------------------
  |  | 1145|  22.6k|#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1UL
  ------------------
              		if (rv != CKR_TOKEN_NOT_RECOGNIZED && rv != CKR_OK)
  ------------------
  |  | 1086|  6.16k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (116:7): [True: 6.16k, False: 5.14k]
  |  Branch (116:41): [True: 1.21k, False: 4.94k]
  ------------------
  117|  1.21k|			goto fail;
  118|       |
  119|  10.0k|		rv = p11card->framework->create_tokens(p11card, app_generic);
  120|  10.0k|		if (rv != CKR_OK)
  ------------------
  |  | 1086|  10.0k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (120:7): [True: 0, False: 10.0k]
  ------------------
  121|      0|			goto fail;
  122|  10.0k|		free_p11card = 0;
  123|  10.0k|	}
  124|       |	
  125|       |	/* Bind rest of application*/
  126|  15.3k|	for (int j = 0; j < p11card->card->app_count; j++)   {
  ------------------
  |  Branch (126:18): [True: 3.81k, False: 11.5k]
  ------------------
  127|  3.81k|		struct sc_app_info *app_info = p11card->card->app[j];
  128|       |
  129|  3.81k|		if (app_generic && app_generic == p11card->card->app[j])
  ------------------
  |  Branch (129:7): [True: 0, False: 3.81k]
  |  Branch (129:22): [True: 0, False: 0]
  ------------------
  130|      0|			continue;
  131|       |
  132|  3.81k|		if (p11card->framework->bind(p11card, app_info) != CKR_OK) {
  ------------------
  |  | 1086|  3.81k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (132:7): [True: 3.18k, False: 633]
  ------------------
  133|  3.18k|			continue;
  134|  3.18k|		}
  135|    633|		rv = p11card->framework->create_tokens(p11card, app_info);
  136|    633|		if (rv != CKR_OK) {
  ------------------
  |  | 1086|    633|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (136:7): [True: 0, False: 633]
  ------------------
  137|      0|			goto fail;
  138|      0|		}
  139|    633|		free_p11card = 0;
  140|    633|	}
  141|  11.5k|	if (slot_out)
  ------------------
  |  Branch (141:6): [True: 249, False: 11.2k]
  ------------------
  142|    249|		*slot_out = slot;
  143|  15.7k|fail:
  144|  15.7k|	if (free_p11card) {
  ------------------
  |  Branch (144:6): [True: 5.40k, False: 10.3k]
  ------------------
  145|  5.40k|		sc_pkcs11_card_free(p11card);
  146|  5.40k|	}
  147|  15.7k|	return (int)rv;
  148|  11.5k|}
fuzz_pkcs11.c:test_change_pin:
  188|    958|{
  189|    958|	CK_SESSION_HANDLE session;
  190|    958|	CK_TOKEN_INFO     info;
  191|    958|	char             *pin = NULL;
  192|    958|	char             *new_pin = NULL;
  193|    958|	int               login_type = data[0];
  194|    958|	data++; size--;
  195|       |
  196|    958|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (196:6): [True: 2, False: 956]
  ------------------
  197|      2|		goto end;
  198|    956|	if (!(new_pin = extract_word(&data, &size)))
  ------------------
  |  Branch (198:6): [True: 4, False: 952]
  ------------------
  199|      4|		goto end;
  200|       |
  201|    952|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    952|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (201:6): [True: 136, False: 816]
  ------------------
  202|    136|		goto end;
  203|    816|	p11->C_GetTokenInfo(0, &info);
  204|    816|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, pin == NULL ? 0 : strlen(pin));
  ------------------
  |  Branch (204:57): [True: 0, False: 816]
  ------------------
  205|    816|	p11->C_SetPIN(session,
  206|    816|		(CK_UTF8CHAR *) pin, pin == NULL ? 0 : strlen(pin),
  ------------------
  |  Branch (206:24): [True: 0, False: 816]
  ------------------
  207|    816|		(CK_UTF8CHAR *) new_pin, new_pin == NULL ? 0 : strlen(new_pin));
  ------------------
  |  Branch (207:28): [True: 0, False: 816]
  ------------------
  208|       |
  209|    816|	p11->C_CloseSession(session);
  210|    816|	p11->C_Finalize(NULL);
  211|    958|end:
  212|    958|	free(new_pin);
  213|    958|	free(pin);
  214|    958|}
fuzz_pkcs11.c:test_init_pin:
  217|    450|{
  218|    450|	CK_SESSION_HANDLE session;
  219|    450|	CK_TOKEN_INFO     info;
  220|    450|	char             *pin = NULL;
  221|    450|	char             *so_pin = NULL;
  222|    450|	int               login_type = data[0];
  223|    450|	data++; size--;
  224|       |
  225|    450|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (225:6): [True: 1, False: 449]
  ------------------
  226|      1|		goto end;
  227|    449|	if (!(so_pin = extract_word(&data, &size)))
  ------------------
  |  Branch (227:6): [True: 3, False: 446]
  ------------------
  228|      3|		goto end;
  229|       |
  230|    446|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    446|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (230:6): [True: 141, False: 305]
  ------------------
  231|    141|		goto end;
  232|    305|	p11->C_GetTokenInfo(0, &info);
  233|    305|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) so_pin, so_pin == NULL ? 0 : strlen(so_pin));
  ------------------
  |  Branch (233:60): [True: 0, False: 305]
  ------------------
  234|    305|	p11->C_InitPIN(session, (CK_UTF8CHAR *) pin, pin == NULL ? 0 : strlen(pin));
  ------------------
  |  Branch (234:47): [True: 0, False: 305]
  ------------------
  235|       |
  236|    305|	p11->C_CloseSession(session);
  237|    305|	p11->C_Finalize(NULL);
  238|    450|end:
  239|    450|	free(pin);
  240|    450|	free(so_pin);
  241|    450|}
fuzz_pkcs11.c:test_init_token:
  244|    398|{
  245|    398|	CK_SESSION_HANDLE session;
  246|    398|	char             *pin = NULL;
  247|    398|	unsigned char    *label = NULL;
  248|    398|	size_t            label_len = 0;
  249|    398|	unsigned char     token_label[33];
  250|    398|	sc_pkcs11_slot_t *slot = NULL;
  251|       |	/* token label must be padded with blank characters, and which must not be null-terminated*/
  252|    398|	memset(token_label, ' ', sizeof(token_label));
  253|       |
  254|    398|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (254:6): [True: 1, False: 397]
  ------------------
  255|      1|		goto end;
  256|    397|	if (!(label = (unsigned char *) extract_word(&data, &size)))
  ------------------
  |  Branch (256:6): [True: 1, False: 396]
  ------------------
  257|      1|		goto end;
  258|    396|	label_len = strlen((char *) label);
  259|    396|	memcpy(token_label, label, label_len < 33 ? label_len : 32);
  ------------------
  |  Branch (259:29): [True: 386, False: 10]
  ------------------
  260|       |
  261|    396|	if (fuzz_pkcs11_initialize(data, size, &slot, &session) != CKR_OK)
  ------------------
  |  | 1086|    396|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (261:6): [True: 148, False: 248]
  ------------------
  262|    148|		goto end;
  263|    248|	p11->C_InitToken(slot->id, (CK_UTF8CHAR *) pin, pin == NULL ? 0 : strlen(pin), token_label);
  ------------------
  |  Branch (263:50): [True: 0, False: 248]
  ------------------
  264|       |
  265|    248|	p11->C_CloseSession(session);
  266|    248|	p11->C_Finalize(NULL);
  267|    398|end:
  268|    398|	free(pin);
  269|    398|	free(label);
  270|    398|}
fuzz_pkcs11.c:test_random:
  273|  11.6k|{
  274|  11.6k|	CK_SESSION_HANDLE session;
  275|  11.6k|	size_t            random_len = data[0];
  276|  11.6k|	CK_BYTE           buf[256];
  277|  11.6k|	data++; size--;
  278|       |
  279|  11.6k|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|  11.6k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (279:6): [True: 4.68k, False: 6.96k]
  ------------------
  280|  4.68k|		return;
  281|       |
  282|  6.96k|	p11->C_GenerateRandom(session, buf, random_len);
  283|       |
  284|  6.96k|	p11->C_CloseSession(session);
  285|       |	p11->C_Finalize(NULL);
  286|  6.96k|}
fuzz_pkcs11.c:test_digest_update:
  289|    219|{
  290|    219|	CK_SESSION_HANDLE session;
  291|    219|	const uint8_t    *dig_data = NULL;
  292|    219|	size_t            dig_size = 0;
  293|    219|	CK_MECHANISM      mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|    219|#define NULL_PTR ((void *)0)
  ------------------
  294|    219|	unsigned char     buffer[64] = {0};
  295|    219|	CK_ULONG          hash_len = sizeof(buffer);
  296|    219|	size_t to_process = 0;
  297|    219|	CK_RV rv = 0;
  298|       |
  299|    219|	if (set_mechanism(&data, &size, &mech))
  ------------------
  |  Branch (299:6): [True: 0, False: 219]
  ------------------
  300|      0|		return;
  301|       |
  302|       |	/* Copy data for hashing*/
  303|    219|	dig_data = data;
  304|    219|	if ((dig_size = get_buffer(&dig_data, size, &data, &size, 6000)) == 0)
  ------------------
  |  Branch (304:6): [True: 2, False: 217]
  ------------------
  305|      2|		return;
  306|       |
  307|    217|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    217|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (307:6): [True: 27, False: 190]
  ------------------
  308|     27|		return;
  309|       |
  310|    190|	if (p11->C_DigestInit(session, &mech) != CKR_OK)
  ------------------
  |  | 1086|    190|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (310:6): [True: 182, False: 8]
  ------------------
  311|    182|		goto end;
  312|       |
  313|    108|	while (dig_size > 0) {
  ------------------
  |  Branch (313:9): [True: 100, False: 8]
  ------------------
  314|    100|		to_process = dig_size > sizeof(buffer) ? sizeof(buffer) : dig_size;
  ------------------
  |  Branch (314:16): [True: 92, False: 8]
  ------------------
  315|    100|		dig_size -= to_process;
  316|    100|		memcpy(buffer, dig_data, to_process);
  317|    100|		dig_data += to_process;
  318|       |
  319|    100|		rv = p11->C_DigestUpdate(session, buffer, to_process);
  320|    100|		if (rv != CKR_OK)
  ------------------
  |  | 1086|    100|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (320:7): [True: 0, False: 100]
  ------------------
  321|      0|			goto end;
  322|    100|	}
  323|      8|	hash_len = sizeof(buffer);
  324|      8|	p11->C_DigestFinal(session, buffer, &hash_len);
  325|       |
  326|    190|end:
  327|    190|	p11->C_CloseSession(session);
  328|       |	p11->C_Finalize(NULL);
  329|    190|}
fuzz_pkcs11.c:test_sign:
  396|    463|{
  397|    463|	CK_SESSION_HANDLE    session;
  398|    463|	uint8_t              login_type = CKU_USER;
  ------------------
  |  | 1211|    463|#define CKU_USER 1UL
  ------------------
  399|    463|	char                *pin = NULL;
  400|    463|	const unsigned char *opt_id;
  401|    463|	size_t               opt_id_len = 0;
  402|    463|	const uint8_t       *sign_data = NULL;
  403|    463|	size_t               sign_data_size = 0;
  404|    463|	CK_OBJECT_HANDLE     key = CK_INVALID_HANDLE;
  ------------------
  |  |   33|    463|#define CK_INVALID_HANDLE 0UL
  ------------------
  405|    463|	unsigned char        in_buffer[1025], sig_buffer[512];
  406|    463|	CK_MECHANISM         mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|    463|#define NULL_PTR ((void *)0)
  ------------------
  407|    463|	CK_ULONG             sig_len = sizeof(sig_buffer);
  408|    463|	size_t               to_process = 0;
  409|    463|	CK_TOKEN_INFO        info;
  410|       |
  411|       |	/* Process options*/
  412|    463|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (412:6): [True: 0, False: 463]
  |  Branch (412:44): [True: 1, False: 462]
  ------------------
  413|      1|		return;
  414|    462|	login_type = data[0];
  415|    462|	data++; size--;
  416|    462|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (416:6): [True: 3, False: 459]
  ------------------
  417|      3|		return;
  418|    459|	opt_id = data;
  419|    459|	opt_id_len = get_buffer(&opt_id, size, &data, &size, 256);
  420|       |
  421|       |	/* Prepare buffer for signing */
  422|    459|	sign_data = data;
  423|    459|	if ((sign_data_size = get_buffer(&sign_data, size, &data, &size, 6000)) == 0)
  ------------------
  |  Branch (423:6): [True: 4, False: 455]
  ------------------
  424|      4|		goto end;
  425|       |
  426|       |	/* Initialize */
  427|    455|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    455|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (427:6): [True: 22, False: 433]
  ------------------
  428|     22|		goto end;
  429|    433|	p11->C_GetTokenInfo(0, &info);
  430|    433|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  431|    433|	fuzz_find_object(session, CKO_PRIVATE_KEY, &key, opt_id_len ? opt_id : NULL, opt_id_len);
  ------------------
  |  | 1030|    433|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (431:51): [True: 7, False: 426]
  ------------------
  432|       |
  433|    433|	if (p11->C_SignInit(session, &mech, key) != CKR_OK)
  ------------------
  |  | 1086|    433|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (433:6): [True: 195, False: 238]
  ------------------
  434|    195|		goto fin;
  435|    238|	p11->C_Login(session, CKU_CONTEXT_SPECIFIC, (CK_UTF8CHAR *) pin, strlen(pin));
  ------------------
  |  | 1212|    238|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  436|       |
  437|    238|	if (sign_data_size <= sizeof(in_buffer)) {
  ------------------
  |  Branch (437:6): [True: 234, False: 4]
  ------------------
  438|    234|		memcpy(in_buffer, sign_data, sign_data_size);
  439|    234|		p11->C_Sign(session, in_buffer, sign_data_size, sig_buffer, &sig_len);
  440|    234|	} else {
  441|     16|		while (sign_data_size > 0) {
  ------------------
  |  Branch (441:10): [True: 12, False: 4]
  ------------------
  442|     12|			to_process = sign_data_size < sizeof(in_buffer) ? sign_data_size : sizeof(in_buffer);
  ------------------
  |  Branch (442:17): [True: 4, False: 8]
  ------------------
  443|     12|			sign_data_size -= to_process;
  444|     12|			memcpy(in_buffer, sign_data, to_process);
  445|     12|			sign_data += to_process;
  446|       |
  447|     12|			if (p11->C_SignUpdate(session, in_buffer, to_process) != CKR_OK)
  ------------------
  |  | 1086|     12|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (447:8): [True: 0, False: 12]
  ------------------
  448|      0|				goto fin;
  449|     12|		}
  450|       |
  451|      4|		sig_len = sizeof(sig_buffer);
  452|      4|		p11->C_SignFinal(session, sig_buffer, &sig_len);
  453|      4|	}
  454|       |
  455|    433|fin:
  456|    433|	p11->C_CloseSession(session);
  457|    433|	p11->C_Finalize(NULL);
  458|    459|end:
  459|    459|	free(pin);
  460|    459|}
fuzz_pkcs11.c:fuzz_find_object:
  366|  1.47k|{
  367|       |	/* taken from tools/pkcs11-tool.c */
  368|  1.47k|	CK_ATTRIBUTE attrs[2];
  369|  1.47k|	unsigned int nattrs = 0;
  370|  1.47k|	CK_ULONG     count = 0;
  371|       |
  372|  1.47k|	attrs[0].type = CKA_CLASS;
  ------------------
  |  |  137|  1.47k|#define CKA_CLASS 0x00000000UL
  ------------------
  373|  1.47k|	attrs[0].pValue = &cls;
  374|  1.47k|	attrs[0].ulValueLen = sizeof(cls);
  375|  1.47k|	nattrs++;
  376|  1.47k|	if (id) {
  ------------------
  |  Branch (376:6): [True: 297, False: 1.18k]
  ------------------
  377|    297|		attrs[nattrs].type = CKA_ID;
  ------------------
  |  |  161|    297|#define CKA_ID 0x00000102UL
  ------------------
  378|    297|		attrs[nattrs].pValue = (void *) id;
  379|    297|		attrs[nattrs].ulValueLen = id_len;
  380|    297|		nattrs++;
  381|    297|	}
  382|       |
  383|  1.47k|	if (p11->C_FindObjectsInit(sess, attrs, nattrs) != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (383:6): [True: 0, False: 1.47k]
  ------------------
  384|      0|		return -1;
  385|       |
  386|  1.47k|	if (p11->C_FindObjects(sess, ret, 1, &count) != CKR_OK)
  ------------------
  |  | 1086|  1.47k|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (386:6): [True: 0, False: 1.47k]
  ------------------
  387|      0|		return -1;
  388|       |
  389|  1.47k|	if (count == 0)
  ------------------
  |  Branch (389:6): [True: 767, False: 711]
  ------------------
  390|    767|		*ret = CK_INVALID_HANDLE;
  ------------------
  |  |   33|    767|#define CK_INVALID_HANDLE 0UL
  ------------------
  391|  1.47k|	p11->C_FindObjectsFinal(sess);
  392|  1.47k|	return (int)count;
  393|  1.47k|}
fuzz_pkcs11.c:test_verify:
  463|    256|{
  464|    256|	CK_SESSION_HANDLE    session;
  465|    256|	CK_MECHANISM         mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|    256|#define NULL_PTR ((void *)0)
  ------------------
  466|    256|	uint8_t              login_type = CKU_USER;
  ------------------
  |  | 1211|    256|#define CKU_USER 1UL
  ------------------
  467|    256|	char                *pin = NULL;
  468|    256|	const unsigned char *opt_id = NULL;
  469|    256|	size_t               opt_id_len = 0;
  470|    256|	const uint8_t       *verify_data = NULL, *sig_data = NULL;
  471|    256|	size_t               verify_data_size = 0;
  472|    256|	CK_OBJECT_HANDLE     key = CK_INVALID_HANDLE;
  ------------------
  |  |   33|    256|#define CK_INVALID_HANDLE 0UL
  ------------------
  473|    256|	unsigned char        in_buffer[1025], sig_buffer[512];
  474|    256|	CK_ULONG             sig_len = sizeof(sig_buffer);
  475|    256|	size_t               to_process = 0;
  476|       |
  477|       |	/* Process options*/
  478|    256|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (478:6): [True: 0, False: 256]
  |  Branch (478:44): [True: 1, False: 255]
  ------------------
  479|      1|		return;
  480|    255|	login_type = data[0];
  481|    255|	data++; size--;
  482|    255|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (482:6): [True: 3, False: 252]
  ------------------
  483|      3|		return;
  484|    252|	opt_id = data;
  485|    252|	opt_id_len = get_buffer(&opt_id, size, &data, &size, 256);
  486|       |
  487|       |	/* Prepare buffer with data */
  488|    252|	verify_data = data;
  489|    252|	if ((verify_data_size = get_buffer(&verify_data, size, &data, &size, 6000)) == 0)
  ------------------
  |  Branch (489:6): [True: 5, False: 247]
  ------------------
  490|      5|		goto end;
  491|       |	/* Get buffer with signature */
  492|    247|	sig_data = data;
  493|    247|	if ((sig_len = get_buffer(&sig_data, size, &data, &size, 512)) == 0)
  ------------------
  |  Branch (493:6): [True: 6, False: 241]
  ------------------
  494|      6|		goto end;
  495|    241|	memcpy(sig_buffer, sig_data, sig_len);
  496|       |
  497|       |	/* Initialize */
  498|    241|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    241|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (498:6): [True: 5, False: 236]
  ------------------
  499|      5|		goto end;
  500|       |
  501|    236|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  502|       |
  503|    236|	if (!fuzz_find_object(session, CKO_PUBLIC_KEY, &key, opt_id_len ? opt_id : NULL, opt_id_len)
  ------------------
  |  | 1029|    236|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
  |  Branch (503:6): [True: 166, False: 70]
  |  Branch (503:55): [True: 109, False: 127]
  ------------------
  504|    166|		&& !fuzz_find_object(session, CKO_CERTIFICATE, &key, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1028|    166|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
  |  Branch (504:6): [True: 166, False: 0]
  |  Branch (504:56): [True: 109, False: 57]
  ------------------
  505|    166|		goto fin;
  506|       |
  507|     70|	if (p11->C_VerifyInit(session, &mech, key) != CKR_OK)
  ------------------
  |  | 1086|     70|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (507:6): [True: 20, False: 50]
  ------------------
  508|     20|		goto fin;
  509|       |
  510|     50|	if (verify_data_size <= sizeof(in_buffer)) {
  ------------------
  |  Branch (510:6): [True: 50, False: 0]
  ------------------
  511|     50|		memcpy(in_buffer, verify_data, verify_data_size);
  512|     50|		p11->C_Verify(session, in_buffer, verify_data_size, sig_buffer, sig_len);
  513|     50|	} else {
  514|      0|		while (verify_data_size > 0) {
  ------------------
  |  Branch (514:10): [True: 0, False: 0]
  ------------------
  515|      0|			to_process = verify_data_size < sizeof(in_buffer) ? verify_data_size : sizeof(in_buffer);
  ------------------
  |  Branch (515:17): [True: 0, False: 0]
  ------------------
  516|      0|			verify_data_size -= to_process;
  517|      0|			memcpy(in_buffer, verify_data, to_process);
  518|      0|			verify_data += to_process;
  519|       |
  520|      0|			if (p11->C_VerifyUpdate(session, in_buffer, to_process) != CKR_OK)
  ------------------
  |  | 1086|      0|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (520:8): [True: 0, False: 0]
  ------------------
  521|      0|				goto fin;
  522|      0|		}
  523|       |
  524|      0|		p11->C_VerifyFinal(session, sig_buffer, sig_len);
  525|      0|	}
  526|    236|fin:
  527|    236|	p11->C_CloseSession(session);
  528|    236|	p11->C_Finalize(NULL);
  529|    252|end:
  530|    252|	free(pin);
  531|    252|}
fuzz_pkcs11.c:test_decrypt:
  534|    523|{
  535|    523|	CK_SESSION_HANDLE    session;
  536|    523|	uint8_t              login_type = CKU_USER;
  ------------------
  |  | 1211|    523|#define CKU_USER 1UL
  ------------------
  537|    523|	char                *pin = NULL;
  538|    523|	const unsigned char *opt_id;
  539|    523|	size_t               opt_id_len = 0;
  540|    523|	const uint8_t       *dec_data = NULL;
  541|    523|	size_t               dec_data_size = 0;
  542|    523|	CK_OBJECT_HANDLE     key = CK_INVALID_HANDLE;
  ------------------
  |  |   33|    523|#define CK_INVALID_HANDLE 0UL
  ------------------
  543|    523|	unsigned char        in_buffer[1024], out_buffer[1024];
  544|    523|	CK_MECHANISM         mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|    523|#define NULL_PTR ((void *)0)
  ------------------
  545|    523|	size_t               out_len = 0;
  546|       |
  547|       |	/* Process options*/
  548|    523|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (548:6): [True: 0, False: 523]
  |  Branch (548:44): [True: 2, False: 521]
  ------------------
  549|      2|		return;
  550|    521|	login_type = data[0];
  551|    521|	data++; size--;
  552|    521|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (552:6): [True: 1, False: 520]
  ------------------
  553|      1|		return;
  554|    520|	opt_id = data;
  555|    520|	opt_id_len = get_buffer(&opt_id, size, &data, &size, 256);
  556|       |
  557|       |	/* Prepare buffer for signing */
  558|    520|	dec_data = data;
  559|    520|	if ((dec_data_size = get_buffer(&dec_data, size, &data, &size, 1024)) == 0)
  ------------------
  |  Branch (559:6): [True: 4, False: 516]
  ------------------
  560|      4|		goto end;
  561|       |
  562|       |	/* Initialize */
  563|    516|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    516|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (563:6): [True: 38, False: 478]
  ------------------
  564|     38|		goto end;
  565|       |
  566|    478|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  567|    478|	if (!fuzz_find_object(session, CKO_PRIVATE_KEY, &key, opt_id_len ? opt_id : NULL, opt_id_len)
  ------------------
  |  | 1030|    478|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (567:6): [True: 123, False: 355]
  |  Branch (567:56): [True: 31, False: 447]
  ------------------
  568|    123|		&& !fuzz_find_object(session, CKO_SECRET_KEY, &key, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1031|    123|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  |  Branch (568:6): [True: 123, False: 0]
  |  Branch (568:55): [True: 28, False: 95]
  ------------------
  569|    123|		goto fin;
  570|       |
  571|    355|	if (p11->C_DecryptInit(session, &mech, key) != CKR_OK)
  ------------------
  |  | 1086|    355|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (571:6): [True: 169, False: 186]
  ------------------
  572|    169|		goto fin;
  573|       |
  574|    186|	p11->C_Login(session, CKU_CONTEXT_SPECIFIC, (CK_UTF8CHAR *) pin, strlen(pin));
  ------------------
  |  | 1212|    186|#define CKU_CONTEXT_SPECIFIC 2UL
  ------------------
  575|    186|	out_len = sizeof(out_buffer);
  576|       |
  577|    186|	memcpy(in_buffer, dec_data, dec_data_size);
  578|    186|	p11->C_Decrypt(session, in_buffer, dec_data_size, out_buffer, &out_len);
  579|    478|fin:
  580|    478|	p11->C_CloseSession(session);
  581|    478|	p11->C_Finalize(NULL);
  582|    520|end:
  583|    520|	free(pin);
  584|    520|}
fuzz_pkcs11.c:test_wrap:
  587|     19|{
  588|     19|	CK_SESSION_HANDLE    session;
  589|     19|	uint8_t              login_type = CKU_USER;
  ------------------
  |  | 1211|     19|#define CKU_USER 1UL
  ------------------
  590|     19|	char                *pin = NULL;
  591|     19|	CK_BYTE              pWrappedKey[4096];
  592|     19|	CK_ULONG             pulWrappedKeyLen = sizeof(pWrappedKey);
  593|     19|	CK_MECHANISM         mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|     19|#define NULL_PTR ((void *)0)
  ------------------
  594|     19|	CK_OBJECT_HANDLE     hWrappingKey;
  595|     19|	CK_OBJECT_HANDLE     hkey;
  596|     19|	const unsigned char *hkey_id;
  597|     19|	const unsigned char *opt_id;
  598|     19|	size_t               opt_id_len = 0, hkey_id_len = 0;
  599|       |
  600|       |	/* Set options */
  601|     19|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (601:6): [True: 0, False: 19]
  |  Branch (601:44): [True: 2, False: 17]
  ------------------
  602|      2|		return;
  603|     17|	login_type = data[0];
  604|     17|	data++; size--;
  605|     17|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (605:6): [True: 1, False: 16]
  ------------------
  606|      1|		return;
  607|     16|	opt_id = data;
  608|     16|	opt_id_len = get_buffer(&opt_id, size, &data, &size, 256);
  609|     16|	hkey_id = data;
  610|     16|	hkey_id_len = get_buffer(&hkey_id, size, &data, &size, 256);
  611|       |
  612|       |	/* Initialize */
  613|     16|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|     16|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (613:6): [True: 7, False: 9]
  ------------------
  614|      7|		goto end;
  615|       |
  616|      9|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  617|      9|	if (!fuzz_find_object(session, CKO_SECRET_KEY, &hkey, hkey_id_len ? hkey_id : NULL, hkey_id_len))
  ------------------
  |  | 1031|      9|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  |  Branch (617:6): [True: 9, False: 0]
  |  Branch (617:56): [True: 6, False: 3]
  ------------------
  618|      9|		goto fin;
  619|      0|	if (!fuzz_find_object(session, CKO_PUBLIC_KEY, &hWrappingKey, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1029|      0|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
  |  Branch (619:6): [True: 0, False: 0]
  |  Branch (619:64): [True: 0, False: 0]
  ------------------
  620|      0|		if (!fuzz_find_object(session, CKO_SECRET_KEY, &hWrappingKey, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1031|      0|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  |  Branch (620:7): [True: 0, False: 0]
  |  Branch (620:65): [True: 0, False: 0]
  ------------------
  621|      0|			goto fin;
  622|      0|	p11->C_WrapKey(session, &mech, hWrappingKey, hkey, pWrappedKey, &pulWrappedKeyLen);
  623|       |
  624|      9|fin:
  625|      9|	p11->C_CloseSession(session);
  626|      9|	p11->C_Finalize(NULL);
  627|     16|end:
  628|     16|	free(pin);
  629|     16|}
fuzz_pkcs11.c:test_unwrap:
  740|     15|{
  741|     15|	CK_SESSION_HANDLE    session;
  742|     15|	CK_MECHANISM         mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|     15|#define NULL_PTR ((void *)0)
  ------------------
  743|     15|	uint8_t              login_type = CKU_USER;
  ------------------
  |  | 1211|     15|#define CKU_USER 1UL
  ------------------
  744|     15|	char                *pin = NULL;
  745|     15|	const unsigned char *opt_id, *wrapped_key;
  746|     15|	size_t               opt_id_len;
  747|     15|	CK_OBJECT_HANDLE     hUnwrappingKey;
  748|     15|	CK_ULONG             wrapped_key_length;
  749|     15|	CK_BYTE_PTR          pWrappedKey;
  750|     15|	unsigned char        in_buffer[1024];
  751|     15|	CK_OBJECT_CLASS      secret_key_class = CKO_SECRET_KEY;
  ------------------
  |  | 1031|     15|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  752|     15|	CK_ATTRIBUTE        *keyTemplate = NULL;
  753|     15|	int                  n_attr = 2;
  754|     15|	CK_OBJECT_HANDLE     hSecretKey;
  755|       |
  756|       |	/* Set options */
  757|     15|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (757:6): [True: 0, False: 15]
  |  Branch (757:44): [True: 1, False: 14]
  ------------------
  758|      1|		goto end;
  759|     14|	login_type = data[0];
  760|     14|	data++; size--;
  761|     14|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (761:6): [True: 1, False: 13]
  ------------------
  762|      1|		goto end;
  763|     13|	opt_id = data;
  764|     13|	opt_id_len = get_buffer(&opt_id, size, &data, &size, 256);
  765|     13|	wrapped_key = data;
  766|     13|	if ((wrapped_key_length = get_buffer(&wrapped_key, size, &data, &size, 1024)) == 0)
  ------------------
  |  Branch (766:6): [True: 3, False: 10]
  ------------------
  767|      3|		goto end;
  768|     10|	memcpy(in_buffer, wrapped_key, wrapped_key_length);
  769|     10|	pWrappedKey = in_buffer;
  770|       |
  771|     10|	if (fill_key_template((CK_ATTRIBUTE **) &keyTemplate, &n_attr, &data, &size, &secret_key_class, true))
  ------------------
  |  Branch (771:6): [True: 2, False: 8]
  ------------------
  772|      2|		goto end;
  773|       |
  774|       |	/* Initialize */
  775|      8|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|      8|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (775:6): [True: 2, False: 6]
  ------------------
  776|      2|		goto end;
  777|       |
  778|      6|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  779|       |	/* Find keys*/
  780|      6|	if (!fuzz_find_object(session, CKO_PRIVATE_KEY, &hUnwrappingKey, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1030|      6|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (780:6): [True: 3, False: 3]
  |  Branch (780:67): [True: 2, False: 4]
  ------------------
  781|      3|		if (!fuzz_find_object(session, CKO_SECRET_KEY, &hUnwrappingKey, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1031|      3|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  |  Branch (781:7): [True: 3, False: 0]
  |  Branch (781:67): [True: 2, False: 1]
  ------------------
  782|      3|			goto fin;
  783|      3|	p11->C_UnwrapKey(session, &mech, hUnwrappingKey, pWrappedKey, wrapped_key_length, keyTemplate, n_attr, &hSecretKey);
  784|       |
  785|      6|fin:
  786|      6|	p11->C_CloseSession(session);
  787|      6|	p11->C_Finalize(NULL);
  788|     15|end:
  789|     15|	free(pin);
  790|     15|	free(keyTemplate);
  791|     15|}
fuzz_pkcs11.c:test_derive:
  794|     41|{
  795|     41|	CK_SESSION_HANDLE    session;
  796|     41|	CK_OBJECT_HANDLE     key;
  797|     41|	CK_MECHANISM         mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|     41|#define NULL_PTR ((void *)0)
  ------------------
  798|     41|	uint8_t              login_type = CKU_USER;
  ------------------
  |  | 1211|     41|#define CKU_USER 1UL
  ------------------
  799|     41|	char                *pin = NULL;
  800|     41|	const unsigned char *opt_id = NULL;
  801|     41|	size_t               opt_id_len;
  802|     41|	CK_OBJECT_HANDLE     newkey = 0;
  803|     41|	CK_OBJECT_CLASS      newkey_class = CKO_SECRET_KEY;
  ------------------
  |  | 1031|     41|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
  804|     41|	CK_ATTRIBUTE        *keyTemplate = NULL;
  805|     41|	int                  n_attrs = 2;
  806|       |
  807|       |	/* Set options */
  808|     41|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (808:6): [True: 0, False: 41]
  |  Branch (808:44): [True: 1, False: 40]
  ------------------
  809|      1|		goto end;
  810|     40|	login_type = data[0];
  811|     40|	data++; size--;
  812|     40|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (812:6): [True: 1, False: 39]
  ------------------
  813|      1|		goto end;
  814|     39|	opt_id = data;
  815|     39|	opt_id_len = get_buffer(&opt_id, size, &data, &size, 256);
  816|     39|	if (fill_key_template((CK_ATTRIBUTE **) &keyTemplate, &n_attrs, &data, &size, &newkey_class, false))
  ------------------
  |  Branch (816:6): [True: 2, False: 37]
  ------------------
  817|      2|		goto end;
  818|       |
  819|       |	/* Initialize */
  820|     37|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|     37|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (820:6): [True: 13, False: 24]
  ------------------
  821|     13|		goto end;
  822|       |
  823|     24|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  824|     24|	if (fuzz_find_object(session, CKO_PRIVATE_KEY, &key, opt_id_len ? opt_id : NULL, opt_id_len))
  ------------------
  |  | 1030|     24|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (824:6): [True: 18, False: 6]
  |  Branch (824:55): [True: 3, False: 21]
  ------------------
  825|     18|		p11->C_DeriveKey(session, &mech, key, keyTemplate, n_attrs, &newkey);
  826|       |
  827|     24|	p11->C_CloseSession(session);
  828|     24|	p11->C_Finalize(NULL);
  829|     41|end:
  830|     41|	free(pin);
  831|     41|	free(keyTemplate);
  832|     41|}
fuzz_pkcs11.c:test_genkeypair:
  835|    350|{
  836|    350|	CK_SESSION_HANDLE session;
  837|    350|	CK_OBJECT_HANDLE  hPublicKey;
  838|    350|	CK_OBJECT_HANDLE  hPrivateKey;
  839|    350|	CK_MECHANISM      mech = {0, NULL_PTR, 0};
  ------------------
  |  |   27|    350|#define NULL_PTR ((void *)0)
  ------------------
  840|    350|	uint8_t           login_type = CKU_USER;
  ------------------
  |  | 1211|    350|#define CKU_USER 1UL
  ------------------
  841|    350|	char             *pin = NULL;
  842|    350|	CK_OBJECT_CLASS   pubkey_class = CKO_PUBLIC_KEY;
  ------------------
  |  | 1029|    350|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
  843|    350|	CK_OBJECT_CLASS   privkey_class = CKO_PRIVATE_KEY;
  ------------------
  |  | 1030|    350|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  844|    350|	int               n_pubkey_attr = 2;
  845|    350|	int               n_privkey_attr = 2;
  846|    350|	CK_ATTRIBUTE     *publicKeyTemplate = NULL;
  847|    350|	CK_ATTRIBUTE     *privateKeyTemplate = NULL;
  848|       |
  849|       |	/* Process options*/
  850|    350|	if (set_mechanism(&data, &size, &mech) || size < 3)
  ------------------
  |  Branch (850:6): [True: 0, False: 350]
  |  Branch (850:44): [True: 1, False: 349]
  ------------------
  851|      1|		goto end;
  852|    349|	login_type = data[0];
  853|    349|	data++; size--;
  854|    349|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (854:6): [True: 4, False: 345]
  ------------------
  855|      4|		goto end;
  856|       |
  857|    345|	if (fill_key_template(&publicKeyTemplate, &n_pubkey_attr, &data, &size, &pubkey_class, true) != 0
  ------------------
  |  Branch (857:6): [True: 1, False: 344]
  ------------------
  858|    344|		|| fill_key_template(&privateKeyTemplate, &n_privkey_attr, &data, &size, &privkey_class, true) != 0)
  ------------------
  |  Branch (858:6): [True: 8, False: 336]
  ------------------
  859|      9|		goto end;
  860|       |
  861|       |	/* Initialize */
  862|    336|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    336|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (862:6): [True: 50, False: 286]
  ------------------
  863|     50|		goto end;
  864|       |
  865|    286|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  866|    286|	p11->C_GenerateKeyPair(session, &mech, publicKeyTemplate, n_pubkey_attr,
  867|    286|						   privateKeyTemplate, n_privkey_attr,
  868|    286|						   &hPublicKey, &hPrivateKey);
  869|    286|	p11->C_CloseSession(session);
  870|    286|	p11->C_Finalize(NULL);
  871|       |
  872|    350|end:
  873|    350|	free(pin);
  874|    350|	free(privateKeyTemplate);
  875|    350|	free(publicKeyTemplate);
  876|    350|}
fuzz_pkcs11.c:test_store_data:
  879|     91|{
  880|     91|	CK_SESSION_HANDLE session;
  881|     91|	CK_OBJECT_HANDLE  data_obj;
  882|     91|	CK_OBJECT_CLASS   class = CKO_DATA;
  ------------------
  |  | 1027|     91|#define CKO_DATA 0x00000000UL
  ------------------
  883|     91|	uint8_t           login_type = CKU_USER;
  ------------------
  |  | 1211|     91|#define CKU_USER 1UL
  ------------------
  884|     91|	unsigned char     contents[5001];
  885|     91|	int               contents_len = 0;
  886|     91|	const uint8_t    *ptr = NULL;
  887|     91|	CK_ATTRIBUTE     *data_templ = NULL;
  888|     91|	int               n_data_attr = 0;
  889|     91|	char             *pin = NULL;
  890|     91|	unsigned char     app_id[256];
  891|     91|	int               app_id_len = 0;
  892|       |
  893|       |	/* Create data template */
  894|     91|	if (!(data_templ = malloc(20 * sizeof(CK_ATTRIBUTE))))
  ------------------
  |  Branch (894:6): [True: 0, False: 91]
  ------------------
  895|      0|		return;
  896|     91|	memset(data_templ, 0, 20 * sizeof(CK_ATTRIBUTE));
  897|       |
  898|       |	/* Get PIN */
  899|     91|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (899:6): [True: 1, False: 90]
  ------------------
  900|      1|		goto end;
  901|       |
  902|       |	/* Extract content from fuzzing input*/
  903|     90|	memset(contents, 0, sizeof(contents));
  904|     90|	ptr = data;
  905|     90|	if ((contents_len = get_buffer(&ptr, size, &data, &size, 5000)) == 0)	
  ------------------
  |  Branch (905:6): [True: 6, False: 84]
  ------------------
  906|      6|		goto end;
  907|     84|	memcpy(contents, ptr, contents_len);
  908|     84|	contents[contents_len] = '\0';
  909|       |
  910|       |	/* Fill attributes to data template */
  911|     84|	if (size < 4)
  ------------------
  |  Branch (911:6): [True: 4, False: 80]
  ------------------
  912|      4|		goto end;
  913|     80|	FILL_ATTR(data_templ[n_data_attr], CKA_CLASS, &class, sizeof(class));
  ------------------
  |  |  631|     80|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     80|	(attr).type=(typ); \
  |  |  633|     80|	(attr).pValue=(val); \
  |  |  634|     80|	(attr).ulValueLen=len; \
  |  |  635|     80|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 80]
  |  |  ------------------
  ------------------
  914|     80|	n_data_attr++;
  915|     80|	FILL_ATTR(data_templ[n_data_attr], CKA_VALUE, &contents, contents_len);
  ------------------
  |  |  631|     80|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     80|	(attr).type=(typ); \
  |  |  633|     80|	(attr).pValue=(val); \
  |  |  634|     80|	(attr).ulValueLen=len; \
  |  |  635|     80|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 80]
  |  |  ------------------
  ------------------
  916|     80|	n_data_attr++;
  917|     80|	fill_bool_attr(&data_templ, &n_data_attr, CKA_TOKEN, *data % 2);
  ------------------
  |  |  138|     80|#define CKA_TOKEN 0x00000001UL
  ------------------
  918|     80|	data++; size--;
  919|     80|	fill_bool_attr(&data_templ, &n_data_attr, CKA_PRIVATE, *data % 2);
  ------------------
  |  |  139|     80|#define CKA_PRIVATE 0x00000002UL
  ------------------
  920|     80|	data++; size--;
  921|       |
  922|       |	/* Get application id*/
  923|     80|	if (data[0] % 2){
  ------------------
  |  Branch (923:6): [True: 36, False: 44]
  ------------------
  924|     36|		data++; size--;
  925|     36|		ptr = data;
  926|     36|		if ((app_id_len = get_buffer(&ptr, size, &data, &size, 256)) == 0)
  ------------------
  |  Branch (926:7): [True: 6, False: 30]
  ------------------
  927|      6|			goto end;
  928|     30|		memcpy(app_id, ptr, app_id_len);
  929|     30|		FILL_ATTR(data_templ[n_data_attr], CKA_OBJECT_ID, app_id, app_id_len);
  ------------------
  |  |  631|     30|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     30|	(attr).type=(typ); \
  |  |  633|     30|	(attr).pValue=(val); \
  |  |  634|     30|	(attr).ulValueLen=len; \
  |  |  635|     30|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 30]
  |  |  ------------------
  ------------------
  930|     30|		n_data_attr++;
  931|     30|	}
  932|       |
  933|       |	/* Initialize */
  934|     74|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|     74|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (934:6): [True: 8, False: 66]
  ------------------
  935|      8|		goto end;
  936|       |
  937|     66|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  938|     66|	p11->C_CreateObject(session, data_templ, n_data_attr, &data_obj);
  939|     66|	p11->C_CloseSession(session);
  940|     66|	p11->C_Finalize(NULL);
  941|     91|end:
  942|     91|	free(data_templ);
  943|     91|	free(pin);
  944|     91|}
fuzz_pkcs11.c:test_store_cert:
  947|    158|{
  948|    158|	CK_SESSION_HANDLE   session;
  949|    158|	CK_OBJECT_CLASS     class = CKO_CERTIFICATE;
  ------------------
  |  | 1028|    158|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
  950|    158|	uint8_t             login_type = CKU_USER;
  ------------------
  |  | 1211|    158|#define CKU_USER 1UL
  ------------------
  951|    158|	unsigned char       contents[5000];
  952|    158|	int                 contents_len = 0;
  953|    158|	const uint8_t      *ptr = NULL;
  954|    158|	CK_ATTRIBUTE       *cert_templ = NULL;
  955|    158|	int                 n_cert_attr = 0;
  956|    158|	char               *pin = NULL;
  957|    158|	CK_OBJECT_HANDLE    cert_obj;
  958|    158|	CK_CERTIFICATE_TYPE cert_type = CKC_X_509;
  ------------------
  |  |  303|    158|#define CKC_X_509 0x00000000UL
  ------------------
  959|       |
  960|       |	/* Create certificate template */
  961|    158|	if (!(cert_templ = malloc(20 * sizeof(CK_ATTRIBUTE))))
  ------------------
  |  Branch (961:6): [True: 0, False: 158]
  ------------------
  962|      0|		return;
  963|    158|	memset(cert_templ, 0, 20 * sizeof(CK_ATTRIBUTE));
  964|       |
  965|       |	/* Get PIN */
  966|    158|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (966:6): [True: 1, False: 157]
  ------------------
  967|      1|		goto end;
  968|       |
  969|       |	/* Extract content from fuzzing input */
  970|    157|	memset(contents, 0, sizeof(contents));
  971|    157|	ptr = data;
  972|    157|	if ((contents_len = get_buffer(&ptr, size, &data, &size, 5000)) == 0)	
  ------------------
  |  Branch (972:6): [True: 6, False: 151]
  ------------------
  973|      6|		goto end;
  974|    151|	memcpy(contents, ptr, contents_len);
  975|    151|	contents[contents_len] = '\0';
  976|       |
  977|       |	/* Fill attributes to certificate template */
  978|    151|	if (size < 4)
  ------------------
  |  Branch (978:6): [True: 2, False: 149]
  ------------------
  979|      2|		goto end;
  980|    149|	FILL_ATTR(cert_templ[n_cert_attr], CKA_CLASS, &class, sizeof(class));
  ------------------
  |  |  631|    149|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|    149|	(attr).type=(typ); \
  |  |  633|    149|	(attr).pValue=(val); \
  |  |  634|    149|	(attr).ulValueLen=len; \
  |  |  635|    149|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 149]
  |  |  ------------------
  ------------------
  981|    149|	n_cert_attr++;
  982|    149|	FILL_ATTR(cert_templ[n_cert_attr], CKA_VALUE, contents, contents_len);
  ------------------
  |  |  631|    149|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|    149|	(attr).type=(typ); \
  |  |  633|    149|	(attr).pValue=(val); \
  |  |  634|    149|	(attr).ulValueLen=len; \
  |  |  635|    149|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 149]
  |  |  ------------------
  ------------------
  983|    149|	n_cert_attr++;
  984|    149|	FILL_ATTR(cert_templ[n_cert_attr], CKA_CERTIFICATE_TYPE, &cert_type, sizeof(cert_type));
  ------------------
  |  |  631|    149|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|    149|	(attr).type=(typ); \
  |  |  633|    149|	(attr).pValue=(val); \
  |  |  634|    149|	(attr).ulValueLen=len; \
  |  |  635|    149|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 149]
  |  |  ------------------
  ------------------
  985|    149|	n_cert_attr++;
  986|    149|	fill_bool_attr(&cert_templ, &n_cert_attr, CKA_TOKEN, *data % 2);
  ------------------
  |  |  138|    149|#define CKA_TOKEN 0x00000001UL
  ------------------
  987|    149|	data++; size--;
  988|    149|	fill_bool_attr(&cert_templ, &n_cert_attr, CKA_PRIVATE, *data % 2);
  ------------------
  |  |  139|    149|#define CKA_PRIVATE 0x00000002UL
  ------------------
  989|    149|	data++; size--;
  990|       |
  991|       |	/* Initialize */
  992|    149|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    149|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (992:6): [True: 67, False: 82]
  ------------------
  993|     67|		goto end;
  994|       |
  995|     82|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
  996|     82|	p11->C_CreateObject(session, cert_templ, n_cert_attr, &cert_obj);
  997|     82|	p11->C_CloseSession(session);
  998|     82|	p11->C_Finalize(NULL);
  999|    158|end:
 1000|    158|	free(pin);
 1001|    158|	free(cert_templ);
 1002|    158|}
fuzz_pkcs11.c:test_store_key:
 1005|    253|{
 1006|    253|	CK_SESSION_HANDLE session;
 1007|    253|	CK_OBJECT_CLASS   class = CKO_SECRET_KEY;
  ------------------
  |  | 1031|    253|#define CKO_SECRET_KEY 0x00000004UL
  ------------------
 1008|    253|	uint8_t           login_type = CKU_USER;
  ------------------
  |  | 1211|    253|#define CKU_USER 1UL
  ------------------
 1009|    253|	unsigned char     contents[5000];
 1010|    253|	int               contents_len = 0;
 1011|    253|	const uint8_t    *ptr = NULL;
 1012|    253|	CK_ATTRIBUTE     *key_template = NULL;
 1013|    253|	int               n_key_attr = 0;
 1014|    253|	char             *pin = NULL;
 1015|    253|	CK_OBJECT_HANDLE  key_obj;
 1016|       |
 1017|    253|	memset(contents, 0, sizeof(contents));
 1018|    253|	if (size < 3)
  ------------------
  |  Branch (1018:6): [True: 0, False: 253]
  ------------------
 1019|      0|		return;
 1020|    253|	class = *data;
 1021|    253|	data++; size--;
 1022|       |
 1023|       |	/* Get PIN */
 1024|    253|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (1024:6): [True: 2, False: 251]
  ------------------
 1025|      2|		goto end;
 1026|       |
 1027|    251|	if (fill_key_template(&key_template, &n_key_attr, &data, &size, &class, true) != 0)
  ------------------
  |  Branch (1027:6): [True: 31, False: 220]
  ------------------
 1028|     31|		goto end;
 1029|       |
 1030|    220|	if (size < 3)
  ------------------
  |  Branch (1030:6): [True: 10, False: 210]
  ------------------
 1031|     10|		goto end;
 1032|    210|	if (data[0] && n_key_attr < 20) {
  ------------------
  |  Branch (1032:6): [True: 50, False: 160]
  |  Branch (1032:17): [True: 46, False: 4]
  ------------------
 1033|     46|		data++; size--;
 1034|     46|		ptr = data;
 1035|     46|		if ((contents_len = get_buffer(&ptr, size, &data, &size, 5000)) == 0)	
  ------------------
  |  Branch (1035:7): [True: 18, False: 28]
  ------------------
 1036|     18|			goto end;
 1037|     28|		memcpy(contents, ptr, contents_len);
 1038|     28|		FILL_ATTR(key_template[n_key_attr], CKA_VALUE, contents, contents_len);
  ------------------
  |  |  631|     28|#define FILL_ATTR(attr, typ, val, len) do { \
  |  |  632|     28|	(attr).type=(typ); \
  |  |  633|     28|	(attr).pValue=(val); \
  |  |  634|     28|	(attr).ulValueLen=len; \
  |  |  635|     28|} while(0)
  |  |  ------------------
  |  |  |  Branch (635:9): [Folded, False: 28]
  |  |  ------------------
  ------------------
 1039|     28|		n_key_attr++;
 1040|     28|	}
 1041|       |
 1042|       |	/* Initialize */
 1043|    192|	if (fuzz_pkcs11_initialize(data, size, NULL, &session) != CKR_OK)
  ------------------
  |  | 1086|    192|#define CKR_OK 0x00000000UL
  ------------------
  |  Branch (1043:6): [True: 30, False: 162]
  ------------------
 1044|     30|		goto end;
 1045|       |
 1046|    162|	p11->C_Login(session, login_type, (CK_UTF8CHAR *) pin, strlen(pin));
 1047|    162|	p11->C_CreateObject(session, key_template, n_key_attr, &key_obj);
 1048|    162|	p11->C_CloseSession(session);
 1049|    162|	p11->C_Finalize(NULL);
 1050|    253|end:
 1051|    253|	free(pin);
 1052|    253|	free(key_template);
 1053|    253|}

fuzz_get_chunk:
   36|   564k|{
   37|   564k|    struct driver_data *data;
   38|   564k|    uint16_t c_size;
   39|   564k|    const uint8_t *c;
   40|       |
   41|   564k|    if (chunk)
  ------------------
  |  Branch (41:9): [True: 564k, False: 0]
  ------------------
   42|   564k|        *chunk = NULL;
   43|   564k|    if (chunk_size)
  ------------------
  |  Branch (43:9): [True: 564k, False: 0]
  ------------------
   44|   564k|        *chunk_size = 0;
   45|       |
   46|   564k|    if (!chunk || !chunk_size || !reader) {
  ------------------
  |  Branch (46:9): [True: 0, False: 564k]
  |  Branch (46:19): [True: 0, False: 564k]
  |  Branch (46:34): [True: 0, False: 564k]
  ------------------
   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|   564k|    data = reader->drv_data;
   52|   564k|    if (!data || !data->Data || data->Size < sizeof c_size) {
  ------------------
  |  Branch (52:9): [True: 0, False: 564k]
  |  Branch (52:18): [True: 0, False: 564k]
  |  Branch (52:33): [True: 156k, False: 408k]
  ------------------
   53|   156k|        sc_debug(reader->ctx, SC_LOG_DEBUG_VERBOSE_TOOL, "Invalid Arguments");
  ------------------
  |  |   70|   156k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   54|   156k|        return;
   55|   156k|    }
   56|       |    /* parse the length of the returned data on two bytes */
   57|   408k|    c_size = *((uint16_t *) data->Data);
   58|       |    /* consume two bytes from the fuzzing data */
   59|   408k|    data->Size -= sizeof c_size;
   60|   408k|    data->Data += sizeof c_size;
   61|       |
   62|   408k|    if (data->Size < c_size) {
  ------------------
  |  Branch (62:9): [True: 12.6k, False: 396k]
  ------------------
   63|  12.6k|        c_size = data->Size;
   64|  12.6k|    }
   65|       |
   66|       |    /* consume the bytes from the fuzzing data */
   67|   408k|    c = data->Data;
   68|   408k|    data->Size -= c_size;
   69|   408k|    data->Data += c_size;
   70|       |
   71|   408k|    sc_debug_hex(reader->ctx, SC_LOG_DEBUG_VERBOSE_TOOL,
  ------------------
  |  |  127|   408k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   72|   408k|        "Returning fuzzing chunk", c, c_size);
   73|       |
   74|   408k|    *chunk = c;
   75|   408k|    *chunk_size = c_size;
   76|   408k|}
sc_get_fuzz_driver:
  150|  15.7k|{
  151|  15.7k|    fuzz_ops.release = fuzz_reader_release;
  152|  15.7k|    fuzz_ops.connect = fuzz_reader_connect;
  153|  15.7k|    fuzz_ops.disconnect = fuzz_reader_disconnect;
  154|  15.7k|    fuzz_ops.transmit = fuzz_reader_transmit;
  155|  15.7k|    fuzz_ops.lock = fuzz_reader_lock;
  156|  15.7k|    fuzz_ops.unlock = fuzz_reader_unlock;
  157|  15.7k|    return &fuzz_drv;
  158|  15.7k|}
fuzz_add_reader:
  161|  15.7k|{
  162|  15.7k|    sc_reader_t	*reader;
  163|  15.7k|    struct driver_data *data;
  164|  15.7k|    char name[64] = {0};
  165|       |
  166|  15.7k|    if (!(reader = calloc(1, sizeof(*reader)))
  ------------------
  |  Branch (166:9): [True: 0, False: 15.7k]
  ------------------
  167|  15.7k|            || !(data = (calloc(1, sizeof(*data))))) {
  ------------------
  |  Branch (167:16): [True: 0, False: 15.7k]
  ------------------
  168|      0|        free(reader);
  169|      0|        return;
  170|      0|    }
  171|       |
  172|  15.7k|    data->Data = Data;
  173|  15.7k|    data->Size = Size;
  174|       |
  175|  15.7k|    reader->driver = &fuzz_drv;
  176|  15.7k|    reader->ops = &fuzz_ops;
  177|  15.7k|    reader->drv_data = data;
  178|  15.7k|    snprintf(name, sizeof name - 1, "%zu random byte%s reader (%p)",
  179|  15.7k|            Size, Size == 1 ? "" : "s", Data);
  ------------------
  |  Branch (179:19): [True: 23, False: 15.7k]
  ------------------
  180|  15.7k|    reader->name = strdup(name);
  181|       |
  182|  15.7k|    reader->ctx = ctx;
  183|  15.7k|    list_append(&ctx->readers, reader);
  184|  15.7k|}
fuzzer_reader.c:fuzz_reader_release:
   79|  15.7k|{
   80|  15.7k|    if (reader) {
  ------------------
  |  Branch (80:9): [True: 15.7k, False: 0]
  ------------------
   81|  15.7k|        free(reader->drv_data);
   82|  15.7k|        reader->drv_data = NULL;
   83|  15.7k|    }
   84|       |
   85|  15.7k|    return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
   86|  15.7k|}
fuzzer_reader.c:fuzz_reader_connect:
   89|  15.7k|{
   90|  15.7k|    uint16_t chunk_size;
   91|  15.7k|    const uint8_t *chunk;
   92|       |
   93|  15.7k|    fuzz_get_chunk(reader, &chunk, &chunk_size);
   94|       |
   95|  15.7k|    if (chunk_size > SC_MAX_ATR_SIZE)
  ------------------
  |  |   41|  15.7k|#define SC_MAX_ATR_SIZE			33
  ------------------
  |  Branch (95:9): [True: 66, False: 15.7k]
  ------------------
   96|     66|        chunk_size = SC_MAX_ATR_SIZE;
  ------------------
  |  |   41|     66|#define SC_MAX_ATR_SIZE			33
  ------------------
   97|  15.7k|    else
   98|  15.7k|        reader->atr.len = chunk_size;
   99|       |
  100|  15.7k|    if (chunk_size > 0)
  ------------------
  |  Branch (100:9): [True: 11.4k, False: 4.31k]
  ------------------
  101|  11.4k|        memcpy(reader->atr.value, chunk, chunk_size);
  102|       |
  103|  15.7k|    return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  104|  15.7k|}
fuzzer_reader.c:fuzz_reader_disconnect:
  107|  15.7k|{
  108|  15.7k|    return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
  109|  15.7k|}
fuzzer_reader.c:fuzz_reader_transmit:
  112|   549k|{
  113|   549k|    const uint8_t *chunk;
  114|   549k|    uint16_t chunk_size;
  115|       |
  116|   549k|    fuzz_get_chunk(reader, &chunk, &chunk_size);
  117|       |
  118|   549k|    if (chunk_size >= 2) {
  ------------------
  |  Branch (118:9): [True: 314k, False: 234k]
  ------------------
  119|       |        /* set the SW1 and SW2 status bytes (the last two bytes of
  120|       |         * the response */
  121|   314k|        apdu->sw1 = (unsigned int)chunk[chunk_size - 2];
  122|   314k|        apdu->sw2 = (unsigned int)chunk[chunk_size - 1];
  123|   314k|        chunk_size -= 2;
  124|       |        /* set output length and copy the returned data if necessary */
  125|   314k|        if (chunk_size <= apdu->resplen)
  ------------------
  |  Branch (125:13): [True: 268k, False: 45.8k]
  ------------------
  126|   268k|            apdu->resplen = chunk_size;
  127|       |
  128|   314k|        if (apdu->resplen != 0)
  ------------------
  |  Branch (128:13): [True: 229k, False: 84.9k]
  ------------------
  129|   229k|            memcpy(apdu->resp, chunk, apdu->resplen);
  130|   314k|    } else {
  131|   234k|        apdu->sw1 = 0x6D;
  132|   234k|        apdu->sw2 = 0x00;
  133|   234k|        apdu->resplen = 0;
  134|   234k|    }
  135|       |
  136|   549k|    return SC_SUCCESS;
  ------------------
  |  |   28|   549k|#define SC_SUCCESS				0
  ------------------
  137|   549k|}
fuzzer_reader.c:fuzz_reader_lock:
  140|   281k|{
  141|   281k|    return 0;
  142|   281k|}
fuzzer_reader.c:fuzz_reader_unlock:
  145|   281k|{
  146|   281k|    return 0;
  147|   281k|}

get_word:
   26|  5.76k|{
   27|       |	/* Words are separated by one zero byte,
   28|       |	   return pointer to the next word if there is one */
   29|  5.76k|	const uint8_t *ptr = data;
   30|  5.76k|	if (!data || size == 0 || *data == 0)
  ------------------
  |  Branch (30:6): [True: 0, False: 5.76k]
  |  Branch (30:15): [True: 0, False: 5.76k]
  |  Branch (30:28): [True: 16, False: 5.75k]
  ------------------
   31|     16|		return NULL;
   32|       |	
   33|  5.75k|	ptr = memchr(data, 0, size - 1);
   34|  5.75k|	return ptr ? ++ptr : NULL;
  ------------------
  |  Branch (34:9): [True: 5.73k, False: 13]
  ------------------
   35|  5.76k|}
extract_word:
   38|  5.76k|{
   39|       |	/* Find word and return its copy (needs to be freed) */
   40|  5.76k|	char *result = NULL;
   41|  5.76k|	const uint8_t *ptr = NULL;
   42|       |
   43|  5.76k|	if (*size < 2)
  ------------------
  |  Branch (43:6): [True: 1, False: 5.76k]
  ------------------
   44|      1|		return NULL;
   45|       |
   46|  5.76k|	ptr = get_word(*data, *size);
   47|  5.76k|	if (!ptr)
  ------------------
  |  Branch (47:6): [True: 29, False: 5.73k]
  ------------------
   48|     29|		return NULL;
   49|  5.73k|	result = strdup((const char *)*data);
   50|  5.73k|	*size -=(ptr - *data);
   51|  5.73k|	*data = ptr;
   52|       |
   53|  5.73k|	return result;
   54|  5.76k|}
get_buffer:
   98|  3.66k|{
   99|       |	/* Split buf into two parts according to length stored in first two bytes */
  100|  3.66k|	uint16_t len = 0;
  101|       |
  102|  3.66k|	if (!buf || !(*buf) || buf_len < sizeof(uint16_t))
  ------------------
  |  Branch (102:6): [True: 0, False: 3.66k]
  |  Branch (102:14): [True: 0, False: 3.66k]
  |  Branch (102:25): [True: 22, False: 3.64k]
  ------------------
  103|     22|		return 0;
  104|       |
  105|       |	/* Get length of the result buffer*/
  106|  3.64k|	len = *((uint16_t *) *buf) % max_size;
  107|  3.64k|	(*buf) += 2;
  108|  3.64k|	buf_len -= 2;
  109|  3.64k|	if (buf_len <= len) {
  ------------------
  |  Branch (109:6): [True: 74, False: 3.57k]
  ------------------
  110|     74|		*out = *buf;
  111|     74|		*out_len = buf_len;
  112|     74|		return 0;
  113|     74|	}
  114|       |
  115|       |	/* Set out buffer to new reader data*/
  116|  3.57k|	*out = *buf + len;
  117|  3.57k|	*out_len = buf_len - len;
  118|  3.57k|	return len;
  119|  3.64k|}

sc_notify_init:
  524|      2|void sc_notify_init(void) {}
sc_notify_close:
  525|  15.7k|void sc_notify_close(void) {}
sc_notify:
  526|      2|void sc_notify(const char *title, const char *text) {}
sc_notify_id:
  528|    520|		struct sc_pkcs15_card *p15card, enum ui_str id) {}

