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

EAC_init:
   71|    136|{
   72|       |    OpenSSL_add_all_algorithms();
   73|    136|    EAC_add_all_objects();
   74|    136|    EAC_set_x509_default_dir(X509DIR);
   75|    136|    EAC_set_cvc_default_dir(CVCDIR);
   76|    136|}

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

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

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

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

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

sc_asn1_read_tag:
   64|   278k|{
   65|   278k|	const u8 *p = *buf;
   66|   278k|	size_t left = buflen, len;
   67|   278k|	unsigned int cla, tag, i;
   68|       |
   69|   278k|	*buf = NULL;
   70|       |
   71|   278k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (71:6): [True: 16.7k, False: 261k]
  |  Branch (71:19): [True: 0, False: 261k]
  |  Branch (71:25): [True: 0, False: 261k]
  ------------------
   72|  16.7k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  16.7k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   73|   261k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (73:6): [True: 3.21k, False: 258k]
  |  Branch (73:20): [True: 8.37k, False: 250k]
  ------------------
   74|       |		/* end of data reached */
   75|  11.5k|		*taglen = 0;
   76|  11.5k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  194|  11.5k|#define SC_ASN1_TAG_EOC			0
  ------------------
   77|  11.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
   78|  11.5k|	}
   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|   250k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  184|   250k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  190|   250k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   85|   250k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  191|   250k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   86|   250k|	if (left < 1)
  ------------------
  |  Branch (86:6): [True: 0, False: 250k]
  ------------------
   87|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   88|   250k|	p++;
   89|   250k|	left--;
   90|   250k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  191|   250k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (90:6): [True: 2.48k, False: 247k]
  ------------------
   91|       |		/* high tag number */
   92|  2.48k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  145|  2.48k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   93|       |		/* search the last tag octet */
   94|  3.81k|		do {
   95|  3.81k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (95:8): [True: 148, False: 3.67k]
  |  Branch (95:21): [True: 198, False: 3.47k]
  ------------------
   96|       |				/* either an invalid tag or it doesn't fit in
   97|       |				 * unsigned int */
   98|    346|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    346|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   99|  3.47k|			tag <<= 8;
  100|  3.47k|			tag |= *p;
  101|  3.47k|			p++;
  102|  3.47k|			left--;
  103|  3.47k|			n--;
  104|  3.47k|		} while (tag & 0x80);
  ------------------
  |  Branch (104:12): [True: 1.33k, False: 2.13k]
  ------------------
  105|  2.48k|	}
  106|       |
  107|       |	/* parse length byte(s) */
  108|   249k|	if (left == 0)
  ------------------
  |  Branch (108:6): [True: 1.58k, False: 248k]
  ------------------
  109|  1.58k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.58k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  110|   248k|	len = *p;
  111|   248k|	p++;
  112|   248k|	left--;
  113|   248k|	if (len & 0x80) {
  ------------------
  |  Branch (113:6): [True: 30.5k, False: 217k]
  ------------------
  114|  30.5k|		len &= 0x7f;
  115|  30.5k|		unsigned int a = 0;
  116|  30.5k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (116:7): [True: 7.10k, False: 23.4k]
  |  Branch (116:25): [True: 665, False: 22.7k]
  ------------------
  117|  7.77k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  7.77k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  118|  34.9k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (118:15): [True: 12.1k, False: 22.7k]
  ------------------
  119|  12.1k|			a <<= 8;
  120|  12.1k|			a |= *p;
  121|  12.1k|			p++;
  122|  12.1k|			left--;
  123|  12.1k|		}
  124|  22.7k|		len = a;
  125|  22.7k|	}
  126|       |
  127|   240k|	*cla_out = cla;
  128|   240k|	*tag_out = tag;
  129|   240k|	*taglen = len;
  130|   240k|	*buf = p;
  131|       |
  132|   240k|	if (len > left)
  ------------------
  |  Branch (132:6): [True: 16.5k, False: 223k]
  ------------------
  133|  16.5k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  16.5k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  134|       |
  135|   223k|	return SC_SUCCESS;
  ------------------
  |  |   28|   223k|#define SC_SUCCESS				0
  ------------------
  136|   240k|}
sc_format_asn1_entry:
  140|   613k|{
  141|   613k|	entry->parm = parm;
  142|   613k|	entry->arg  = arg;
  143|   613k|	if (set_present)
  ------------------
  |  Branch (143:6): [True: 308k, False: 305k]
  ------------------
  144|   308k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|   308k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  145|   613k|}
sc_copy_asn1_entry:
  149|   279k|{
  150|  1.14M|	while (src->name != NULL) {
  ------------------
  |  Branch (150:9): [True: 867k, False: 279k]
  ------------------
  151|   867k|		*dest = *src;
  152|   867k|		dest++;
  153|   867k|		src++;
  154|   867k|	}
  155|       |	dest->name = NULL;
  156|   279k|}
sc_asn1_find_tag:
  486|  44.8k|{
  487|  44.8k|	size_t left = buflen, taglen;
  488|  44.8k|	const u8 *p = buf;
  489|       |
  490|  44.8k|	*taglen_in = 0;
  491|   103k|	while (left >= 2) {
  ------------------
  |  Branch (491:9): [True: 92.8k, False: 10.8k]
  ------------------
  492|  92.8k|		unsigned int cla = 0, tag, mask = 0xff00;
  493|       |
  494|  92.8k|		buf = p;
  495|       |		/* read a tag */
  496|  92.8k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   185k|#define SC_SUCCESS				0
  ------------------
  |  Branch (496:7): [True: 9.01k, False: 83.8k]
  ------------------
  497|  83.8k|				|| p == NULL)
  ------------------
  |  Branch (497:8): [True: 6.25k, False: 77.5k]
  ------------------
  498|  15.2k|			return NULL;
  499|       |
  500|  77.5k|		left -= (p - buf);
  501|       |		/* we need to shift the class byte to the leftmost
  502|       |		 * byte of the tag */
  503|  79.2k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (503:10): [True: 1.63k, False: 77.5k]
  ------------------
  504|  1.63k|			cla  <<= 8;
  505|  1.63k|			mask <<= 8;
  506|  1.63k|		}
  507|       |		/* compare the read tag with the given tag */
  508|  77.5k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (508:7): [True: 18.6k, False: 58.9k]
  ------------------
  509|       |			/* we have a match => return length and value part */
  510|  18.6k|			if (taglen > left)
  ------------------
  |  Branch (510:8): [True: 0, False: 18.6k]
  ------------------
  511|      0|				return NULL;
  512|  18.6k|			*taglen_in = taglen;
  513|  18.6k|			return p;
  514|  18.6k|		}
  515|       |		/* otherwise continue reading tags */
  516|  58.9k|		left -= taglen;
  517|  58.9k|		p += taglen;
  518|  58.9k|	}
  519|  10.8k|	return NULL;
  520|  44.8k|}
sc_asn1_skip_tag:
  524|   119k|{
  525|   119k|	const u8 *p = *buf;
  526|   119k|	size_t len = *buflen, taglen;
  527|   119k|	unsigned int cla = 0, tag;
  528|       |
  529|   119k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   239k|#define SC_SUCCESS				0
  ------------------
  |  Branch (529:6): [True: 28.8k, False: 91.0k]
  ------------------
  530|  91.0k|			|| p == NULL)
  ------------------
  |  Branch (530:7): [True: 2.69k, False: 88.3k]
  ------------------
  531|  31.5k|		return NULL;
  532|  88.3k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (532:10): [True: 88.3k, False: 0]
  ------------------
  533|  36.3k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  185|  36.3k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (533:2): [True: 36.3k, False: 51.9k]
  ------------------
  534|  36.3k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  136|  36.3k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  137|  36.3k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (534:7): [True: 5.57k, False: 30.7k]
  ------------------
  535|  5.57k|			return NULL;
  536|  30.7k|		break;
  537|  30.7k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  186|  10.0k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (537:2): [True: 10.0k, False: 78.2k]
  ------------------
  538|  10.0k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  136|  10.0k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  138|  10.0k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (538:7): [True: 1.62k, False: 8.41k]
  ------------------
  539|  1.62k|			return NULL;
  540|  8.41k|		break;
  541|  41.0k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  187|  41.0k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (541:2): [True: 41.0k, False: 47.3k]
  ------------------
  542|  41.0k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  136|  41.0k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  139|  41.0k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (542:7): [True: 1.71k, False: 39.2k]
  ------------------
  543|  1.71k|			return NULL;
  544|  39.2k|		break;
  545|  39.2k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  188|    926|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (545:2): [True: 926, False: 87.3k]
  ------------------
  546|    926|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  136|    926|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  140|    926|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (546:7): [True: 926, False: 0]
  ------------------
  547|    926|			return NULL;
  548|      0|		break;
  549|  88.3k|	}
  550|  78.4k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  190|  78.4k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (550:6): [True: 54.2k, False: 24.2k]
  ------------------
  551|  54.2k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  141|  54.2k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (551:7): [True: 3.18k, False: 51.0k]
  ------------------
  552|  3.18k|			return NULL;
  553|  54.2k|	} else
  554|  24.2k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  141|  24.2k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (554:7): [True: 1.17k, False: 23.0k]
  ------------------
  555|  1.17k|			return NULL;
  556|  74.1k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  144|  74.1k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (556:6): [True: 35.8k, False: 38.3k]
  ------------------
  557|  35.8k|		return NULL;
  558|  38.3k|	len -= (p - *buf);	/* header size */
  559|  38.3k|	if (taglen > len) {
  ------------------
  |  Branch (559:6): [True: 0, False: 38.3k]
  ------------------
  560|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  561|      0|			 "too long ASN.1 object (size %"SC_FORMAT_LEN_SIZE_T"u while only %"SC_FORMAT_LEN_SIZE_T"u available)\n",
  562|      0|			 taglen, len);
  563|      0|		return NULL;
  564|      0|	}
  565|  38.3k|	*buflen -= (p - *buf) + taglen;
  566|  38.3k|	*buf = p + taglen;	/* point to next tag */
  567|  38.3k|	*taglen_out = taglen;
  568|  38.3k|	return p;
  569|  38.3k|}
sc_asn1_verify_tag:
  573|  1.18k|{
  574|  1.18k|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  575|  1.18k|}
sc_asn1_decode_integer:
  734|  1.98k|{
  735|  1.98k|	int    a = 0, is_negative = 0;
  736|  1.98k|	size_t i = 0;
  737|       |
  738|  1.98k|	if (inlen == 0) {
  ------------------
  |  Branch (738:6): [True: 8, False: 1.97k]
  ------------------
  739|      8|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      8|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  740|      8|	}
  741|  1.97k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (741:6): [True: 17, False: 1.95k]
  ------------------
  742|     17|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     17|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  743|     17|	}
  744|  1.95k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (744:6): [True: 396, False: 1.56k]
  ------------------
  745|    396|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (745:7): [True: 0, False: 396]
  |  Branch (745:17): [True: 0, False: 0]
  |  Branch (745:30): [True: 0, False: 0]
  |  Branch (745:50): [True: 0, False: 0]
  ------------------
  746|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  747|      0|		}
  748|    396|		is_negative = 1;
  749|    396|		a |= 0xff^(*inbuf++);
  750|    396|		i = 1;
  751|  1.56k|	} else {
  752|  1.56k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (752:7): [True: 0, False: 1.56k]
  |  Branch (752:17): [True: 0, False: 0]
  |  Branch (752:30): [True: 0, False: 0]
  |  Branch (752:50): [True: 0, False: 0]
  ------------------
  753|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  754|      0|		}
  755|  1.56k|	}
  756|  4.05k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (756:9): [True: 2.09k, False: 1.95k]
  ------------------
  757|  2.09k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (757:7): [True: 0, False: 2.09k]
  |  Branch (757:29): [True: 0, False: 2.09k]
  ------------------
  758|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  759|      0|		}
  760|  2.09k|		a <<= 8;
  761|  2.09k|		if (is_negative) {
  ------------------
  |  Branch (761:7): [True: 195, False: 1.89k]
  ------------------
  762|    195|			a |= 0xff^(*inbuf++);
  763|  1.89k|		} else {
  764|  1.89k|			a |= *inbuf++;
  765|  1.89k|		}
  766|  2.09k|	}
  767|  1.95k|	if (is_negative) {
  ------------------
  |  Branch (767:6): [True: 396, False: 1.56k]
  ------------------
  768|       |		/* Calculate Two's complement from previously positive number */
  769|    396|		a = (-1 * a) - 1;
  770|    396|	}
  771|  1.95k|	*out = a;
  772|  1.95k|	return 0;
  773|  1.95k|}
sc_asn1_decode_object_id:
  834|  7.35k|{
  835|  7.35k|	int large_second_octet = 0;
  836|  7.35k|	unsigned int a = 0;
  837|  7.35k|	const u8 *p = inbuf;
  838|  7.35k|	int *octet;
  839|       |
  840|  7.35k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (840:6): [True: 395, False: 6.95k]
  |  Branch (840:20): [True: 10, False: 6.94k]
  |  Branch (840:37): [True: 0, False: 6.94k]
  ------------------
  841|    405|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    405|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  842|       |
  843|  6.94k|	sc_init_oid(id);
  844|  6.94k|	octet = id->value;
  845|       |
  846|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  847|  6.94k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   70|  6.94k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 4.82k, False: 2.12k]
  |  |  ------------------
  ------------------
  848|  6.94k|	*octet++ = a;
  849|       |
  850|       |	/* The second octet fits here if the previous was 0 or 1 and second one is smaller than 40.
  851|       |	 * for the value 2 we can go up to 47. Otherwise the first bit needs to be set
  852|       |	 * and we continue reading further */
  853|  6.94k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (853:6): [True: 5.13k, False: 1.80k]
  ------------------
  854|  5.13k|		*octet++ = *p - (a * 40);
  855|  5.13k|		inlen--;
  856|  5.13k|	} else {
  857|  1.80k|		large_second_octet = 1;
  858|  1.80k|	}
  859|       |
  860|  24.3k|	while (inlen) {
  ------------------
  |  Branch (860:9): [True: 19.3k, False: 4.99k]
  ------------------
  861|  19.3k|		if (!large_second_octet)
  ------------------
  |  Branch (861:7): [True: 17.5k, False: 1.80k]
  ------------------
  862|  17.5k|			p++;
  863|       |		/* This signalizes empty most significant bits, which means
  864|       |		 * the unsigned integer encoding is not minimal */
  865|  19.3k|		if (*p == 0x80) {
  ------------------
  |  Branch (865:7): [True: 385, False: 18.9k]
  ------------------
  866|    385|			sc_init_oid(id);
  867|    385|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    385|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  868|    385|		}
  869|       |		/* Use unsigned type here so we can process the whole INT range.
  870|       |		 * Values can not be negative */
  871|  18.9k|		a = *p & 0x7F;
  872|  18.9k|		inlen--;
  873|  25.2k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (873:10): [True: 19.3k, False: 5.95k]
  |  Branch (873:19): [True: 6.59k, False: 12.7k]
  ------------------
  874|       |			/* Limit the OID values to int size and do not overflow */
  875|  6.59k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (875:8): [True: 277, False: 6.31k]
  ------------------
  876|    277|				sc_init_oid(id);
  877|    277|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    277|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  878|    277|			}
  879|  6.31k|			p++;
  880|  6.31k|			a <<= 7;
  881|  6.31k|			a |= *p & 0x7F;
  882|  6.31k|			inlen--;
  883|  6.31k|		}
  884|  18.7k|		if (*p & 0x80) {
  ------------------
  |  Branch (884:7): [True: 1.01k, False: 17.6k]
  ------------------
  885|       |			/* We dropped out from previous cycle on the end of
  886|       |			 * data while still expecting continuation of value */
  887|  1.01k|			sc_init_oid(id);
  888|  1.01k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.01k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  889|  1.01k|		}
  890|  17.6k|		if (large_second_octet) {
  ------------------
  |  Branch (890:7): [True: 1.15k, False: 16.5k]
  ------------------
  891|  1.15k|			a -= (2 * 40);
  892|  1.15k|		}
  893|  17.6k|		if (a > INT_MAX) {
  ------------------
  |  Branch (893:7): [True: 67, False: 17.6k]
  ------------------
  894|     67|			sc_init_oid(id);
  895|     67|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     67|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  896|     67|		}
  897|  17.6k|		*octet++ = a;
  898|  17.6k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  17.6k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (898:7): [True: 215, False: 17.4k]
  ------------------
  899|    215|			sc_init_oid(id);
  900|    215|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    215|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  901|    215|		}
  902|  17.4k|		large_second_octet = 0;
  903|  17.4k|	}
  904|       |
  905|  4.99k|	return 0;
  906|  6.94k|}
sc_asn1_encode_object_id:
  910|  15.8k|{
  911|  15.8k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  912|  15.8k|	int	i;
  913|       |
  914|  15.8k|	if (!buflen || !id)
  ------------------
  |  Branch (914:6): [True: 0, False: 15.8k]
  |  Branch (914:17): [True: 0, False: 15.8k]
  ------------------
  915|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  916|       |
  917|       |	/* an OID must have at least two components */
  918|  15.8k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (918:6): [True: 0, False: 15.8k]
  |  Branch (918:28): [True: 0, False: 15.8k]
  ------------------
  919|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  920|       |
  921|   148k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|   148k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (921:14): [True: 148k, False: 0]
  ------------------
  922|   148k|		unsigned int k, shift;
  923|       |
  924|   148k|		if (id->value[i] == -1)
  ------------------
  |  Branch (924:7): [True: 15.8k, False: 132k]
  ------------------
  925|  15.8k|			break;
  926|       |
  927|   132k|		k = id->value[i];
  928|   132k|		switch (i) {
  929|  15.8k|		case 0:
  ------------------
  |  Branch (929:3): [True: 15.8k, False: 116k]
  ------------------
  930|  15.8k|			if (k > 2)
  ------------------
  |  Branch (930:8): [True: 0, False: 15.8k]
  ------------------
  931|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  932|  15.8k|			*p = k * 40;
  933|  15.8k|			break;
  934|  15.8k|		case 1:
  ------------------
  |  Branch (934:3): [True: 15.8k, False: 116k]
  ------------------
  935|  15.8k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (935:8): [True: 0, False: 15.8k]
  |  Branch (935:18): [True: 0, False: 0]
  ------------------
  936|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  937|      0|			}
  938|       |			/* We can encode larger IDs to multiple bytes
  939|       |			 * similarly as the following IDs */
  940|  15.8k|			k += *p;
  941|       |			/* fall through */
  942|   116k|		default:
  ------------------
  |  Branch (942:3): [True: 101k, False: 31.6k]
  ------------------
  943|   116k|			shift = 28;
  944|   569k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (944:11): [True: 467k, False: 102k]
  |  Branch (944:20): [True: 452k, False: 14.8k]
  ------------------
  945|   452k|				shift -= 7;
  946|   131k|			while (shift) {
  ------------------
  |  Branch (946:11): [True: 14.8k, False: 116k]
  ------------------
  947|  14.8k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  948|  14.8k|				shift -= 7;
  949|  14.8k|			}
  950|   116k|			*p++ = k & 0x7F;
  951|   116k|			break;
  952|   132k|		}
  953|   132k|	}
  954|       |
  955|  15.8k|	*buflen = p - temp;
  956|       |
  957|  15.8k|	if (buf)   {
  ------------------
  |  Branch (957:6): [True: 15.8k, False: 0]
  ------------------
  958|  15.8k|		*buf = malloc(*buflen);
  959|  15.8k|		if (!*buf)
  ------------------
  |  Branch (959:7): [True: 0, False: 15.8k]
  ------------------
  960|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  961|  15.8k|		memcpy(*buf, temp, *buflen);
  962|  15.8k|	}
  963|  15.8k|	return 0;
  964|  15.8k|}
sc_asn1_put_tag:
  981|  7.04k|{
  982|  7.04k|	size_t c = 0;
  983|  7.04k|	unsigned int tag_len, ii;
  984|  7.04k|	u8 *p = out;
  985|  7.04k|	u8 tag_char[4] = {0, 0, 0, 0};
  986|       |
  987|       |	/* Check tag */
  988|  7.04k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (988:6): [True: 0, False: 7.04k]
  |  Branch (988:18): [True: 0, False: 7.04k]
  ------------------
  989|       |		/* A tag of 0x00 is not valid and at most 4-byte tag names are supported. */
  990|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  991|      0|	}
  992|  14.0k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (992:20): [True: 7.04k, False: 7.04k]
  ------------------
  993|       |		/* Note: tag char will be reversed order. */
  994|  7.04k|		tag_char[tag_len++] = tag & 0xFF;
  995|  7.04k|	}
  996|       |
  997|  7.04k|	if (tag_len > 1)   {
  ------------------
  |  Branch (997:6): [True: 0, False: 7.04k]
  ------------------
  998|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  191|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  222|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (998:7): [True: 0, False: 0]
  ------------------
  999|       |			/* First byte is not escape marker. */
 1000|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1001|      0|		}
 1002|      0|		for (ii = 1; ii < tag_len - 1; ii++) {
  ------------------
  |  Branch (1002:16): [True: 0, False: 0]
  ------------------
 1003|      0|			if ((tag_char[ii] & 0x80) != 0x80) {
  ------------------
  |  Branch (1003:8): [True: 0, False: 0]
  ------------------
 1004|       |				/* MS bit is not 'one'. */
 1005|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1006|      0|			}
 1007|      0|		}
 1008|      0|		if ((tag_char[0] & 0x80) != 0x00) {
  ------------------
  |  Branch (1008:7): [True: 0, False: 0]
  ------------------
 1009|       |			/* MS bit of the last byte is not 'zero'. */
 1010|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1011|      0|		}
 1012|      0|	}
 1013|       |
 1014|       |	/* Calculate the number of additional bytes necessary to encode the length. */
 1015|       |	/* c+1 is the size of the length field. */
 1016|  7.04k|	if (datalen > 127) {
  ------------------
  |  Branch (1016:6): [True: 0, False: 7.04k]
  ------------------
 1017|      0|		c = 1;
 1018|      0|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1018:10): [True: 0, False: 0]
  ------------------
 1019|      0|			c++;
 1020|      0|	}
 1021|  7.04k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1021:6): [True: 0, False: 7.04k]
  |  Branch (1021:21): [True: 0, False: 7.04k]
  ------------------
 1022|       |		/* Caller only asks for the length that would be written. */
 1023|      0|		return (int)(tag_len + (c + 1) + datalen);
 1024|      0|	}
 1025|       |	/* We will write the tag, so check the length. */
 1026|  7.04k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1026:6): [True: 0, False: 7.04k]
  ------------------
 1027|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1028|  14.0k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1028:12): [True: 7.04k, False: 7.04k]
  ------------------
 1029|  7.04k|		*p++ = tag_char[tag_len - ii - 1];
 1030|       |
 1031|  7.04k|	if (c > 0) {
  ------------------
  |  Branch (1031:6): [True: 0, False: 7.04k]
  ------------------
 1032|      0|		*p++ = 0x80 | c;
 1033|      0|		while (c--)
  ------------------
  |  Branch (1033:10): [True: 0, False: 0]
  ------------------
 1034|      0|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1035|      0|	}
 1036|  7.04k|	else {
 1037|  7.04k|		*p++ = datalen & 0x7F;
 1038|  7.04k|	}
 1039|  7.04k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1039:5): [True: 7.04k, False: 0]
  |  Branch (1039:13): [True: 7.04k, False: 0]
  ------------------
 1040|  7.04k|		memcpy(p, data, datalen);
 1041|  7.04k|		p += datalen;
 1042|  7.04k|	}
 1043|  7.04k|	if (ptr != NULL)
  ------------------
  |  Branch (1043:6): [True: 7.04k, False: 0]
  ------------------
 1044|  7.04k|		*ptr = p;
 1045|  7.04k|	return 0;
 1046|  7.04k|}
sc_asn1_decode:
 1816|  16.6k|{
 1817|  16.6k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1818|  16.6k|}
sc_asn1_decode_choice:
 1822|  6.88k|{
 1823|  6.88k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1824|  6.88k|}
sc_asn1_encode:
 2088|  42.7k|{
 2089|  42.7k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2090|  42.7k|}
_sc_asn1_encode:
 2094|  4.97k|{
 2095|  4.97k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2096|  4.97k|}
_sc_asn1_decode:
 2102|    661|{
 2103|    661|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2104|    661|}
sc_der_copy:
 2108|  1.03k|{
 2109|  1.03k|	if (!dst || !src)
  ------------------
  |  Branch (2109:6): [True: 0, False: 1.03k]
  |  Branch (2109:14): [True: 0, False: 1.03k]
  ------------------
 2110|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2111|  1.03k|	memset(dst, 0, sizeof(*dst));
 2112|  1.03k|	if (src->len) {
  ------------------
  |  Branch (2112:6): [True: 1.02k, False: 10]
  ------------------
 2113|  1.02k|		if (!src->value)
  ------------------
  |  Branch (2113:7): [True: 0, False: 1.02k]
  ------------------
 2114|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2115|  1.02k|		dst->value = malloc(src->len);
 2116|  1.02k|		if (!dst->value)
  ------------------
  |  Branch (2116:7): [True: 0, False: 1.02k]
  ------------------
 2117|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2118|  1.02k|		dst->len = src->len;
 2119|  1.02k|		memcpy(dst->value, src->value, src->len);
 2120|  1.02k|	}
 2121|  1.03k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.03k|#define SC_SUCCESS				0
  ------------------
 2122|  1.03k|}
sc_encode_oid:
 2127|  4.84k|{
 2128|  4.84k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2129|  4.84k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  159|  4.84k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  200|  4.84k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  4.84k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2130|  4.84k|		{ NULL, 0, 0, 0, NULL, NULL }
 2131|  4.84k|	};
 2132|  4.84k|	struct sc_asn1_entry asn1_object_id[2];
 2133|  4.84k|	int rv;
 2134|       |
 2135|  4.84k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2136|  4.84k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2137|       |
 2138|  4.84k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2139|  4.84k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|  4.84k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.84k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.84k|	int _ret = (r); \
  |  |  |  |  168|  4.84k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 4.84k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  4.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2140|       |
 2141|  4.84k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.84k|#define SC_SUCCESS				0
  ------------------
 2142|  4.84k|}
asn1.c:decode_bit_string:
  579|  1.63k|{
  580|  1.63k|	const u8 *in = inbuf;
  581|  1.63k|	u8 *out = (u8 *) outbuf;
  582|  1.63k|	int i, count = 0;
  583|  1.63k|	int zero_bits;
  584|  1.63k|	size_t octets_left;
  585|       |
  586|  1.63k|	if (inlen < 1)
  ------------------
  |  Branch (586:6): [True: 4, False: 1.62k]
  ------------------
  587|      4|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  588|       |
  589|       |	/* The formatting is only enforced by SHALL keyword so we should accept
  590|       |	 * by default also non-strict values. */
  591|  1.62k|	if (strict) {
  ------------------
  |  Branch (591:6): [True: 0, False: 1.62k]
  ------------------
  592|       |		/* 8.6.2.3 If the bitstring is empty, there shall be no
  593|       |		 * subsequent octets,and the initial octet shall be zero. */
  594|      0|		if (inlen == 1 && *in != 0)
  ------------------
  |  Branch (594:7): [True: 0, False: 0]
  |  Branch (594:21): [True: 0, False: 0]
  ------------------
  595|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  596|       |		/* ITU-T Rec. X.690 8.6.2.2: The number shall be in the range zero to seven. */
  597|      0|		if ((*in & ~0x07) != 0)
  ------------------
  |  Branch (597:7): [True: 0, False: 0]
  ------------------
  598|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  599|      0|	}
  600|       |
  601|  1.62k|	memset(outbuf, 0, outlen);
  602|  1.62k|	zero_bits = *in & 0x07;
  603|  1.62k|	in++;
  604|  1.62k|	octets_left = inlen - 1;
  605|  1.62k|	if (outlen < octets_left)
  ------------------
  |  Branch (605:6): [True: 5, False: 1.62k]
  ------------------
  606|      5|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      5|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  607|       |
  608|  37.2k|	while (octets_left) {
  ------------------
  |  Branch (608:9): [True: 35.6k, False: 1.60k]
  ------------------
  609|       |		/* 1st octet of input:  ABCDEFGH, where A is the MSB */
  610|       |		/* 1st octet of output: HGFEDCBA, where A is the LSB */
  611|       |		/* first bit in bit string is the LSB in first resulting octet */
  612|  35.6k|		int bits_to_go;
  613|       |
  614|  35.6k|		*out = 0;
  615|  35.6k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (615:7): [True: 1.55k, False: 34.0k]
  |  Branch (615:27): [True: 933, False: 622]
  ------------------
  616|    933|			bits_to_go = 8 - zero_bits;
  617|       |			/* Verify the padding is zero bits */
  618|    933|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (618:8): [True: 17, False: 916]
  ------------------
  619|     17|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     17|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  620|     17|			}
  621|    933|		} else
  622|  34.6k|			bits_to_go = 8;
  623|  35.5k|		if (invert)
  ------------------
  |  Branch (623:7): [True: 2.20k, False: 33.3k]
  ------------------
  624|  15.5k|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (624:16): [True: 13.3k, False: 2.20k]
  ------------------
  625|  13.3k|				*out |= ((*in >> (7 - i)) & 1) << i;
  626|  13.3k|			}
  627|  33.3k|		else {
  628|  33.3k|			*out = *in;
  629|  33.3k|		}
  630|  35.5k|		out++;
  631|  35.5k|		in++;
  632|  35.5k|		octets_left--;
  633|  35.5k|		count++;
  634|  35.5k|	}
  635|  1.60k|	return (count * 8) - zero_bits;
  636|  1.62k|}
asn1.c:asn1_write_element:
 1056|   281k|{
 1057|   281k|	unsigned char t;
 1058|   281k|	unsigned char *buf, *p;
 1059|   281k|	int c = 0;
 1060|   281k|	unsigned short_tag;
 1061|   281k|	unsigned char tag_char[3] = {0, 0, 0};
 1062|   281k|	size_t tag_len, ii;
 1063|       |
 1064|   281k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  144|   281k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1065|   554k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1065:20): [True: 272k, False: 281k]
  ------------------
 1066|   272k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1067|   281k|	if (!tag_len)
  ------------------
  |  Branch (1067:6): [True: 8.56k, False: 272k]
  ------------------
 1068|  8.56k|		tag_len = 1;
 1069|       |
 1070|   281k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1070:6): [True: 0, False: 281k]
  ------------------
 1071|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  191|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  222|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (1071:7): [True: 0, False: 0]
  ------------------
 1072|      0|			SC_TEST_RET(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_INVALID_DATA, "First byte of the long tag is not 'escape marker'");
  ------------------
  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  167|      0|	int _ret = (r); \
  |  |  168|      0|	if (_ret < 0) { \
  |  |  ------------------
  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  171|      0|		return _ret; \
  |  |  172|      0|	} \
  |  |  173|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1073|       |
 1074|      0|		for (ii = 1; ii < tag_len - 1; ii++)
  ------------------
  |  Branch (1074:16): [True: 0, False: 0]
  ------------------
 1075|      0|			if (!(tag_char[ii] & 0x80))
  ------------------
  |  Branch (1075:8): [True: 0, False: 0]
  ------------------
 1076|      0|				SC_TEST_RET(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_INVALID_DATA, "MS bit expected to be 'one'");
  ------------------
  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  167|      0|	int _ret = (r); \
  |  |  168|      0|	if (_ret < 0) { \
  |  |  ------------------
  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  171|      0|		return _ret; \
  |  |  172|      0|	} \
  |  |  173|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1077|       |
 1078|      0|		if (tag_char[0] & 0x80)
  ------------------
  |  Branch (1078:7): [True: 0, False: 0]
  ------------------
 1079|      0|			SC_TEST_RET(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_INVALID_DATA, "MS bit of the last byte expected to be 'zero'");
  ------------------
  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  167|      0|	int _ret = (r); \
  |  |  168|      0|	if (_ret < 0) { \
  |  |  ------------------
  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  171|      0|		return _ret; \
  |  |  172|      0|	} \
  |  |  173|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1080|      0|	}
 1081|       |
 1082|   281k|	t = tag_char[tag_len - 1] & 0x1F;
 1083|       |
 1084|   281k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  136|   281k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1084:10): [True: 281k, False: 0]
  ------------------
 1085|   235k|	case SC_ASN1_UNI:
  ------------------
  |  |  137|   235k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1085:2): [True: 235k, False: 45.6k]
  ------------------
 1086|   235k|		break;
 1087|  14.0k|	case SC_ASN1_APP:
  ------------------
  |  |  138|  14.0k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1087:2): [True: 14.0k, False: 267k]
  ------------------
 1088|  14.0k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  186|  14.0k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1089|  14.0k|		break;
 1090|  31.6k|	case SC_ASN1_CTX:
  ------------------
  |  |  139|  31.6k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1090:2): [True: 31.6k, False: 249k]
  ------------------
 1091|  31.6k|		t |= SC_ASN1_TAG_CONTEXT;
  ------------------
  |  |  187|  31.6k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
 1092|  31.6k|		break;
 1093|      0|	case SC_ASN1_PRV:
  ------------------
  |  |  140|      0|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (1093:2): [True: 0, False: 281k]
  ------------------
 1094|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  188|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1095|      0|		break;
 1096|   281k|	}
 1097|   281k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  141|   281k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1097:6): [True: 128k, False: 152k]
  ------------------
 1098|   128k|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  190|   128k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1099|   281k|	if (datalen > 127) {
  ------------------
  |  Branch (1099:6): [True: 1.02k, False: 280k]
  ------------------
 1100|  1.02k|		c = 1;
 1101|  1.45k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1101:10): [True: 428, False: 1.02k]
  ------------------
 1102|    428|			c++;
 1103|  1.02k|	}
 1104|       |
 1105|   281k|	*outlen = tag_len + 1 + c + datalen;
 1106|   281k|	buf = malloc(*outlen);
 1107|   281k|	if (buf == NULL)
  ------------------
  |  Branch (1107:6): [True: 0, False: 281k]
  ------------------
 1108|      0|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1109|       |
 1110|   281k|	*out = p = buf;
 1111|   281k|	*p++ = t;
 1112|   281k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1112:12): [True: 0, False: 281k]
  ------------------
 1113|      0|		*p++ = tag_char[tag_len - ii - 1];
 1114|       |
 1115|   281k|	if (c) {
  ------------------
  |  Branch (1115:6): [True: 1.02k, False: 280k]
  ------------------
 1116|  1.02k|		*p++ = 0x80 | c;
 1117|  2.47k|		while (c--)
  ------------------
  |  Branch (1117:10): [True: 1.45k, False: 1.02k]
  ------------------
 1118|  1.45k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1119|  1.02k|	}
 1120|   280k|	else   {
 1121|   280k|		*p++ = datalen & 0x7F;
 1122|   280k|	}
 1123|   281k|	if (datalen && data) {
  ------------------
  |  Branch (1123:6): [True: 279k, False: 1.83k]
  |  Branch (1123:17): [True: 279k, False: 0]
  ------------------
 1124|   279k|		memcpy(p, data, datalen);
 1125|   279k|	}
 1126|       |
 1127|   281k|	return SC_SUCCESS;
  ------------------
  |  |   28|   281k|#define SC_SUCCESS				0
  ------------------
 1128|   281k|}
asn1.c:asn1_decode:
 1724|  41.8k|{
 1725|  41.8k|	int r, idx = 0;
 1726|  41.8k|	const u8 *p = in, *obj;
 1727|  41.8k|	struct sc_asn1_entry *entry = asn1;
 1728|  41.8k|	size_t left = len, objlen;
 1729|       |
 1730|  41.8k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|  83.6k|#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: 7.32k, False: 34.5k]
  |  |  ------------------
  ------------------
 1731|  41.8k|		 "%*.*s""called, left=%"SC_FORMAT_LEN_SIZE_T"u, depth %d%s\n",
 1732|  41.8k|		 depth, depth, "", left, depth, choice ? ", choice" : "");
 1733|       |
 1734|  41.8k|	if (!p)
  ------------------
  |  Branch (1734:6): [True: 2, False: 41.8k]
  ------------------
 1735|      2|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      2|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1736|  41.8k|	if (left < 2) {
  ------------------
  |  Branch (1736:6): [True: 2.54k, False: 39.2k]
  ------------------
 1737|  6.12k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|  4.42k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1737:10): [True: 4.42k, False: 1.70k]
  |  Branch (1737:24): [True: 3.58k, False: 845]
  ------------------
 1738|  3.58k|			asn1++;
 1739|       |		/* If all elements were optional, there's nothing
 1740|       |		 * to complain about */
 1741|  2.54k|		if (asn1->name == NULL)
  ------------------
  |  Branch (1741:7): [True: 1.70k, False: 845]
  ------------------
 1742|  1.70k|			return 0;
 1743|    845|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|    845|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1744|    845|			      "non-optional field \"%s\" not found\n",
 1745|    845|			      asn1->name);
 1746|    845|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    845|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1747|  2.54k|	}
 1748|  39.2k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1748:6): [True: 1.53k, False: 37.7k]
  |  Branch (1748:19): [True: 221, False: 37.5k]
  |  Branch (1748:35): [True: 0, False: 37.5k]
  ------------------
 1749|  1.75k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  1.75k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1750|       |
 1751|   146k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1751:16): [True: 118k, False: 27.9k]
  ------------------
 1752|   118k|		entry = &asn1[idx];
 1753|       |
 1754|   118k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|   118k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  | 1755|   118k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1756|   118k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|   118k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1755|   118k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1756|   118k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1757|       |
 1758|       |		/* Special case CHOICE has no tag */
 1759|   118k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|   118k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1759:7): [True: 440, False: 118k]
  ------------------
 1760|    440|			r = asn1_decode(ctx,
 1761|    440|				(struct sc_asn1_entry *) entry->parm,
 1762|    440|				p, left, &p, &left, 1, depth + 1);
 1763|       |			/* When the inner call fails it returns before writing
 1764|       |			 * back to *newp and *len_left, so the caller's p/left are
 1765|       |			 * unchanged.  Swallowing the error for an optional
 1766|       |			 * CHOICE is therefore safe: the next field will be
 1767|       |			 * attempted at the same position. */
 1768|    440|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|    161|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1768:8): [True: 279, False: 161]
  |  Branch (1768:18): [True: 0, False: 161]
  ------------------
 1769|    279|				r = 0;
 1770|    440|			goto decode_ok;
 1771|    440|		}
 1772|       |
 1773|   118k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1774|   118k|		if (obj == NULL) {
  ------------------
  |  Branch (1774:7): [True: 80.6k, False: 37.4k]
  ------------------
 1775|  80.6k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  80.6k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1776|  80.6k|			if (choice)
  ------------------
  |  Branch (1776:8): [True: 30.7k, False: 49.9k]
  ------------------
 1777|  30.7k|				continue;
 1778|  49.9k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  148|  49.9k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1778:8): [True: 47.9k, False: 1.93k]
  ------------------
 1779|  47.9k|				continue;
 1780|  1.93k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  1.93k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1781|  1.93k|			if (left) {
  ------------------
  |  Branch (1781:8): [True: 1.88k, False: 53]
  ------------------
 1782|  1.88k|				u8 line[128], *linep = line;
 1783|  1.88k|				size_t i;
 1784|       |
 1785|  1.88k|				line[0] = 0;
 1786|  18.4k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1786:17): [True: 16.9k, False: 1.47k]
  |  Branch (1786:27): [True: 16.5k, False: 410]
  ------------------
 1787|  16.5k|					sprintf((char *) linep, "%02X ", p[i]);
 1788|  16.5k|					linep += 3;
 1789|  16.5k|				}
 1790|  1.88k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  1.88k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1791|  1.88k|			}
 1792|  1.93k|			sc_free_entry(asn1);
 1793|  1.93k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  1.93k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.93k|	int _ret = r; \
  |  |  155|  1.93k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.93k, False: 0]
  |  |  ------------------
  |  |  156|  1.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.93k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.93k, False: 0]
  |  |  ------------------
  |  |  157|  1.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.93k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.93k|	return _ret; \
  |  |  163|  1.93k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1794|  1.93k|		}
 1795|  37.4k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1796|       |
 1797|  37.8k|decode_ok:
 1798|  37.8k|		if (r)
  ------------------
  |  Branch (1798:7): [True: 998, False: 36.8k]
  ------------------
 1799|    998|			return r;
 1800|  36.8k|		if (choice)
  ------------------
  |  Branch (1800:7): [True: 6.66k, False: 30.2k]
  ------------------
 1801|  6.66k|			break;
 1802|  36.8k| 	}
 1803|  34.6k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1803:7): [True: 6.98k, False: 27.6k]
  |  Branch (1803:17): [True: 319, False: 6.66k]
  ------------------
 1804|    319|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  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|    319|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 319, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1805|  34.2k| 	if (newp != NULL)
  ------------------
  |  Branch (1805:7): [True: 7.99k, False: 26.2k]
  ------------------
 1806|  7.99k|		*newp = p;
 1807|  34.2k| 	if (len_left != NULL)
  ------------------
  |  Branch (1807:7): [True: 7.99k, False: 26.2k]
  ------------------
 1808|  7.99k|		*len_left = left;
 1809|  34.2k|	if (choice)
  ------------------
  |  Branch (1809:6): [True: 6.66k, False: 27.6k]
  ------------------
 1810|  6.66k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  153|  6.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  6.66k|	int _ret = r; \
  |  |  155|  6.66k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.30k, False: 5.35k]
  |  |  ------------------
  |  |  156|  1.30k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 1.30k]
  |  |  ------------------
  |  |  157|  1.30k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.35k|	} else { \
  |  |  159|  5.35k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  5.35k|			"returning with: %d\n", _ret); \
  |  |  161|  5.35k|	} \
  |  |  162|  6.66k|	return _ret; \
  |  |  163|  6.66k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1811|  27.6k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  153|  27.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  27.6k|	int _ret = r; \
  |  |  155|  27.6k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 27.6k, False: 0]
  |  |  ------------------
  |  |  156|  27.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 27.6k]
  |  |  ------------------
  |  |  157|  27.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  27.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|  27.6k|	return _ret; \
  |  |  163|  27.6k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1812|  27.6k|}
asn1.c:sc_free_entry:
 1689|  9.81k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1690|  9.81k|	int idx = 0;
 1691|  9.81k|	struct sc_asn1_entry *entry = asn1;
 1692|       |
 1693|  9.81k|	if (!asn1)
  ------------------
  |  Branch (1693:6): [True: 381, False: 9.43k]
  ------------------
 1694|    381|		return;
 1695|       |
 1696|  46.3k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1696:16): [True: 36.9k, False: 9.43k]
  ------------------
 1697|  36.9k|		entry = &asn1[idx];
 1698|  36.9k|		switch (entry->type) {
 1699|  2.85k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  170|  2.85k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1699:3): [True: 2.85k, False: 34.0k]
  ------------------
 1700|  7.88k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  7.88k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1700:3): [True: 5.02k, False: 31.8k]
  ------------------
 1701|  7.88k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1702|  7.88k|			break;
 1703|  5.41k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  5.41k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1703:3): [True: 5.41k, False: 31.5k]
  ------------------
 1704|  5.43k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  5.43k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1704:3): [True: 17, False: 36.9k]
  ------------------
 1705|  5.48k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  5.48k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1705:3): [True: 47, False: 36.8k]
  ------------------
 1706|  5.66k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|  5.66k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1706:3): [True: 183, False: 36.7k]
  ------------------
 1707|  5.89k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|  5.89k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1707:3): [True: 228, False: 36.6k]
  ------------------
 1708|  7.37k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  7.37k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1708:3): [True: 1.47k, False: 35.4k]
  ------------------
 1709|  7.37k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  149|  7.37k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    687|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1709:8): [True: 687, False: 6.68k]
  |  Branch (1709:42): [True: 165, False: 522]
  ------------------
 1710|    165|				u8 **buf = (u8 **)entry->parm;
 1711|    165|				free(*buf);
 1712|    165|				*buf = NULL;
 1713|    165|			}
 1714|  7.37k|			break;
 1715|  21.6k|		default:
  ------------------
  |  Branch (1715:3): [True: 21.6k, False: 15.2k]
  ------------------
 1716|  21.6k|			break;
 1717|  36.9k|		}
 1718|  36.9k|	}
 1719|  9.43k|}
asn1.c:asn1_decode_entry:
 1491|  37.4k|{
 1492|  37.4k|	void *parm = entry->parm;
 1493|  37.4k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1494|  37.4k|			     size_t nobjlen, int ndepth);
 1495|  37.4k|	size_t *len = (size_t *) entry->arg;
 1496|  37.4k|	int r = 0;
 1497|       |
 1498|  37.4k|	callback_func = parm;
 1499|       |
 1500|  37.4k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|   149k|#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.64k, False: 32.8k]
  |  |  |  Branch (70:115): [True: 4.64k, False: 32.8k]
  |  |  ------------------
  ------------------
 1501|  37.4k|		depth, depth, "", entry->name,
 1502|  37.4k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1503|  37.4k|		objlen > 16 ? "..." : "");
 1504|       |
 1505|  37.4k|	switch (entry->type) {
 1506|  11.1k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  11.1k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1506:2): [True: 11.1k, False: 26.2k]
  ------------------
 1507|  11.1k|		if (parm != NULL)
  ------------------
  |  Branch (1507:7): [True: 10.3k, False: 785]
  ------------------
 1508|  10.3k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1509|  10.3k|				       objlen, NULL, NULL, 0, depth + 1);
 1510|  11.1k|		break;
 1511|    259|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    259|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1511:2): [True: 259, False: 37.1k]
  ------------------
 1512|    259|		break;
 1513|     12|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|     12|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1513:2): [True: 12, False: 37.4k]
  ------------------
 1514|     12|		if (parm != NULL) {
  ------------------
  |  Branch (1514:7): [True: 12, False: 0]
  ------------------
 1515|     12|			if (objlen != 1) {
  ------------------
  |  Branch (1515:8): [True: 2, False: 10]
  ------------------
 1516|      2|				sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|      2|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1517|      2|					 "invalid ASN.1 object length: %"SC_FORMAT_LEN_SIZE_T"u\n",
 1518|      2|					 objlen);
 1519|      2|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1520|      2|			} else
 1521|     10|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1521:23): [True: 9, False: 1]
  ------------------
 1522|     12|		}
 1523|     12|		break;
 1524|  1.70k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  1.70k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1524:2): [True: 1.70k, False: 35.7k]
  ------------------
 1525|  1.98k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  1.98k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1525:2): [True: 278, False: 37.1k]
  ------------------
 1526|  1.98k|		if (parm != NULL) {
  ------------------
  |  Branch (1526:7): [True: 1.98k, False: 0]
  ------------------
 1527|  1.98k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1528|  1.98k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.98k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1528:8): [True: 1.95k, False: 25]
  ------------------
 1529|  1.95k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  1.95k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1530|  1.95k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1531|  1.95k|			}
 1532|  1.98k|		}
 1533|  1.98k|		break;
 1534|    393|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|    393|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1534:2): [True: 393, False: 37.0k]
  ------------------
 1535|    543|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|    543|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1535:2): [True: 150, False: 37.3k]
  ------------------
 1536|    543|		if (parm != NULL) {
  ------------------
  |  Branch (1536:7): [True: 393, False: 150]
  ------------------
 1537|    393|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  155|    393|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1537:17): [True: 0, False: 393]
  ------------------
 1538|    393|			if (len == NULL)
  ------------------
  |  Branch (1538:8): [True: 0, False: 393]
  ------------------
 1539|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1540|    393|			if (objlen < 1) {
  ------------------
  |  Branch (1540:8): [True: 12, False: 381]
  ------------------
 1541|     12|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     12|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1542|     12|				break;
 1543|     12|			}
 1544|    381|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    381|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1544:8): [True: 381, False: 0]
  ------------------
 1545|    381|				u8 **buf = (u8 **) parm;
 1546|    381|				if (objlen > 1) {
  ------------------
  |  Branch (1546:9): [True: 340, False: 41]
  ------------------
 1547|    340|					*buf = malloc(objlen-1);
 1548|    340|					if (*buf == NULL) {
  ------------------
  |  Branch (1548:10): [True: 0, False: 340]
  ------------------
 1549|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1550|      0|						break;
 1551|      0|					}
 1552|    340|				}
 1553|    381|				*len = objlen-1;
 1554|    381|				parm = *buf;
 1555|    381|			}
 1556|    381|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1557|    381|			if (r >= 0) {
  ------------------
  |  Branch (1557:8): [True: 361, False: 20]
  ------------------
 1558|    361|				*len = r;
 1559|    361|				r = 0;
 1560|    361|			}
 1561|    381|		}
 1562|    531|		break;
 1563|  1.25k|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|  1.25k|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1563:2): [True: 1.25k, False: 36.2k]
  ------------------
 1564|  1.25k|		if (parm != NULL)
  ------------------
  |  Branch (1564:7): [True: 1.25k, False: 0]
  ------------------
 1565|  1.25k|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1566|  1.25k|		break;
 1567|  12.5k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  12.5k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1567:2): [True: 12.5k, False: 24.9k]
  ------------------
 1568|  12.5k|		if (parm != NULL) {
  ------------------
  |  Branch (1568:7): [True: 12.5k, False: 22]
  ------------------
 1569|  12.5k|			size_t c;
 1570|  12.5k|			if (len == NULL)
  ------------------
  |  Branch (1570:8): [True: 0, False: 12.5k]
  ------------------
 1571|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1572|       |
 1573|       |			/* Strip off padding zero */
 1574|  12.5k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  12.5k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1574:8): [True: 2.90k, False: 9.59k]
  ------------------
 1575|  2.90k|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1575:9): [True: 2.34k, False: 563]
  |  Branch (1575:23): [True: 450, False: 1.89k]
  ------------------
 1576|    450|				objlen--;
 1577|    450|				obj++;
 1578|    450|			}
 1579|       |
 1580|       |			/* Allocate buffer if needed */
 1581|  12.5k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  12.5k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1581:8): [True: 4.09k, False: 8.40k]
  ------------------
 1582|  4.09k|				u8 **buf = (u8 **) parm;
 1583|  4.09k|				if (objlen > 0) {
  ------------------
  |  Branch (1583:9): [True: 3.02k, False: 1.07k]
  ------------------
 1584|  3.02k|					*buf = malloc(objlen);
 1585|  3.02k|					if (*buf == NULL) {
  ------------------
  |  Branch (1585:10): [True: 0, False: 3.02k]
  ------------------
 1586|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1587|      0|						break;
 1588|      0|					}
 1589|  3.02k|				}
 1590|  4.09k|				c = *len = objlen;
 1591|  4.09k|				parm = *buf;
 1592|  4.09k|			} else
 1593|  8.40k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1593:9): [True: 311, False: 8.09k]
  ------------------
 1594|       |
 1595|  12.5k|			memcpy(parm, obj, c);
 1596|  12.5k|			*len = c;
 1597|  12.5k|		}
 1598|  12.5k|		break;
 1599|  12.5k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|     17|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1599:2): [True: 17, False: 37.4k]
  ------------------
 1600|     17|		if (parm != NULL) {
  ------------------
  |  Branch (1600:7): [True: 17, False: 0]
  ------------------
 1601|     17|			size_t c;
 1602|     17|			if (len == NULL)
  ------------------
  |  Branch (1602:8): [True: 0, False: 17]
  ------------------
 1603|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1604|     17|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|     17|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1604:8): [True: 0, False: 17]
  ------------------
 1605|      0|				u8 **buf = (u8 **) parm;
 1606|      0|				if (objlen > 0) {
  ------------------
  |  Branch (1606:9): [True: 0, False: 0]
  ------------------
 1607|      0|					*buf = malloc(objlen);
 1608|      0|					if (*buf == NULL) {
  ------------------
  |  Branch (1608:10): [True: 0, False: 0]
  ------------------
 1609|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1610|      0|						break;
 1611|      0|					}
 1612|      0|				}
 1613|      0|				c = *len = objlen;
 1614|      0|				parm = *buf;
 1615|      0|			} else
 1616|     17|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1616:9): [True: 1, False: 16]
  ------------------
 1617|       |
 1618|     17|			memcpy(parm, obj, c);
 1619|     17|			*len = c;
 1620|     17|		}
 1621|     17|		break;
 1622|    820|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|    820|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1622:2): [True: 820, False: 36.6k]
  ------------------
 1623|    820|		if (parm != NULL)
  ------------------
  |  Branch (1623:7): [True: 817, False: 3]
  ------------------
 1624|    817|			r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *) parm);
 1625|    820|		break;
 1626|      4|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      4|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1626:2): [True: 4, False: 37.4k]
  ------------------
 1627|    607|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|    607|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1627:2): [True: 603, False: 36.8k]
  ------------------
 1628|    607|		if (parm != NULL) {
  ------------------
  |  Branch (1628:7): [True: 603, False: 4]
  ------------------
 1629|    603|			if (len == NULL)
  ------------------
  |  Branch (1629:8): [True: 0, False: 603]
  ------------------
 1630|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1631|    603|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    603|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1631:8): [True: 0, False: 603]
  ------------------
 1632|      0|				u8 **buf = (u8 **) parm;
 1633|      0|				*buf = malloc(objlen+1);
 1634|      0|				if (*buf == NULL) {
  ------------------
  |  Branch (1634:9): [True: 0, False: 0]
  ------------------
 1635|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1636|      0|					break;
 1637|      0|				}
 1638|      0|				*len = objlen+1;
 1639|      0|				parm = *buf;
 1640|      0|			}
 1641|    603|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1642|    603|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    603|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1642:8): [True: 0, False: 603]
  ------------------
 1643|      0|				*len -= 1;
 1644|      0|			}
 1645|    603|		}
 1646|    607|		break;
 1647|  6.45k|	case SC_ASN1_PATH:
  ------------------
  |  |  174|  6.45k|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1647:2): [True: 6.45k, False: 30.9k]
  ------------------
 1648|  6.45k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1648:7): [True: 6.44k, False: 13]
  ------------------
 1649|  6.44k|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1650|  6.45k|		break;
 1651|    351|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|    351|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1651:2): [True: 351, False: 37.1k]
  ------------------
 1652|    351|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1652:7): [True: 351, False: 0]
  ------------------
 1653|    351|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1654|    351|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1654:15): [True: 0, False: 351]
  ------------------
 1655|       |
 1656|    351|			memcpy(id->value, obj, c);
 1657|    351|			id->len = c;
 1658|    351|		}
 1659|    351|		break;
 1660|    314|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|    314|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1660:2): [True: 314, False: 37.1k]
  ------------------
 1661|    314|		if (entry->parm != NULL)
  ------------------
  |  Branch (1661:7): [True: 310, False: 4]
  ------------------
 1662|    310|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1663|    314|		break;
 1664|    628|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|    628|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1664:2): [True: 628, False: 36.8k]
  ------------------
 1665|    628|		if (entry->parm != NULL)
  ------------------
  |  Branch (1665:7): [True: 628, False: 0]
  ------------------
 1666|    628|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1667|    628|		break;
 1668|     17|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|     17|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1668:2): [True: 17, False: 37.4k]
  ------------------
 1669|     17|		if (entry->parm != NULL)
  ------------------
  |  Branch (1669:7): [True: 17, False: 0]
  ------------------
 1670|     17|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1671|     17|		break;
 1672|    488|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|    488|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1672:2): [True: 488, False: 36.9k]
  ------------------
 1673|    488|		if (entry->parm != NULL)
  ------------------
  |  Branch (1673:7): [True: 488, False: 0]
  ------------------
 1674|    488|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1675|    488|		break;
 1676|      0|	default:
  ------------------
  |  Branch (1676:2): [True: 0, False: 37.4k]
  ------------------
 1677|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 type: %d\n", entry->type);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1678|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1679|  37.4k|	}
 1680|  37.4k|	if (r) {
  ------------------
  |  Branch (1680:6): [True: 837, False: 36.6k]
  ------------------
 1681|    837|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|    837|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1682|    837|		      sc_strerror(r));
 1683|    837|		return r;
 1684|    837|	}
 1685|  36.6k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  36.6k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1686|  36.6k|	return 0;
 1687|  37.4k|}
asn1.c:decode_bit_field:
  692|  1.25k|{
  693|  1.25k|	u8		data[sizeof(unsigned int)];
  694|  1.25k|	unsigned int	field = 0;
  695|  1.25k|	int		i, n;
  696|       |
  697|  1.25k|	if (outlen != sizeof(data))
  ------------------
  |  Branch (697:6): [True: 0, False: 1.25k]
  ------------------
  698|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  699|       |
  700|  1.25k|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  701|  1.25k|	if (n < 0)
  ------------------
  |  Branch (701:6): [True: 38, False: 1.21k]
  ------------------
  702|     38|		return n;
  703|       |
  704|  3.42k|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (704:14): [True: 2.20k, False: 1.21k]
  ------------------
  705|  2.20k|		field |= ((unsigned int) data[i/8] << i);
  706|  2.20k|	}
  707|  1.21k|	memcpy(outbuf, &field, outlen);
  708|  1.21k|	return 0;
  709|  1.25k|}
asn1.c:sc_asn1_decode_utf8string:
  968|    603|{
  969|    603|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (969:6): [True: 3, False: 600]
  ------------------
  970|      3|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      3|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  971|    600|	*outlen = inlen+1;
  972|    600|	memcpy(out, inbuf, inlen);
  973|    600|	out[inlen] = 0;
  974|    600|	return 0;
  975|    603|}
asn1.c:asn1_decode_path:
 1150|  6.44k|{
 1151|  6.44k|	int idx, count, r;
 1152|  6.44k|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1153|  6.44k|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1154|  6.44k|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1155|       |
 1156|  6.44k|	memset(path, 0, sizeof(struct sc_path));
 1157|       |
 1158|  6.44k|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1159|  6.44k|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1160|       |
 1161|  6.44k|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1162|  6.44k|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1163|       |
 1164|  6.44k|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1165|  6.44k|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1166|  6.44k|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1167|  6.44k|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1168|       |
 1169|  6.44k|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1170|  6.44k|	if (r)
  ------------------
  |  Branch (1170:6): [True: 17, False: 6.42k]
  ------------------
 1171|     17|		return r;
 1172|       |
 1173|  6.42k|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|  6.42k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1173:6): [True: 0, False: 6.42k]
  ------------------
 1174|       |		/* extended path present: set 'path' and 'aid' */
 1175|      0|		memcpy(path->aid.value, aid_value, aid_len);
 1176|      0|		path->aid.len = aid_len;
 1177|       |
 1178|      0|		memcpy(path->value, path_value, path_len);
 1179|      0|		path->len = path_len;
 1180|      0|	}
 1181|  6.42k|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|  6.42k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1181:11): [True: 6.40k, False: 26]
  ------------------
 1182|       |		/* path present: set 'path' */
 1183|  6.40k|		memcpy(path->value, path_value, path_len);
 1184|  6.40k|		path->len = path_len;
 1185|  6.40k|	}
 1186|     26|	else   {
 1187|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1188|     26|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     26|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1189|     26|	}
 1190|       |
 1191|  6.40k|	if (path->len == 2)
  ------------------
  |  Branch (1191:6): [True: 390, False: 6.01k]
  ------------------
 1192|    390|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    390|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1193|  6.01k|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1193:13): [True: 0, False: 6.01k]
  |  Branch (1193:30): [True: 0, False: 0]
  ------------------
 1194|      0|		path->type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 1195|  6.01k|	else
 1196|  6.01k|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  6.01k|#define SC_PATH_TYPE_PATH		2
  ------------------
 1197|       |
 1198|  6.40k|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  6.40k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    159|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1198:6): [True: 159, False: 6.24k]
  |  Branch (1198:48): [True: 66, False: 93]
  ------------------
 1199|     66|		path->index = idx;
 1200|     66|		path->count = count;
 1201|     66|	}
 1202|  6.33k|	else {
 1203|  6.33k|		path->index = 0;
 1204|  6.33k|		path->count = -1;
 1205|  6.33k|	}
 1206|       |
 1207|  6.40k|	return SC_SUCCESS;
  ------------------
  |  |   28|  6.40k|#define SC_SUCCESS				0
  ------------------
 1208|  6.42k|}
asn1.c:asn1_decode_p15_object:
 1396|    310|{
 1397|    310|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1398|    310|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1399|    310|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1400|    310|	size_t flags_len = sizeof(p15_obj->flags);
 1401|    310|	size_t label_len = sizeof(p15_obj->label);
 1402|    310|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1403|    310|	int r, ii;
 1404|       |
 1405|  2.79k|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|  2.79k|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1405:13): [True: 2.48k, False: 310]
  ------------------
 1406|  2.48k|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1407|    310|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1408|       |
 1409|       |
 1410|    310|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1411|    310|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1412|    310|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1413|    310|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1414|    310|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1415|    310|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1416|       |
 1417|  2.79k|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|  2.79k|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1417:13): [True: 2.48k, False: 310]
  ------------------
 1418|  2.48k|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1419|  2.48k|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1420|  2.48k|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1421|  2.48k|	}
 1422|    310|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1423|       |
 1424|    310|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1425|    310|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1426|    310|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1427|    310|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1428|       |
 1429|    310|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1430|    310|	return r;
 1431|    310|}
asn1.c:asn1_decode_se_info:
 1244|     17|{
 1245|     17|	struct sc_pkcs15_sec_env_info **ses;
 1246|     17|	const unsigned char *ptr = obj;
 1247|     17|	size_t idx, ptrlen = objlen;
 1248|     17|	int ret;
 1249|       |
 1250|     17|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     17|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     17|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     17|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     17|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1251|       |
 1252|     17|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|     17|#define SC_MAX_SE_NUM			8
  ------------------
 1253|     17|	if (ses == NULL) {
  ------------------
  |  Branch (1253:6): [True: 0, False: 17]
  ------------------
 1254|      0|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1255|      0|	}
 1256|       |
 1257|     25|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|     50|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1257:14): [True: 25, False: 0]
  |  Branch (1257:37): [True: 16, False: 9]
  ------------------
 1258|     16|		struct sc_asn1_entry asn1_se[2];
 1259|     16|		struct sc_asn1_entry asn1_se_info[4];
 1260|     16|		struct sc_pkcs15_sec_env_info si;
 1261|       |
 1262|     16|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1263|     16|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1264|       |
 1265|     16|		si.aid.len = sizeof(si.aid.value);
 1266|     16|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1267|     16|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1268|     16|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1269|     16|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1270|       |
 1271|     16|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1272|     16|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
  |  Branch (1272:7): [True: 8, False: 8]
  ------------------
 1273|      8|			goto err;
 1274|      8|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|      8|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1274:7): [True: 5, False: 3]
  ------------------
 1275|      5|			sc_init_oid(&si.owner);
 1276|       |
 1277|      8|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1278|      8|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1278:7): [True: 0, False: 8]
  ------------------
 1279|      0|			ret = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1280|      0|			goto err;
 1281|      0|		}
 1282|       |
 1283|      8|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1284|      8|		idx++;
 1285|      8|	}
 1286|       |
 1287|      9|	*se  = ses;
 1288|      9|	*num = idx;
 1289|      9|	ret = SC_SUCCESS;
  ------------------
  |  |   28|      9|#define SC_SUCCESS				0
  ------------------
 1290|     17|err:
 1291|     17|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (1291:6): [True: 8, False: 9]
  ------------------
 1292|      8|		size_t i;
 1293|     12|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1293:15): [True: 4, False: 8]
  ------------------
 1294|      4|			if (ses[i])
  ------------------
  |  Branch (1294:8): [True: 4, False: 0]
  ------------------
 1295|      4|				free(ses[i]);
 1296|      8|		free(ses);
 1297|      8|	}
 1298|       |
 1299|     17|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  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|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 8, False: 9]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1300|     17|}
asn1.c:asn1_encode:
 2045|   177k|{
 2046|   177k|	int r, idx = 0;
 2047|   177k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2048|   177k|	size_t total = 0, objsize;
 2049|       |
 2050|   177k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2050:6): [True: 0, False: 177k]
  ------------------
 2051|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2052|      0|	}
 2053|       |
 2054|   672k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2054:16): [True: 497k, False: 175k]
  ------------------
 2055|   497k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2056|   497k|		if (r) {
  ------------------
  |  Branch (2056:7): [True: 2.33k, False: 495k]
  ------------------
 2057|  2.33k|			if (obj)
  ------------------
  |  Branch (2057:8): [True: 0, False: 2.33k]
  ------------------
 2058|      0|				free(obj);
 2059|  2.33k|			if (buf)
  ------------------
  |  Branch (2059:8): [True: 635, False: 1.69k]
  ------------------
 2060|    635|				free(buf);
 2061|  2.33k|			return r;
 2062|  2.33k|		}
 2063|       |		/* in case of an empty (optional) element continue with
 2064|       |		 * the next asn1 element */
 2065|   495k|		if (!objsize)
  ------------------
  |  Branch (2065:7): [True: 214k, False: 281k]
  ------------------
 2066|   214k|			continue;
 2067|   281k|		tmp = (u8 *) realloc(buf, total + objsize);
 2068|   281k|		if (!tmp) {
  ------------------
  |  Branch (2068:7): [True: 0, False: 281k]
  ------------------
 2069|      0|			if (obj)
  ------------------
  |  Branch (2069:8): [True: 0, False: 0]
  ------------------
 2070|      0|				free(obj);
 2071|      0|			if (buf)
  ------------------
  |  Branch (2071:8): [True: 0, False: 0]
  ------------------
 2072|      0|				free(buf);
 2073|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2074|      0|		}
 2075|   281k|		buf = tmp;
 2076|   281k|		memcpy(buf + total, obj, objsize);
 2077|   281k|		free(obj);
 2078|   281k|		obj = NULL;
 2079|   281k|		total += objsize;
 2080|   281k|	}
 2081|   175k|	*ptr = buf;
 2082|   175k|	*size = total;
 2083|   175k|	return 0;
 2084|   177k|}
asn1.c:asn1_encode_entry:
 1828|   501k|{
 1829|   501k|	void *parm = entry->parm;
 1830|   501k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1831|   501k|			     size_t *nobjlen, int ndepth);
 1832|   501k|	const size_t *len = (const size_t *) entry->arg;
 1833|   501k|	int r = 0;
 1834|   501k|	u8 * buf = NULL;
 1835|   501k|	size_t buflen = 0;
 1836|       |
 1837|   501k|	callback_func = parm;
 1838|       |
 1839|   501k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|   501k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  | 1840|   501k|	       	depth, depth, "", entry->name,
  |  |  |  | 1841|   501k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|   501k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1840|   501k|	       	depth, depth, "", entry->name,
 1841|   501k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1842|   501k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|   501k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1842:6): [True: 214k, False: 287k]
  ------------------
 1843|   214k|		goto no_object;
 1844|   287k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|   575k|#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: 97.4k, False: 190k]
  |  |  ------------------
  ------------------
 1845|   287k|		 "%*.*stype=%d, tag=0x%02x, parm=%p, len=%"SC_FORMAT_LEN_SIZE_T"u\n",
 1846|   287k|		 depth, depth, "", entry->type, entry->tag, parm,
 1847|   287k|		 len ? *len : 0);
 1848|       |
 1849|   287k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|   287k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1849:6): [True: 4.06k, False: 283k]
  ------------------
 1850|  4.06k|		const struct sc_asn1_entry *list, *choice = NULL;
 1851|       |
 1852|  4.06k|		list = (const struct sc_asn1_entry *) parm;
 1853|  16.0k|		while (list->name != NULL) {
  ------------------
  |  Branch (1853:10): [True: 12.0k, False: 4.06k]
  ------------------
 1854|  12.0k|			if (list->flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|  12.0k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1854:8): [True: 4.06k, False: 7.94k]
  ------------------
 1855|  4.06k|				if (choice) {
  ------------------
  |  Branch (1855:9): [True: 0, False: 4.06k]
  ------------------
 1856|      0|					sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1857|      0|						"ASN.1 problem: more than "
 1858|      0|						"one CHOICE when encoding %s: "
 1859|      0|						"%s and %s both present\n",
 1860|      0|						entry->name,
 1861|      0|						choice->name,
 1862|      0|						list->name);
 1863|      0|					return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1864|      0|				}
 1865|  4.06k|				choice = list;
 1866|  4.06k|			}
 1867|  12.0k|			list++;
 1868|  12.0k|		}
 1869|  4.06k|		if (choice == NULL)
  ------------------
  |  Branch (1869:7): [True: 0, False: 4.06k]
  ------------------
 1870|      0|			goto no_object;
 1871|  4.06k|		return asn1_encode_entry(ctx, choice, obj, objlen, depth + 1);
 1872|  4.06k|	}
 1873|       |
 1874|   283k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  158|   567k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1874:6): [True: 283k, False: 245]
  |  Branch (1874:37): [True: 23, False: 283k]
  ------------------
 1875|     23|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "unexpected parm == NULL\n");
  ------------------
  |  |   70|     23|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1876|     23|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     23|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1877|     23|	}
 1878|       |
 1879|   283k|	switch (entry->type) {
 1880|  81.9k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  81.9k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1880:2): [True: 81.9k, False: 201k]
  ------------------
 1881|  81.9k|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1882|  81.9k|				&buflen, depth + 1);
 1883|  81.9k|		break;
 1884|    245|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    245|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1884:2): [True: 245, False: 283k]
  ------------------
 1885|    245|		buf = NULL;
 1886|    245|		buflen = 0;
 1887|    245|		break;
 1888|     55|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|     55|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1888:2): [True: 55, False: 283k]
  ------------------
 1889|     55|		buf = malloc(1);
 1890|     55|		if (buf == NULL) {
  ------------------
  |  Branch (1890:7): [True: 0, False: 55]
  ------------------
 1891|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1892|      0|			break;
 1893|      0|		}
 1894|     55|		buf[0] = *((int *) parm) ? 0xFF : 0;
  ------------------
  |  Branch (1894:12): [True: 55, False: 0]
  ------------------
 1895|     55|		buflen = 1;
 1896|     55|		break;
 1897|  27.0k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  27.0k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1897:2): [True: 27.0k, False: 256k]
  ------------------
 1898|  30.5k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  30.5k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1898:2): [True: 3.58k, False: 280k]
  ------------------
 1899|  30.5k|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1900|  30.5k|		break;
 1901|    138|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|    138|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1901:2): [True: 138, False: 283k]
  ------------------
 1902|    138|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|    138|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1902:2): [True: 0, False: 283k]
  ------------------
 1903|    138|		if (len != NULL) {
  ------------------
  |  Branch (1903:7): [True: 138, False: 0]
  ------------------
 1904|    138|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  155|    138|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1904:8): [True: 0, False: 138]
  ------------------
 1905|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1906|    138|			else
 1907|    138|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1908|    138|		} else {
 1909|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1910|      0|		}
 1911|    138|		break;
 1912|  14.9k|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|  14.9k|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1912:2): [True: 14.9k, False: 268k]
  ------------------
 1913|  14.9k|		if (len != NULL) {
  ------------------
  |  Branch (1913:7): [True: 14.9k, False: 0]
  ------------------
 1914|  14.9k|			r = encode_bit_field((const u8 *) parm, *len, &buf, &buflen);
 1915|  14.9k|		} else {
 1916|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1917|      0|		}
 1918|  14.9k|		break;
 1919|      0|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      0|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1919:2): [True: 0, False: 283k]
  ------------------
 1920|  42.5k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  42.5k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1920:2): [True: 42.5k, False: 241k]
  ------------------
 1921|  82.3k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  82.3k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1921:2): [True: 39.7k, False: 243k]
  ------------------
 1922|  82.3k|		if (len != NULL) {
  ------------------
  |  Branch (1922:7): [True: 82.3k, False: 0]
  ------------------
 1923|  82.3k|			buf = malloc(*len + 1);
 1924|  82.3k|			if (buf == NULL) {
  ------------------
  |  Branch (1924:8): [True: 0, False: 82.3k]
  ------------------
 1925|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1926|      0|				break;
 1927|      0|			}
 1928|  82.3k|			buflen = 0;
 1929|       |			/* If the integer is supposed to be unsigned, insert
 1930|       |			 * a padding byte if the MSB is one */
 1931|  82.3k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  82.3k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1931:8): [True: 339, False: 81.9k]
  ------------------
 1932|    339|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1932:9): [True: 128, False: 211]
  ------------------
 1933|    128|				buf[buflen++] = 0x00;
 1934|    128|			}
 1935|  82.3k|			memcpy(buf + buflen, parm, *len);
 1936|  82.3k|			buflen += *len;
 1937|  82.3k|		} else {
 1938|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1939|      0|		}
 1940|  82.3k|		break;
 1941|  82.3k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1941:2): [True: 0, False: 283k]
  ------------------
 1942|      0|		if (len != NULL) {
  ------------------
  |  Branch (1942:7): [True: 0, False: 0]
  ------------------
 1943|      0|			buf = malloc(*len);
 1944|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1944:8): [True: 0, False: 0]
  ------------------
 1945|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1946|      0|				break;
 1947|      0|			}
 1948|      0|			memcpy(buf, parm, *len);
 1949|      0|			buflen = *len;
 1950|      0|		} else {
 1951|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1952|      0|		}
 1953|      0|		break;
 1954|  15.8k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  15.8k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1954:2): [True: 15.8k, False: 267k]
  ------------------
 1955|  15.8k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1956|  15.8k|		break;
 1957|  24.0k|	case SC_ASN1_PATH:
  ------------------
  |  |  174|  24.0k|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1957:2): [True: 24.0k, False: 259k]
  ------------------
 1958|  24.0k|		r = asn1_encode_path(ctx, (const sc_path_t *) parm, &buf, &buflen, depth, entry->flags);
 1959|  24.0k|		break;
 1960|  9.83k|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|  9.83k|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1960:2): [True: 9.83k, False: 273k]
  ------------------
 1961|  9.83k|		{
 1962|  9.83k|			const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm;
 1963|       |
 1964|  9.83k|			buf = malloc(id->len);
 1965|  9.83k|			if (buf == NULL) {
  ------------------
  |  Branch (1965:8): [True: 0, False: 9.83k]
  ------------------
 1966|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1967|      0|				break;
 1968|      0|			}
 1969|  9.83k|			memcpy(buf, id->value, id->len);
 1970|  9.83k|			buflen = id->len;
 1971|  9.83k|		}
 1972|      0|		break;
 1973|  23.7k|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|  23.7k|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1973:2): [True: 23.7k, False: 259k]
  ------------------
 1974|  23.7k|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1975|  23.7k|		break;
 1976|    138|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|    138|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1976:2): [True: 138, False: 283k]
  ------------------
 1977|    138|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1978|    138|		break;
 1979|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1979:2): [True: 0, False: 283k]
  ------------------
 1980|      0|		if (!len)
  ------------------
  |  Branch (1980:7): [True: 0, False: 0]
  ------------------
 1981|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1982|      0|		r = asn1_encode_se_info(ctx, (struct sc_pkcs15_sec_env_info **)parm, *len, &buf, &buflen, depth);
 1983|      0|		break;
 1984|      0|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|      0|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1984:2): [True: 0, False: 283k]
  ------------------
 1985|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1986|      0|		break;
 1987|      0|	default:
  ------------------
  |  Branch (1987:2): [True: 0, False: 283k]
  ------------------
 1988|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 type: %d\n", entry->type);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1989|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1990|   283k|	}
 1991|   283k|	if (r) {
  ------------------
  |  Branch (1991:6): [True: 1.68k, False: 282k]
  ------------------
 1992|  1.68k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|  1.68k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1993|  1.68k|		      sc_strerror(r));
 1994|  1.68k|		if (buf)
  ------------------
  |  Branch (1994:7): [True: 0, False: 1.68k]
  ------------------
 1995|      0|			free(buf);
 1996|  1.68k|		return r;
 1997|  1.68k|	}
 1998|       |
 1999|       |	/* Treatment of OPTIONAL elements:
 2000|       |	 *  -	if the encoding has 0 length, and the element is OPTIONAL,
 2001|       |	 *	we don't write anything (unless it's an ASN1 NULL and the
 2002|       |	 *      SC_ASN1_PRESENT flag is set).
 2003|       |	 *  -	if the encoding has 0 length, but the element is non-OPTIONAL,
 2004|       |	 *	constructed, we write a empty element (e.g. a SEQUENCE of
 2005|       |	 *      length 0). In case of an ASN1 NULL just write the tag and
 2006|       |	 *      length (i.e. 0x05,0x00).
 2007|       |	 *  -	any other empty objects are considered bogus
 2008|       |	 */
 2009|   496k|no_object:
 2010|   496k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  148|   712k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|   215k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2010:6): [True: 216k, False: 279k]
  |  Branch (2010:17): [True: 215k, False: 1.31k]
  |  Branch (2010:52): [True: 214k, False: 1.14k]
  ------------------
 2011|       |		/* This happens when we try to encode e.g. the
 2012|       |		 * subClassAttributes, which may be empty */
 2013|   214k|		*obj = NULL;
 2014|   214k|		*objlen = 0;
 2015|   214k|		r = 0;
 2016|   282k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  151|  2.46k|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2016:13): [True: 2.46k, False: 279k]
  |  Branch (2016:24): [True: 496, False: 1.96k]
  ------------------
 2017|    496|		*obj = NULL;
 2018|    496|		*objlen = 0;
 2019|    496|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2020|    496|		if (r)
  ------------------
  |  Branch (2020:7): [True: 0, False: 496]
  ------------------
 2021|      0|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "error writing ASN.1 tag and length: %s\n", sc_strerror(r));
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2022|   281k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  158|   283k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  141|  1.72k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2022:13): [True: 279k, False: 1.96k]
  |  Branch (2022:23): [True: 245, False: 1.72k]
  |  Branch (2022:54): [True: 1.09k, False: 628]
  ------------------
 2023|   280k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2024|   280k|		if (r)
  ------------------
  |  Branch (2024:7): [True: 0, False: 280k]
  ------------------
 2025|      0|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "error writing ASN.1 tag and length: %s\n",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2026|   280k|					sc_strerror(r));
 2027|   280k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    628|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2027:13): [True: 0, False: 628]
  ------------------
 2028|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode non-optional ASN.1 object: not given by caller\n");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2029|      0|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2030|    628|	} else {
 2031|    628|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode empty non-optional ASN.1 object\n");
  ------------------
  |  |   70|    628|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2032|    628|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    628|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2033|    628|	}
 2034|   496k|	if (buf)
  ------------------
  |  Branch (2034:6): [True: 280k, False: 215k]
  ------------------
 2035|   280k|		free(buf);
 2036|   496k|	if (r >= 0)
  ------------------
  |  Branch (2036:6): [True: 495k, False: 628]
  ------------------
 2037|   495k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|   495k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2038|   496k|			 "%*.*slength of encoded item=%"SC_FORMAT_LEN_SIZE_T"u\n",
 2039|   496k|			 depth, depth, "", *objlen);
 2040|   496k|	return r;
 2041|   283k|}
asn1.c:asn1_encode_integer:
  776|  30.5k|{
  777|  30.5k|	int i = sizeof(in) * 8, skip_zero, skip_sign;
  778|  30.5k|	u8 *p, b;
  779|       |
  780|  30.5k|	if (in < 0)
  ------------------
  |  Branch (780:6): [True: 138, False: 30.4k]
  ------------------
  781|    138|	{
  782|    138|		skip_sign = 1;
  783|    138|		skip_zero= 0;
  784|    138|	}
  785|  30.4k|	else
  786|  30.4k|	{
  787|  30.4k|		skip_sign = 0;
  788|  30.4k|		skip_zero= 1;
  789|  30.4k|	}
  790|  30.5k|	*obj = p = malloc(sizeof(in)+1);
  791|  30.5k|	if (*obj == NULL)
  ------------------
  |  Branch (791:6): [True: 0, False: 30.5k]
  ------------------
  792|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  793|   122k|	do {
  794|   122k|		i -= 8;
  795|   122k|		b = in >> i;
  796|   122k|		if (skip_sign)
  ------------------
  |  Branch (796:7): [True: 511, False: 121k]
  ------------------
  797|    511|		{
  798|    511|			if (b != 0xff)
  ------------------
  |  Branch (798:8): [True: 74, False: 437]
  ------------------
  799|     74|				skip_sign = 0;
  800|    511|			if (b & 0x80)
  ------------------
  |  Branch (800:8): [True: 508, False: 3]
  ------------------
  801|    508|			{
  802|    508|				*p = b;
  803|    508|				if (0xff == b)
  ------------------
  |  Branch (803:9): [True: 437, False: 71]
  ------------------
  804|    437|					continue;
  805|    508|			}
  806|      3|			else
  807|      3|			{
  808|      3|				p++;
  809|      3|				skip_sign = 0;
  810|      3|			}
  811|    511|		}
  812|   121k|		if (b == 0 && skip_zero)
  ------------------
  |  Branch (812:7): [True: 93.3k, False: 28.6k]
  |  Branch (812:17): [True: 91.3k, False: 1.91k]
  ------------------
  813|  91.3k|			continue;
  814|  30.5k|		if (skip_zero) {
  ------------------
  |  Branch (814:7): [True: 22.5k, False: 7.97k]
  ------------------
  815|  22.5k|			skip_zero = 0;
  816|       |			/* prepend 0x00 if MSb is 1 and integer positive */
  817|  22.5k|			if ((b & 0x80) != 0 && in > 0)
  ------------------
  |  Branch (817:8): [True: 1.84k, False: 20.6k]
  |  Branch (817:27): [True: 1.84k, False: 0]
  ------------------
  818|  1.84k|				*p++ = 0;
  819|  22.5k|		}
  820|  30.5k|		*p++ = b;
  821|   122k|	} while (i > 0);
  ------------------
  |  Branch (821:11): [True: 91.7k, False: 30.5k]
  ------------------
  822|  30.5k|	if (skip_sign)
  ------------------
  |  Branch (822:6): [True: 64, False: 30.5k]
  ------------------
  823|     64|		p++;
  824|  30.5k|	*objsize = p - *obj;
  825|  30.5k|	if (*objsize == 0) {
  ------------------
  |  Branch (825:6): [True: 7.90k, False: 22.6k]
  ------------------
  826|  7.90k|		*objsize = 1;
  827|  7.90k|		(*obj)[0] = 0;
  828|  7.90k|	}
  829|  30.5k|	return 0;
  830|  30.5k|}
asn1.c:encode_bit_string:
  652|  15.0k|{
  653|  15.0k|	const u8 *in = inbuf;
  654|  15.0k|	u8 *out;
  655|  15.0k|	size_t bytes, skipped = 0;
  656|       |
  657|  15.0k|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  146|  15.0k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  658|  15.0k|	*outbuf = out = malloc(bytes);
  659|  15.0k|	if (out == NULL)
  ------------------
  |  Branch (659:6): [True: 0, False: 15.0k]
  ------------------
  660|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  661|  15.0k|	*outlen = bytes;
  662|  15.0k|	out += 1;
  663|  43.2k|	while (bits_left) {
  ------------------
  |  Branch (663:9): [True: 28.1k, False: 15.0k]
  ------------------
  664|  28.1k|		size_t i, bits_to_go = 8;
  665|       |
  666|  28.1k|		*out = 0;
  667|  28.1k|		if (bits_left < 8) {
  ------------------
  |  Branch (667:7): [True: 13.9k, False: 14.2k]
  ------------------
  668|  13.9k|			bits_to_go = bits_left;
  669|  13.9k|			skipped = 8 - bits_left;
  670|  13.9k|		}
  671|  28.1k|		if (invert) {
  ------------------
  |  Branch (671:7): [True: 15.6k, False: 12.5k]
  ------------------
  672|  65.6k|			for (i = 0; i < bits_to_go; i++)
  ------------------
  |  Branch (672:16): [True: 49.9k, False: 15.6k]
  ------------------
  673|  49.9k|				*out |= ((*in >> i) & 1) << (7 - i);
  674|  15.6k|		} else {
  675|  12.5k|			*out = *in;
  676|  12.5k|			if (bits_left < 8)
  ------------------
  |  Branch (676:8): [True: 0, False: 12.5k]
  ------------------
  677|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  678|  12.5k|		}
  679|  28.1k|		bits_left -= bits_to_go;
  680|  28.1k|		out++, in++;
  681|  28.1k|	}
  682|  15.0k|	out = *outbuf;
  683|  15.0k|	out[0] = skipped;
  684|  15.0k|	return 0;
  685|  15.0k|}
asn1.c:encode_bit_field:
  713|  14.9k|{
  714|  14.9k|	u8		data[sizeof(unsigned int)];
  715|  14.9k|	unsigned int	field = 0;
  716|  14.9k|	size_t		i, bits;
  717|       |
  718|  14.9k|	if (inlen != sizeof(data))
  ------------------
  |  Branch (718:6): [True: 0, False: 14.9k]
  ------------------
  719|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  720|       |
  721|       |	/* count the bits */
  722|  14.9k|	memcpy(&field, inbuf, inlen);
  723|  64.9k|	for (bits = 0; field; bits++)
  ------------------
  |  Branch (723:17): [True: 49.9k, False: 14.9k]
  ------------------
  724|  49.9k|		field >>= 1;
  725|       |
  726|  14.9k|	memcpy(&field, inbuf, inlen);
  727|  30.6k|	for (i = 0; i < bits; i += 8)
  ------------------
  |  Branch (727:14): [True: 15.6k, False: 14.9k]
  ------------------
  728|  15.6k|		data[i/8] = field >> i;
  729|       |
  730|  14.9k|	return encode_bit_string(data, bits, outbuf, outlen, 1);
  731|  14.9k|}
asn1.c:asn1_encode_path:
 1212|  24.0k|{
 1213|  24.0k|	int r;
 1214|  24.0k| 	struct sc_asn1_entry asn1_path[5];
 1215|  24.0k|	sc_path_t tpath = *path;
 1216|       |
 1217|  24.0k|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1218|  24.0k|	sc_format_asn1_entry(asn1_path + 0, (void *) &tpath.value, (void *) &tpath.len, 1);
 1219|       |
 1220|  24.0k|	asn1_path[0].flags |= parent_flags;
 1221|  24.0k|	if (path->count > 0) {
  ------------------
  |  Branch (1221:6): [True: 4.98k, False: 19.0k]
  ------------------
 1222|  4.98k|		sc_format_asn1_entry(asn1_path + 1, (void *) &tpath.index, NULL, 1);
 1223|       |		sc_format_asn1_entry(asn1_path + 2, (void *) &tpath.count, NULL, 1);
 1224|  4.98k|	}
 1225|  24.0k|	r = asn1_encode(ctx, asn1_path, buf, bufsize, depth + 1);
 1226|  24.0k|	return r;
 1227|  24.0k|}
asn1.c:asn1_encode_p15_object:
 1435|  23.7k|{
 1436|  23.7k|	struct sc_pkcs15_object p15_obj = *obj->p15_obj;
 1437|  23.7k|	struct sc_asn1_entry    asn1_c_attr[6], asn1_p15_obj[5];
 1438|  23.7k|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1439|  23.7k|	size_t label_len = strlen(p15_obj.label);
 1440|  23.7k|	size_t flags_len;
 1441|  23.7k|	size_t access_mode_len;
 1442|  23.7k|	int r, ii;
 1443|       |
 1444|  23.7k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encode p15 obj(type:0x%X,access_mode:0x%X)", p15_obj.type, p15_obj.access_rules[0].access_mode);
  ------------------
  |  |   70|  23.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1445|  23.7k|	if (p15_obj.access_rules[0].access_mode)   {
  ------------------
  |  Branch (1445:6): [True: 175, False: 23.5k]
  ------------------
 1446|  1.57k|		for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|  1.57k|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1446:14): [True: 1.40k, False: 175]
  ------------------
 1447|  1.40k|			sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1448|  1.40k|			if (p15_obj.access_rules[ii].auth_id.len == 0)   {
  ------------------
  |  Branch (1448:8): [True: 1.35k, False: 44]
  ------------------
 1449|  1.35k|				asn1_ac_rule[ii][1].type = SC_ASN1_NULL;
  ------------------
  |  |  158|  1.35k|#define SC_ASN1_NULL                    5
  ------------------
 1450|  1.35k|				asn1_ac_rule[ii][1].tag = SC_ASN1_TAG_NULL;
  ------------------
  |  |  199|  1.35k|#define SC_ASN1_TAG_NULL		5
  ------------------
 1451|  1.35k|			}
 1452|  1.40k|		}
 1453|    175|		sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1454|    175|	}
 1455|       |
 1456|  23.7k|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1457|  23.7k|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1458|  23.7k|	if (label_len != 0)
  ------------------
  |  Branch (1458:6): [True: 22.1k, False: 1.56k]
  ------------------
 1459|  22.1k|		sc_format_asn1_entry(asn1_c_attr + 0, (void *) p15_obj.label, &label_len, 1);
 1460|  23.7k|	if (p15_obj.flags) {
  ------------------
  |  Branch (1460:6): [True: 7.87k, False: 15.8k]
  ------------------
 1461|  7.87k|		flags_len = sizeof(p15_obj.flags);
 1462|  7.87k|		sc_format_asn1_entry(asn1_c_attr + 1, (void *) &p15_obj.flags, &flags_len, 1);
 1463|  7.87k|	}
 1464|  23.7k|	if (p15_obj.auth_id.len)
  ------------------
  |  Branch (1464:6): [True: 3.70k, False: 20.0k]
  ------------------
 1465|  3.70k|		sc_format_asn1_entry(asn1_c_attr + 2, (void *) &p15_obj.auth_id, NULL, 1);
 1466|  23.7k|	if (p15_obj.user_consent)
  ------------------
  |  Branch (1466:6): [True: 73, False: 23.6k]
  ------------------
 1467|     73|		sc_format_asn1_entry(asn1_c_attr + 3, (void *) &p15_obj.user_consent, NULL, 1);
 1468|       |
 1469|  23.7k|	if (p15_obj.access_rules[0].access_mode)   {
  ------------------
  |  Branch (1469:6): [True: 175, False: 23.5k]
  ------------------
 1470|    381|		for (ii = 0; ii < SC_PKCS15_MAX_ACCESS_RULES && p15_obj.access_rules[ii].access_mode; ii++) {
  ------------------
  |  |   42|    762|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1470:16): [True: 380, False: 1]
  |  Branch (1470:51): [True: 206, False: 174]
  ------------------
 1471|    206|			access_mode_len = sizeof(p15_obj.access_rules[ii].access_mode);
 1472|    206|			sc_format_asn1_entry(asn1_ac_rule[ii] + 0, (void *) &p15_obj.access_rules[ii].access_mode, &access_mode_len, 1);
 1473|    206|			sc_format_asn1_entry(asn1_ac_rule[ii] + 1, (void *) &p15_obj.access_rules[ii].auth_id, NULL, 1);
 1474|    206|			sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 1);
 1475|    206|		}
 1476|    175|		sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 1);
 1477|    175|	}
 1478|       |
 1479|  23.7k|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 1);
 1480|  23.7k|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 1);
 1481|  23.7k|	if (obj->asn1_subclass_attr != NULL && obj->asn1_subclass_attr->name)
  ------------------
  |  Branch (1481:6): [True: 1.89k, False: 21.8k]
  |  Branch (1481:41): [True: 0, False: 1.89k]
  ------------------
 1482|      0|		sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 1);
 1483|  23.7k|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 1);
 1484|       |
 1485|  23.7k|	r = asn1_encode(ctx, asn1_p15_obj, buf, bufsize, depth + 1);
 1486|  23.7k|	return r;
 1487|  23.7k|}

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

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

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

sc_get_authentic_driver:
 2168|  15.0k|{
 2169|  15.0k|	return sc_get_driver();
 2170|  15.0k|}
card-authentic.c:sc_get_driver:
 2133|  15.0k|{
 2134|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2135|       |
 2136|  15.0k|	if (!iso_ops)
  ------------------
  |  Branch (2136:6): [True: 1, False: 15.0k]
  ------------------
 2137|      1|		iso_ops = iso_drv->ops;
 2138|       |
 2139|  15.0k|	authentic_ops = *iso_ops;
 2140|       |
 2141|  15.0k|	authentic_ops.match_card = authentic_match_card;
 2142|  15.0k|	authentic_ops.init = authentic_init;
 2143|  15.0k|	authentic_ops.finish = authentic_finish;
 2144|  15.0k|	authentic_ops.read_binary = authentic_read_binary;
 2145|  15.0k|	authentic_ops.write_binary = authentic_write_binary;
 2146|  15.0k|	authentic_ops.update_binary = authentic_update_binary;
 2147|  15.0k|	authentic_ops.erase_binary = authentic_erase_binary;
 2148|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2149|  15.0k|	authentic_ops.select_file = authentic_select_file;
 2150|       |	/* get_response: Untested */
 2151|  15.0k|	authentic_ops.get_challenge = authentic_get_challenge;
 2152|  15.0k|	authentic_ops.set_security_env = authentic_set_security_env;
 2153|       |	/* decipher: Untested */
 2154|  15.0k|	authentic_ops.decipher = authentic_decipher;
 2155|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2156|  15.0k|	authentic_ops.create_file = authentic_create_file;
 2157|  15.0k|	authentic_ops.delete_file = authentic_delete_file;
 2158|  15.0k|	authentic_ops.card_ctl = authentic_card_ctl;
 2159|  15.0k|	authentic_ops.process_fci = authentic_process_fci;
 2160|  15.0k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2161|  15.0k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2162|       |
 2163|  15.0k|	return &authentic_drv;
 2164|  15.0k|}
card-authentic.c:authentic_match_card:
  390|  10.3k|{
  391|  10.3k|	struct sc_context *ctx = card->ctx;
  392|  10.3k|	int i;
  393|       |
  394|  10.3k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  10.3k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  10.3k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|  10.3k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  396|  10.3k|	if (i < 0)   {
  ------------------
  |  Branch (396:6): [True: 10.1k, False: 271]
  ------------------
  397|  10.1k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  10.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  398|  10.1k|		return 0;
  399|  10.1k|	}
  400|       |
  401|    271|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   71|    271|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  402|    271|	return 1;
  403|  10.3k|}
card-authentic.c:authentic_init:
  442|    271|{
  443|    271|	struct sc_context *ctx = card->ctx;
  444|    271|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    271|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  445|       |
  446|    271|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    271|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    271|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    271|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    271|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 271]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  447|    271|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (447:11): [True: 271, False: 0]
  ------------------
  448|    271|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (448:7): [True: 271, False: 0]
  ------------------
  449|    271|			card->name = authentic_known_atrs[ii].name;
  450|    271|			card->flags = authentic_known_atrs[ii].flags;
  451|    271|			break;
  452|    271|		}
  453|    271|	}
  454|       |
  455|    271|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (455:6): [True: 0, False: 271]
  ------------------
  456|    271|		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|    271|	card->cla  = 0x00;
  459|    271|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  460|    271|	if (!card->drv_data)
  ------------------
  |  Branch (460:6): [True: 0, False: 271]
  ------------------
  461|    271|		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|    271|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (463:6): [True: 271, False: 0]
  ------------------
  464|    271|		rv = authentic_init_oberthur_authentic_3_2(card);
  465|       |
  466|    271|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    271|#define SC_SUCCESS				0
  ------------------
  |  Branch (466:6): [True: 202, False: 69]
  ------------------
  467|    202|		rv = authentic_get_serialnr(card, NULL);
  468|       |
  469|    271|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    271|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 31, False: 240]
  ------------------
  470|     31|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     31|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  471|       |
  472|       |	/* Free private data on error */
  473|    271|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    271|#define SC_SUCCESS				0
  ------------------
  |  Branch (473:6): [True: 31, False: 240]
  ------------------
  474|     31|		free(card->drv_data);
  475|     31|		card->drv_data = NULL;
  476|     31|	}
  477|    271|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    271|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    271|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    271|	int _ret = r; \
  |  |  |  |  155|    271|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 271, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    271|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31, False: 240]
  |  |  |  |  ------------------
  |  |  |  |  157|    271|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    271|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    271|	return _ret; \
  |  |  |  |  163|    271|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|    271|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  408|    271|{
  409|    271|	struct sc_context *ctx = card->ctx;
  410|    271|	unsigned int flags;
  411|    271|	int rv = 0;
  412|       |
  413|    271|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    271|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    271|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    271|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    271|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 271]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|       |
  415|    271|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    271|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    271|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |  102|    271|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    271|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  115|    271|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    271|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  120|    271|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  118|    271|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  119|    271|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    271|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  142|    271|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    271|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  143|    271|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    271|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  147|    271|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  416|       |
  417|    271|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    271|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  418|    271|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|    271|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  419|    271|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  564|    271|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  420|       |
  421|    271|#ifdef ENABLE_SM
  422|    271|	card->sm_ctx.ops.open = authentic_sm_open;
  423|    271|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  424|    271|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  425|    271|#endif
  426|       |
  427|    271|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  428|    271|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  174|    271|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    271|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    271|	int _ret = (r); \
  |  |  |  |  168|    271|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 183, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  169|    183|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    183|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    183|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    183|		return _ret; \
  |  |  |  |  172|    183|	} \
  |  |  |  |  173|    271|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|       |
  430|     88|	rv = authentic_select_mf(card, NULL);
  431|     88|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  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: 19, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  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|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|     69|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  434|     69|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  435|       |
  436|     69|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|     69|}
card-authentic.c:authentic_select_mf:
  544|     88|{
  545|     88|	struct sc_context *ctx = card->ctx;
  546|     88|	struct sc_path mfpath;
  547|     88|	int rv;
  548|       |
  549|     88|	struct sc_apdu apdu;
  550|     88|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  551|       |
  552|     88|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     88|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     88|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     88|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     88|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  553|       |
  554|     88|	sc_format_path("3F00", &mfpath);
  555|     88|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|     88|#define SC_PATH_TYPE_PATH		2
  ------------------
  556|       |
  557|     88|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|     88|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  558|       |
  559|     88|	apdu.resp = rbuf;
  560|     88|	apdu.resplen = sizeof(rbuf);
  561|       |
  562|     88|	rv = sc_transmit_apdu(card, &apdu);
  563|     88|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 87]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  564|     87|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  565|     87|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW 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: 6, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  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|     87|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|       |
  567|     81|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  568|     81|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  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|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|       |
  570|     69|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|     69|}
card-authentic.c:authentic_set_current_files:
  505|    456|{
  506|    456|	struct sc_context *ctx = card->ctx;
  507|    456|	struct sc_file *file = NULL;
  508|    456|	int rv;
  509|       |
  510|    456|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    456|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    456|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    456|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    456|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 456]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|    456|	if (resplen)   {
  ------------------
  |  Branch (511:6): [True: 234, False: 222]
  ------------------
  512|    234|		switch (resp[0]) {
  513|     40|		case 0x62:
  ------------------
  |  Branch (513:3): [True: 40, False: 194]
  ------------------
  514|    216|		case 0x6F:
  ------------------
  |  Branch (514:3): [True: 176, False: 58]
  ------------------
  515|    216|			file = sc_file_new();
  516|    216|			if (file == NULL)
  ------------------
  |  Branch (516:8): [True: 0, False: 216]
  ------------------
  517|    216|				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|    216|			if (path)
  ------------------
  |  Branch (518:8): [True: 216, False: 0]
  ------------------
  519|    216|				file->path = *path;
  520|       |
  521|    216|			rv = authentic_process_fci(card, file, resp, resplen);
  522|    216|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    216|#define SC_SUCCESS				0
  ------------------
  |  Branch (522:8): [True: 38, False: 178]
  ------------------
  523|     38|				sc_file_free(file);
  524|     38|				LOG_TEST_RET(ctx, rv, "cannot set 'current file': FCI process error");
  ------------------
  |  |  174|     38|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     38|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     38|	int _ret = (r); \
  |  |  |  |  168|     38|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     38|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     38|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     38|		return _ret; \
  |  |  |  |  172|     38|	} \
  |  |  |  |  173|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|     38|			}
  526|       |
  527|    178|			break;
  528|    178|		default:
  ------------------
  |  Branch (528:3): [True: 18, False: 216]
  ------------------
  529|     18|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  530|    234|		}
  531|       |
  532|    178|		if (file_out)
  ------------------
  |  Branch (532:7): [True: 95, False: 83]
  ------------------
  533|     95|			*file_out = file;
  534|     83|		else
  535|     83|			sc_file_free(file);
  536|    178|	}
  537|       |
  538|    400|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    400|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    400|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    400|	int _ret = r; \
  |  |  |  |  155|    400|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 400, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    400|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 400]
  |  |  |  |  ------------------
  |  |  |  |  157|    400|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    400|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    400|	return _ret; \
  |  |  |  |  163|    400|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    400|}
card-authentic.c:authentic_get_serialnr:
 1475|    296|{
 1476|    296|	struct sc_context *ctx = card->ctx;
 1477|    296|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1478|    296|	int rv;
 1479|       |
 1480|    296|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    296|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    296|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    296|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    296|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 296]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1481|    296|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1481:6): [True: 203, False: 93]
  ------------------
 1482|    203|		rv = authentic_get_cplc(card);
 1483|    203|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  174|    203|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    203|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    203|	int _ret = (r); \
  |  |  |  |  168|    203|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 171]
  |  |  |  |  ------------------
  |  |  |  |  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|    203|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 171]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1484|       |
 1485|    171|		card->serialnr.len = 4;
 1486|    171|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1487|       |
 1488|    171|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1489|    171|				card->serialnr.value[0], card->serialnr.value[1],
 1490|    171|				card->serialnr.value[2], card->serialnr.value[3]);
 1491|    171|	}
 1492|       |
 1493|    264|	if (serial)
  ------------------
  |  Branch (1493:6): [True: 93, False: 171]
  ------------------
 1494|     93|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1495|       |
 1496|    264|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    264|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    264|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    264|	int _ret = r; \
  |  |  |  |  155|    264|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 264, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    264|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 264]
  |  |  |  |  ------------------
  |  |  |  |  157|    264|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    264|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    264|	return _ret; \
  |  |  |  |  163|    264|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1497|    264|}
card-authentic.c:authentic_get_cplc:
  360|    203|{
  361|    203|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  362|    203|	struct sc_apdu apdu;
  363|    203|	int rv, ii;
  364|    203|	unsigned char p1, p2;
  365|       |
  366|    203|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  345|    203|#define SC_CPLC_TAG		0x9F7F
  ------------------
  367|    203|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  345|    203|#define SC_CPLC_TAG		0x9F7F
  ------------------
  368|    203|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    203|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  369|    206|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (369:12): [True: 205, False: 1]
  ------------------
  370|    205|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    205|#define SC_CPLC_DER_SIZE	45
  ------------------
  371|    205|		apdu.resplen = sizeof(prv_data->cplc.value);
  372|    205|		apdu.resp = prv_data->cplc.value;
  373|       |
  374|    205|		rv = sc_transmit_apdu(card, &apdu);
  375|    205|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    205|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    205|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    205|	int _ret = (r); \
  |  |  |  |  168|    205|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 201]
  |  |  |  |  ------------------
  |  |  |  |  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|    205|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 201]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    201|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  377|    201|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    201|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (377:7): [True: 198, False: 3]
  ------------------
  378|    198|			break;
  379|       |
  380|      3|		apdu.cla = 0x80;
  381|      3|	}
  382|    199|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    199|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    199|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    199|	int _ret = (r); \
  |  |  |  |  168|    199|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 171]
  |  |  |  |  ------------------
  |  |  |  |  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|    199|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 171]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  383|       |
  384|    171|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    171|#define SC_CPLC_DER_SIZE	45
  ------------------
  385|    171|	return SC_SUCCESS;
  ------------------
  |  |   28|    171|#define SC_SUCCESS				0
  ------------------
  386|    199|}
card-authentic.c:authentic_finish:
 1864|    240|{
 1865|    240|	struct sc_context *ctx = card->ctx;
 1866|       |
 1867|    240|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    240|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    240|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    240|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    240|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 240]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1868|       |
 1869|    240|#ifdef ENABLE_SM
 1870|    240|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1870:6): [True: 0, False: 240]
  ------------------
 1871|      0|		card->sm_ctx.ops.close(card);
 1872|    240|#endif
 1873|       |
 1874|    240|	if (card->drv_data)
  ------------------
  |  Branch (1874:6): [True: 240, False: 0]
  ------------------
 1875|    240|		free(card->drv_data);
 1876|    240|	card->drv_data = NULL;
 1877|    240|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    240|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    240|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    240|	int _ret = r; \
  |  |  |  |  155|    240|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    240|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 240]
  |  |  |  |  ------------------
  |  |  |  |  157|    240|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    240|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    240|	return _ret; \
  |  |  |  |  163|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1878|    240|}
card-authentic.c:authentic_read_binary:
  643|    160|{
  644|    160|	struct sc_context *ctx = card->ctx;
  645|    160|	struct sc_apdu apdu;
  646|    160|	size_t sz, rest, ret_count = 0;
  647|    160|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    160|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  648|       |
  649|    160|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    160|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    160|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    160|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    160|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 160]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|    160|	sc_log(ctx,
  ------------------
  |  |   71|    160|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  651|    160|	       "offs:%i,count:%"SC_FORMAT_LEN_SIZE_T"u,max_recv_size:%"SC_FORMAT_LEN_SIZE_T"u",
  652|    160|	       idx, count, card->max_recv_size);
  653|       |
  654|    160|	rest = count;
  655|  2.03k|	while(rest)   {
  ------------------
  |  Branch (655:8): [True: 1.88k, False: 149]
  ------------------
  656|  1.88k|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (656:8): [True: 1.73k, False: 150]
  ------------------
  657|  1.88k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|  1.88k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  658|  1.88k|		apdu.le = sz;
  659|  1.88k|		apdu.resplen = sz;
  660|  1.88k|		apdu.resp = (buf + ret_count);
  661|       |
  662|  1.88k|		rv = sc_transmit_apdu(card, &apdu);
  663|  1.88k|		if(!rv)
  ------------------
  |  Branch (663:6): [True: 1.87k, False: 11]
  ------------------
  664|  1.87k|			ret_count += apdu.resplen;
  665|     11|		else
  666|     11|			break;
  667|       |
  668|  1.87k|		idx += sz;
  669|  1.87k|		rest -= sz;
  670|  1.87k|	}
  671|       |
  672|    160|	if (rv)   {
  ------------------
  |  Branch (672:6): [True: 11, False: 149]
  ------------------
  673|     11|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "authentic_read_binary() failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  674|      0|		LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  675|      0|	}
  676|       |
  677|    149|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  678|    149|	if (!rv)
  ------------------
  |  Branch (678:6): [True: 100, False: 49]
  ------------------
  679|    100|		count = ret_count;
  680|       |
  681|    149|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    149|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    149|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    149|	int _ret = (r); \
  |  |  |  |  168|    149|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 49, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  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|    149|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  682|    100|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|    100|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    100|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    100|	int _ret = r; \
  |  |  |  |  155|    100|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  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|     94|	} else { \
  |  |  |  |  159|     94|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     94|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     94|	} \
  |  |  |  |  162|    100|	return _ret; \
  |  |  |  |  163|    100|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  683|    100|}
card-authentic.c:authentic_select_file:
  576|  1.30k|{
  577|  1.30k|	struct sc_context *ctx = card->ctx;
  578|  1.30k|	struct sc_apdu apdu;
  579|  1.30k|	struct sc_path lpath;
  580|  1.30k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  581|  1.30k|	size_t pathlen;
  582|  1.30k|	int rv;
  583|       |
  584|  1.30k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.30k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.30k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.30k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.30k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.30k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|  1.30k|	memcpy(&lpath, path, sizeof(struct sc_path));
  587|       |
  588|  1.30k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  2.60k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (588:6): [True: 751, False: 549]
  |  Branch (588:41): [True: 23, False: 728]
  ------------------
  589|     23|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     23|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  590|       |
  591|  1.30k|	pathlen = lpath.len;
  592|  1.30k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.30k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  593|       |
  594|  1.30k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (594:6): [True: 0, False: 1.30k]
  ------------------
  595|  1.30k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported card");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|       |
  597|  1.30k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  1.30k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (597:6): [True: 23, False: 1.27k]
  ------------------
  598|     23|		apdu.p1 = 0x00;
  599|     23|	}
  600|  1.27k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.27k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (600:11): [True: 728, False: 549]
  ------------------
  601|    728|		apdu.p1 = 0x08;
  602|    728|	}
  603|    549|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    549|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (603:11): [True: 0, False: 549]
  ------------------
  604|      0|		apdu.p1 = 0x09;
  605|      0|	}
  606|    549|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    549|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (606:11): [True: 549, False: 0]
  ------------------
  607|    549|		apdu.p1 = 4;
  608|    549|	}
  609|      0|	else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (609:11): [True: 0, False: 0]
  ------------------
  610|      0|		apdu.p1 = 0x03;
  611|      0|		pathlen = 0;
  612|      0|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  613|      0|	}
  614|      0|	else   {
  615|      0|		sc_log(ctx, "Invalid PATH type: 0x%X", lpath.type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  616|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "authentic_select_file() invalid PATH type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|      0|	}
  618|       |
  619|  1.30k|	apdu.lc = pathlen;
  620|  1.30k|	apdu.data = lpath.value;
  621|  1.30k|	apdu.datalen = pathlen;
  622|       |
  623|  1.30k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  2.60k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (623:6): [True: 1.30k, False: 0]
  |  Branch (623:42): [True: 0, False: 0]
  ------------------
  624|  1.30k|		apdu.resp = rbuf;
  625|  1.30k|		apdu.resplen = sizeof(rbuf);
  626|  1.30k|		apdu.le = 256;
  627|  1.30k|	}
  628|       |
  629|  1.30k|	rv = sc_transmit_apdu(card, &apdu);
  630|  1.30k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.30k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.30k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.30k|	int _ret = (r); \
  |  |  |  |  168|  1.30k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 1.29k]
  |  |  |  |  ------------------
  |  |  |  |  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.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.29k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|  1.29k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  632|  1.29k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  1.29k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.29k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.29k|	int _ret = (r); \
  |  |  |  |  168|  1.29k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 915, False: 375]
  |  |  |  |  ------------------
  |  |  |  |  169|    915|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    915|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    915|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    915|		return _ret; \
  |  |  |  |  172|    915|	} \
  |  |  |  |  173|  1.29k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 375]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|       |
  634|    375|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  635|    375|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    375|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    375|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    375|	int _ret = (r); \
  |  |  |  |  168|    375|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 44, False: 331]
  |  |  |  |  ------------------
  |  |  |  |  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|    375|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 331]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    331|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    331|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    331|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    331|	int _ret = r; \
  |  |  |  |  155|    331|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 331, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    331|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 331]
  |  |  |  |  ------------------
  |  |  |  |  157|    331|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    331|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    331|	return _ret; \
  |  |  |  |  163|    331|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|    331|}
card-authentic.c:authentic_card_ctl:
 1753|     94|{
 1754|     94|	struct sc_context *ctx = card->ctx;
 1755|     94|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1756|       |
 1757|     94|	switch (cmd) {
  ------------------
  |  Branch (1757:10): [True: 94, False: 0]
  ------------------
 1758|     94|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1758:2): [True: 94, False: 0]
  ------------------
 1759|     94|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1760|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1760:2): [True: 0, False: 94]
  ------------------
 1761|      0|		sc_log(ctx, "CARDCTL SDO_CREATE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1762|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1763|      0|	case SC_CARDCTL_AUTHENTIC_SDO_DELETE:
  ------------------
  |  Branch (1763:2): [True: 0, False: 94]
  ------------------
 1764|      0|		sc_log(ctx, "CARDCTL SDO_DELETE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1765|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1766|      0|	case SC_CARDCTL_AUTHENTIC_SDO_STORE:
  ------------------
  |  Branch (1766:2): [True: 0, False: 94]
  ------------------
 1767|      0|		sc_log(ctx, "CARDCTL SDO_STORE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1768|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1769|      0|	case SC_CARDCTL_AUTHENTIC_SDO_GENERATE:
  ------------------
  |  Branch (1769:2): [True: 0, False: 94]
  ------------------
 1770|      0|		sc_log(ctx, "CARDCTL SDO_GENERATE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1771|      0|		return authentic_manage_sdo_generate(card, (struct sc_authentic_sdo *) ptr);
 1772|     94|	}
 1773|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1774|     94|}
card-authentic.c:authentic_get_tagged_data:
  177|    123|{
  178|    123|	size_t size_len, tag_len, offs, size;
  179|    123|	int rv;
  180|    123|	unsigned tag;
  181|       |
  182|    123|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 123]
  |  Branch (182:14): [True: 0, False: 123]
  ------------------
  183|    123|		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|    850|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 803, False: 47]
  ------------------
  186|    803|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 67, False: 736]
  |  Branch (186:33): [True: 91, False: 645]
  ------------------
  187|    158|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 8, False: 150]
  ------------------
  188|    158|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    150|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|    150|			tag_len = 2;
  191|    150|		}
  192|    645|		else   {
  193|    645|			tag = *(in + offs);
  194|    645|			tag_len = 1;
  195|    645|		}
  196|       |
  197|    795|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 14, False: 781]
  ------------------
  198|    795|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|    781|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|    781|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|    781|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    781|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    781|	int _ret = (r); \
  |  |  |  |  168|    781|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 773]
  |  |  |  |  ------------------
  |  |  |  |  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|    781|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 773]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|    773|		size_len = rv;
  203|       |
  204|    773|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 46, False: 727]
  ------------------
  205|     46|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 2, False: 44]
  ------------------
  206|     46|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|     44|			*out = in + offs + tag_len + size_len;
  209|     44|			*out_len = size;
  210|       |
  211|     44|			return SC_SUCCESS;
  ------------------
  |  |   28|     44|#define SC_SUCCESS				0
  ------------------
  212|     46|		}
  213|       |
  214|    727|		offs += tag_len + size_len + size;
  215|    727|	}
  216|       |
  217|     47|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     47|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    123|}
card-authentic.c:authentic_parse_size:
  149|    781|{
  150|    781|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 781]
  |  Branch (150:13): [True: 0, False: 781]
  |  Branch (150:21): [True: 0, False: 781]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|    781|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 615, False: 166]
  ------------------
  154|    615|		*out = *in;
  155|    615|		return 1;
  156|    615|	}
  157|    166|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 83, False: 83]
  ------------------
  158|     83|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 1, False: 82]
  ------------------
  159|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|     82|		*out = *(in + 1);
  161|     82|		return 2;
  162|     83|	}
  163|     83|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 77, False: 6]
  ------------------
  164|     77|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 1, False: 76]
  ------------------
  165|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|     76|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|     76|		return 3;
  168|     77|	}
  169|       |
  170|      6|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|    781|}
card-authentic.c:authentic_process_fci:
  775|    216|{
  776|    216|	struct sc_context *ctx = card->ctx;
  777|    216|	size_t taglen;
  778|    216|	int rv;
  779|    216|	unsigned ii;
  780|    216|	const unsigned char *tag = NULL;
  781|    216|	unsigned char ops_DF[8] = {
  782|    216|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    216|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    216|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    216|#define SC_AC_OP_CRYPTO			7
  ------------------
  783|    216|	};
  784|    216|	unsigned char ops_EF[8] = {
  785|    216|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    216|#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|    216|#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|    216|#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|    216|#define SC_AC_OP_RESIZE			25
  ------------------
  786|    216|	};
  787|       |
  788|    216|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    216|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    216|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    216|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    216|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 216]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|       |
  790|    216|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  791|    216|	if (tag != NULL) {
  ------------------
  |  Branch (791:6): [True: 171, False: 45]
  ------------------
  792|    171|		sc_log(ctx, "  FCP length %"SC_FORMAT_LEN_SIZE_T"u", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  793|    171|		buf = tag;
  794|    171|		buflen = taglen;
  795|    171|	}
  796|       |
  797|    216|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  798|    216|	if (tag != NULL) {
  ------------------
  |  Branch (798:6): [True: 10, False: 206]
  ------------------
  799|     10|		sc_log(ctx, "  FCP length %"SC_FORMAT_LEN_SIZE_T"u", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  800|     10|		buf = tag;
  801|     10|		buflen = taglen;
  802|     10|	}
  803|       |
  804|    216|	rv = iso_ops->process_fci(card, file, buf, buflen);
  805|    216|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  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: 0, False: 216]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    216|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 216]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  806|       |
  807|    216|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (807:6): [True: 109, False: 107]
  ------------------
  808|    109|		sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
  ------------------
  |  |  129|    109|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    109|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|    109|		sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  810|    109|		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  118|    218|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|     88|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (810:7): [True: 21, False: 88]
  |  Branch (810:50): [True: 50, False: 38]
  ------------------
  811|     71|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     71|#define SC_FILE_TYPE_DF			0x04
  ------------------
  812|     71|		}
  813|     38|		else   {
  814|     38|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     38|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     38|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     38|	int _ret = (r); \
  |  |  |  |  168|     38|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     38|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     38|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     38|		return _ret; \
  |  |  |  |  172|     38|	} \
  |  |  |  |  173|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|     38|		}
  816|    109|	}
  817|       |
  818|    178|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    178|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    178|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  819|    634|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (819:15): [True: 465, False: 169]
  |  Branch (819:46): [True: 456, False: 9]
  ------------------
  820|    456|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    456|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (820:22): [True: 78, False: 378]
  ------------------
  821|    456|		unsigned char acl = *(file->sec_attr + ii*2);
  822|    456|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  823|    456|		unsigned sc = acl * 0x100 + cred_id;
  824|       |
  825|    456|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    456|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  826|    456|		if (op == 0xFF)
  ------------------
  |  Branch (826:7): [True: 121, False: 335]
  ------------------
  827|    121|			;
  828|    335|		else if (!acl && !cred_id)
  ------------------
  |  Branch (828:12): [True: 107, False: 228]
  |  Branch (828:20): [True: 24, False: 83]
  ------------------
  829|     24|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     24|#define SC_AC_NONE			0x00000000
  ------------------
  830|    311|		else if (acl == 0xFF)
  ------------------
  |  Branch (830:12): [True: 42, False: 269]
  ------------------
  831|     42|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     42|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    269|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    269|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (832:12): [True: 97, False: 172]
  ------------------
  833|     97|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|     97|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  834|    172|		else if (cred_id)
  ------------------
  |  Branch (834:12): [True: 130, False: 42]
  ------------------
  835|    130|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|    130|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  836|     42|		else
  837|     42|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     42|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  838|    456|	}
  839|       |
  840|    178|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    178|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    178|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    178|	int _ret = r; \
  |  |  |  |  155|    178|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 178, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    178|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 178]
  |  |  |  |  ------------------
  |  |  |  |  157|    178|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    178|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    178|	return _ret; \
  |  |  |  |  163|    178|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|    178|}
card-authentic.c:authentic_pin_cmd:
 1443|     94|{
 1444|     94|	struct sc_context *ctx = card->ctx;
 1445|     94|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     94|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1446|       |
 1447|     94|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     94|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     94|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     94|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     94|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1448|     94|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1449|     94|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1450|     94|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1451|       |
 1452|     94|	switch (data->cmd)   {
 1453|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1453:2): [True: 0, False: 94]
  ------------------
 1454|      0|		rv = authentic_pin_verify(card, data);
 1455|      0|		break;
 1456|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1456:2): [True: 0, False: 94]
  ------------------
 1457|      0|		rv = authentic_pin_change(card, data);
 1458|      0|		break;
 1459|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1459:2): [True: 0, False: 94]
  ------------------
 1460|      0|		rv = authentic_pin_reset(card, data);
 1461|      0|		break;
 1462|     94|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|     94|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1462:2): [True: 94, False: 0]
  ------------------
 1463|     94|		rv = authentic_pin_get_policy(card, data, NULL);
 1464|     94|		break;
 1465|      0|	default:
  ------------------
  |  Branch (1465:2): [True: 0, False: 94]
  ------------------
 1466|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN command");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1467|     94|	}
 1468|       |
 1469|     94|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|     91|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 91, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1470|     94|}
card-authentic.c:authentic_pin_get_policy:
 1305|     94|{
 1306|     94|	struct sc_context *ctx = card->ctx;
 1307|     94|	struct sc_apdu apdu;
 1308|     94|	unsigned char rbuf[0x100];
 1309|     94|	int ii, rv;
 1310|       |
 1311|     94|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     94|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     94|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     94|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     94|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1312|     94|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1313|       |
 1314|     94|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|     94|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1315|     95|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1315:12): [True: 95, False: 0]
  ------------------
 1316|     95|		apdu.le = sizeof(rbuf);
 1317|     95|		apdu.resp = rbuf;
 1318|     95|		apdu.resplen = sizeof(rbuf);
 1319|       |
 1320|     95|		rv = sc_transmit_apdu(card, &apdu);
 1321|     95|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     95|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     95|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     95|	int _ret = (r); \
  |  |  |  |  168|     95|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     95|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1322|     94|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1323|       |
 1324|     94|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|     94|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1324:7): [True: 93, False: 1]
  ------------------
 1325|     93|			break;
 1326|       |
 1327|      1|		apdu.cla = 0x80;
 1328|      1|	}
 1329|     93|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  174|     93|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     93|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     93|	int _ret = (r); \
  |  |  |  |  168|     93|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 86]
  |  |  |  |  ------------------
  |  |  |  |  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|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 86]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1330|       |
 1331|     86|	data->pin1.tries_left = -1;
 1332|       |
 1333|     86|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1334|     86|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  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: 83, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     83|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     83|		return _ret; \
  |  |  |  |  172|     83|	} \
  |  |  |  |  173|     86|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|       |
 1336|      3|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|      3|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1337|      3|	data->pin1.offset = 5;
 1338|      3|	data->pin1.pad_char = 0xFF;
 1339|      3|	data->pin1.pad_length = data->pin1.max_length;
 1340|      3|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      3|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1341|       |
 1342|      3|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|      3|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1343|       |
 1344|      3|	sc_log(ctx,
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1345|      3|	       "PIN policy: size max/min/pad %"SC_FORMAT_LEN_SIZE_T"u/%"SC_FORMAT_LEN_SIZE_T"u/%"SC_FORMAT_LEN_SIZE_T"u, tries max/left %i/%i",
 1346|      3|	       data->pin1.max_length, data->pin1.min_length,
 1347|      3|	       data->pin1.pad_length, data->pin1.max_tries,
 1348|      3|	       data->pin1.tries_left);
 1349|       |
 1350|      3|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1351|      3|}
card-authentic.c:authentic_parse_credential_data:
  286|     86|{
  287|     86|	unsigned char *data;
  288|     86|	size_t data_len;
  289|     86|	int rv, ii;
  290|     86|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|     86|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|     86|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|     86|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  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: 68, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  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|     86|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|     18|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|     18|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|     18|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  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: 4, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|     14|	pin_cmd->pin1.max_tries = *data;
  298|       |
  299|     14|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|     14|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  300|     14|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|     11|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (301:6): [True: 10, False: 1]
  |  Branch (301:22): [True: 3, False: 7]
  ------------------
  302|      3|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      3|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  303|      8|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (303:11): [True: 7, False: 1]
  |  Branch (303:27): [True: 6, False: 1]
  |  Branch (303:41): [True: 1, False: 5]
  ------------------
  304|      1|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|      1|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  305|      7|	else
  306|      7|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Parse optional ACLs when requested */
  309|      4|	if (acls) {
  ------------------
  |  Branch (309:6): [True: 0, False: 4]
  ------------------
  310|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_ACLS, &data, &data_len);
  ------------------
  |  |   75|      0|#define AUTHENTIC_TAG_DOCP_ACLS			0x86
  ------------------
  311|      0|		LOG_TEST_RET(ctx, rv, "failed to get ACLs");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  312|      0|		sc_log(ctx, "data_len:%"SC_FORMAT_LEN_SIZE_T"u", data_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  313|      0|		if (data_len == 10)   {
  ------------------
  |  Branch (313:7): [True: 0, False: 0]
  ------------------
  314|      0|			for (ii=0; ii<5; ii++)   {
  ------------------
  |  Branch (314:15): [True: 0, False: 0]
  ------------------
  315|      0|				unsigned char acl = *(data + ii*2);
  316|      0|				unsigned char cred_id = *(data + ii*2 + 1);
  317|      0|				unsigned sc = acl * 0x100 + cred_id;
  318|       |
  319|      0|				sc_log(ctx, "%i: SC:%X", ii, sc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|      0|				if (!sc)
  ------------------
  |  Branch (320:9): [True: 0, False: 0]
  ------------------
  321|      0|					continue;
  322|       |
  323|      0|				if (acl & AUTHENTIC_AC_SM_MASK)   {
  ------------------
  |  |  119|      0|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (323:9): [True: 0, False: 0]
  ------------------
  324|      0|					acls[ii].method = SC_AC_SCB;
  ------------------
  |  |  157|      0|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  325|      0|					acls[ii].key_ref = sc;
  326|      0|				}
  327|      0|				else if (acl!=0xFF && cred_id)   {
  ------------------
  |  Branch (327:14): [True: 0, False: 0]
  |  Branch (327:27): [True: 0, False: 0]
  ------------------
  328|      0|					sc_log(ctx, "%i: ACL(method:SC_AC_CHV,id:%i)", ii, cred_id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  329|      0|					acls[ii].method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  330|      0|					acls[ii].key_ref = cred_id;
  331|      0|				}
  332|      0|				else   {
  333|      0|					acls[ii].method = SC_AC_NEVER;
  ------------------
  |  |  163|      0|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  334|      0|					acls[ii].key_ref = 0;
  335|      0|				}
  336|      0|			}
  337|      0|		}
  338|      0|	}
  339|       |
  340|      4|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|      4|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  341|      4|	if (!rv)   {
  ------------------
  |  Branch (341:6): [True: 1, False: 3]
  ------------------
  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|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  355|      4|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1882|    803|{
 1883|    803|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    803|#define SC_SUCCESS				0
  ------------------
 1884|       |
 1885|    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]
  |  |  ------------------
  ------------------
 1886|       |
 1887|    803|	if (was_reset > 0
  ------------------
  |  Branch (1887:6): [True: 0, False: 803]
  ------------------
 1888|      0|			&& card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
  ------------------
  |  Branch (1888:7): [True: 0, False: 0]
  ------------------
 1889|      0|		r = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
 1890|      0|	}
 1891|       |
 1892|    803|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1893|    803|}

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

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

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

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

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

coolkey_get_attribute_data:
  602|  2.66k|{
  603|       |	/* handle the V0 objects first */
  604|  2.66k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  2.66k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (604:6): [True: 1.35k, False: 1.31k]
  ------------------
  605|  1.35k|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  606|  1.35k|	}
  607|       |
  608|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  609|  1.31k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  1.31k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (609:6): [True: 0, False: 1.31k]
  ------------------
  610|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  611|      0|	}
  612|       |
  613|  1.31k|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  614|       |
  615|  1.31k|}
coolkey_compare_id:
  757|   114k|{
  758|   114k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (758:6): [True: 0, False: 114k]
  |  Branch (758:19): [True: 0, False: 114k]
  ------------------
  759|      0|		return 1;
  760|   114k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  761|   114k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  762|   114k|}
coolkey_list_meter:
  765|  6.45k|size_t coolkey_list_meter(const void *el) {
  766|  6.45k|	return sizeof(sc_cardctl_coolkey_object_t);
  767|  6.45k|}
coolkey_fill_object:
 1372|  30.3k|{
 1373|  30.3k|	int r;
 1374|  30.3k|	size_t buf_len = obj->length;
 1375|  30.3k|	u8 *new_obj_data = NULL;
 1376|  30.3k|	sc_cardctl_coolkey_object_t *obj_entry;
 1377|  30.3k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  30.3k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1378|       |
 1379|  30.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  30.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  30.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  30.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  30.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 30.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1380|       |
 1381|  30.3k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1381:6): [True: 0, False: 30.3k]
  ------------------
 1382|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1383|      0|	}
 1384|  30.3k|	new_obj_data = malloc(buf_len);
 1385|  30.3k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1385:6): [True: 0, False: 30.3k]
  ------------------
 1386|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1387|      0|	}
 1388|  30.3k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1389|  30.3k|				priv->nonce, sizeof(priv->nonce));
 1390|  30.3k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1390:6): [True: 28.2k, False: 2.15k]
  ------------------
 1391|  28.2k|		free(new_obj_data);
 1392|  28.2k|		if (r < 0) {
  ------------------
  |  Branch (1392:7): [True: 28.2k, False: 0]
  ------------------
 1393|  28.2k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  28.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  28.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  28.2k|	int _ret = r; \
  |  |  |  |  155|  28.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  28.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|  28.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  28.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  28.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|  28.2k|	return _ret; \
  |  |  |  |  163|  28.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1394|  28.2k|		}
 1395|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_CORRUPTED_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1396|      0|	}
 1397|  2.15k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1398|  2.15k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1398:6): [True: 0, False: 2.15k]
  ------------------
 1399|      0|		free(new_obj_data);
 1400|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1401|      0|	}
 1402|  2.15k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1402:6): [True: 0, False: 2.15k]
  ------------------
 1403|      0|		free(new_obj_data);
 1404|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1405|      0|	}
 1406|       |	/* Make sure we will not go over the allocated limits in the other
 1407|       |	 * objects if they somehow got different lengths in matching objects */
 1408|  2.15k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1408:6): [True: 0, False: 2.15k]
  ------------------
 1409|      0|		free(new_obj_data);
 1410|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1411|      0|	}
 1412|  2.15k|	obj_entry->data = new_obj_data;
 1413|  2.15k|	obj->data = new_obj_data;
 1414|  2.15k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.15k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.15k|	int _ret = r; \
  |  |  |  |  155|  2.15k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.15k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.15k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.15k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.15k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.15k|	return _ret; \
  |  |  |  |  163|  2.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1415|  2.15k|}
coolkey_find_object_by_template:
 1504|  1.36k|{
 1505|  1.36k|	list_t *list;
 1506|  1.36k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1507|  1.36k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.36k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1508|  1.36k|	int i, r;
 1509|  1.36k|	unsigned int tmp_pos = (unsigned int) -1;
 1510|       |
 1511|  1.36k|	list = &priv->objects_list;
 1512|  1.36k|	if (list->iter_active) {
  ------------------
  |  Branch (1512:6): [True: 1.36k, False: 0]
  ------------------
 1513|       |		/* workaround missing functionality of second iterator */
 1514|  1.36k|		tmp_pos = list->iter_pos;
 1515|  1.36k|		list_iterator_stop(list);
 1516|  1.36k|	}
 1517|       |
 1518|  1.36k|	list_iterator_start(list);
 1519|  27.9k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1519:9): [True: 27.0k, False: 888]
  ------------------
 1520|  27.0k|		sc_cardctl_coolkey_attribute_t attribute;
 1521|  27.0k|		current = list_iterator_next(list);
 1522|  27.0k|		attribute.object = current;
 1523|       |
 1524|  28.5k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1524:13): [True: 28.0k, False: 479]
  ------------------
 1525|  28.0k|			attribute.attribute_type = template[i].attribute_type;
 1526|  28.0k|			r = coolkey_find_attribute(card, &attribute);
 1527|  28.0k|			if (r < 0) {
  ------------------
  |  Branch (1527:8): [True: 15.7k, False: 12.3k]
  ------------------
 1528|  15.7k|				break;
 1529|  15.7k|			}
 1530|  12.3k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1530:8): [True: 543, False: 11.7k]
  ------------------
 1531|    543|				break;
 1532|    543|			}
 1533|  11.7k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1533:8): [True: 278, False: 11.4k]
  ------------------
 1534|    278|				break;
 1535|    278|			}
 1536|  11.4k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1536:8): [True: 10.0k, False: 1.44k]
  ------------------
 1537|  11.4k|							attribute.attribute_length) != 0) {
 1538|  10.0k|				break;
 1539|  10.0k|			}
 1540|  11.4k|		}
 1541|       |		/* just return the first one */
 1542|  27.0k|		if (i == count) {
  ------------------
  |  Branch (1542:7): [True: 479, False: 26.6k]
  ------------------
 1543|    479|			rv = current;
 1544|    479|			break;
 1545|    479|		}
 1546|  27.0k|	}
 1547|       |
 1548|  1.36k|	list_iterator_stop(list);
 1549|  1.36k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1549:6): [True: 1.36k, False: 0]
  ------------------
 1550|       |		/* workaround missing functionality of second iterator */
 1551|  1.36k|		list_iterator_start(list);
 1552|  15.5k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1552:10): [True: 15.4k, False: 99]
  |  Branch (1552:41): [True: 14.1k, False: 1.26k]
  ------------------
 1553|  14.1k|			(void) list_iterator_next(list);
 1554|  1.36k|	}
 1555|  1.36k|	return rv;
 1556|  1.36k|}
sc_get_coolkey_driver:
 2476|  15.0k|{
 2477|  15.0k|	return sc_get_driver();
 2478|  15.0k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  517|  1.35k|{
  518|       |	/* we need to manually detect types CK_ULONG */
  519|  1.35k|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|  1.35k|#define COOLKEY_V0_OBJECT 0
  ------------------
  520|  1.35k|	int r;
  521|  1.35k|	size_t len;
  522|       |
  523|  1.35k|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1048|  1.35k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  524|  1.35k|	attr_out->attribute_length = 0;
  525|  1.35k|	attr_out->attribute_value = NULL;
  526|       |
  527|  1.35k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  528|  1.35k|	if (r < 0) {
  ------------------
  |  Branch (528:6): [True: 0, False: 1.35k]
  ------------------
  529|      0|		return r;
  530|      0|	}
  531|  1.35k|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (531:6): [True: 19, False: 1.33k]
  ------------------
  532|     19|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     19|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  533|     19|	}
  534|  1.33k|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|  1.33k|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|    685|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (534:6): [True: 649, False: 685]
  |  Branch (534:34): [True: 0, False: 685]
  ------------------
  535|    685|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|    685|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (535:14): [True: 6, False: 679]
  ------------------
  536|    655|		if (len != 4) {
  ------------------
  |  Branch (536:7): [True: 48, False: 607]
  ------------------
  537|     48|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     48|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  538|     48|		}
  539|    607|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|    607|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  540|    607|	}
  541|       |	/* return the length and the data */
  542|  1.28k|	attr_out->attribute_length = len;
  543|  1.28k|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  544|  1.28k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.28k|#define SC_SUCCESS				0
  ------------------
  545|  1.33k|}
card-coolkey.c:coolkey_get_attribute_type:
  410|  74.5k|{
  411|  74.5k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  412|       |
  413|  74.5k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  414|  74.5k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  350|  28.8k|{
  351|  28.8k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  352|       |	/* don't reference beyond our buffer */
  353|  28.8k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (353:6): [True: 115, False: 28.7k]
  ------------------
  354|    115|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    115|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  355|    115|	}
  356|  28.7k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  357|  28.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  28.7k|#define SC_SUCCESS				0
  ------------------
  358|  28.8k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  552|  1.31k|{
  553|  1.31k|	int r;
  554|  1.31k|	size_t len;
  555|  1.31k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  556|       |
  557|  1.31k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (557:6): [True: 34, False: 1.27k]
  ------------------
  558|     34|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     34|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  559|     34|	}
  560|       |
  561|       |	/* we must have type V1. Process according to data type */
  562|  1.27k|	switch (attribute_head->attribute_data_type) {
  563|       |	/* ULONG has implied length of 4 */
  564|    204|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|    204|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (564:2): [True: 204, False: 1.07k]
  ------------------
  565|    204|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (565:7): [True: 34, False: 170]
  ------------------
  566|     34|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     34|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  567|     34|		}
  568|    170|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|    170|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  569|    170|		attr_out->attribute_length = 4;
  570|    170|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  571|    170|		return SC_SUCCESS;
  ------------------
  |  |   28|    170|#define SC_SUCCESS				0
  ------------------
  572|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  573|       |	/* return type STRING for BOOLS */
  574|    206|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|    206|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (574:2): [True: 206, False: 1.07k]
  ------------------
  575|    206|		attr_out->attribute_length = 1;
  576|    206|		attr_out->attribute_value =  &coolkey_static_false;
  577|    206|		return SC_SUCCESS;
  ------------------
  |  |   28|    206|#define SC_SUCCESS				0
  ------------------
  578|    338|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|    338|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (578:2): [True: 338, False: 941]
  ------------------
  579|    338|		attr_out->attribute_length = 1;
  580|    338|		attr_out->attribute_value =  &coolkey_static_true;
  581|    338|		return SC_SUCCESS;
  ------------------
  |  |   28|    338|#define SC_SUCCESS				0
  ------------------
  582|       |	/* string type has encoded length */
  583|    441|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|    441|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (583:2): [True: 441, False: 838]
  ------------------
  584|    441|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  585|    441|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|    441|#define SC_SUCCESS				0
  ------------------
  |  Branch (585:7): [True: 35, False: 406]
  ------------------
  586|     35|			return r;
  587|     35|		}
  588|    406|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (588:7): [True: 107, False: 299]
  ------------------
  589|    107|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    107|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  590|    107|		}
  591|    299|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  592|    299|		attr_out->attribute_length = len;
  593|    299|		return SC_SUCCESS;
  ------------------
  |  |   28|    299|#define SC_SUCCESS				0
  ------------------
  594|     90|	default:
  ------------------
  |  Branch (594:2): [True: 90, False: 1.18k]
  ------------------
  595|     90|		break;
  596|  1.27k|	}
  597|     90|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     90|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  598|  1.27k|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  313|   272k|{
  314|   272k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  315|       |
  316|   272k|	*len = 0;
  317|       |	/* don't reference beyond our buffer */
  318|   272k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (318:6): [True: 210k, False: 62.1k]
  ------------------
  319|   210k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   210k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  320|   210k|	}
  321|  62.1k|	switch (attribute_head->attribute_data_type) {
  322|  22.2k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  22.2k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (322:2): [True: 22.2k, False: 39.9k]
  ------------------
  323|  22.2k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (323:7): [True: 312, False: 21.9k]
  ------------------
  324|    312|			break;
  325|    312|		}
  326|  21.9k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  327|  21.9k|		if (encoded_len) {
  ------------------
  |  Branch (327:7): [True: 21.5k, False: 406]
  ------------------
  328|  21.5k|			*len += 2;
  329|  21.5k|		}
  330|  21.9k|		return SC_SUCCESS;
  ------------------
  |  |   28|  21.9k|#define SC_SUCCESS				0
  ------------------
  331|  17.8k|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|  17.8k|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (331:2): [True: 17.8k, False: 44.3k]
  ------------------
  332|  29.7k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|  29.7k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (332:2): [True: 11.8k, False: 50.2k]
  ------------------
  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|  29.7k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (335:10): [True: 29.7k, False: 0]
  ------------------
  336|  29.7k|		return SC_SUCCESS;
  ------------------
  |  |   28|  29.7k|#define SC_SUCCESS				0
  ------------------
  337|      0|		break;
  338|  2.36k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|  2.36k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (338:2): [True: 2.36k, False: 59.8k]
  ------------------
  339|  2.36k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  340|  2.36k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.36k|#define SC_SUCCESS				0
  ------------------
  341|  7.86k|	default:
  ------------------
  |  Branch (341:2): [True: 7.86k, False: 54.3k]
  ------------------
  342|  7.86k|		break;
  343|  62.1k|	}
  344|  8.17k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  8.17k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  345|  62.1k|}
card-coolkey.c:coolkey_read_object:
 1100|  30.5k|{
 1101|  30.5k|	coolkey_read_object_param_t params;
 1102|  30.5k|	u8 *out_ptr;
 1103|  30.5k|	size_t left = 0;
 1104|  30.5k|	size_t len;
 1105|  30.5k|	int r;
 1106|       |
 1107|  30.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  30.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  30.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  30.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 30.5k]
  |  |  ------------------
  ------------------
 1108|       |
 1109|  30.5k|	ulong2bebytes(&params.object_id[0], object_id);
 1110|       |
 1111|  30.5k|	out_ptr = out_buf;
 1112|  30.5k|	left = out_len;
 1113|  33.9k|	do {
 1114|  33.9k|		ulong2bebytes(&params.offset[0], offset);
 1115|  33.9k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   70|  33.9k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 27.3k, False: 6.64k]
  |  |  ------------------
  ------------------
 1116|  33.9k|		len = left;
 1117|  33.9k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   72|  33.9k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   88|  33.9k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1118|  33.9k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1119|  33.9k|		if (r < 0) {
  ------------------
  |  Branch (1119:7): [True: 27.3k, False: 6.57k]
  ------------------
 1120|  27.3k|			goto fail;
 1121|  27.3k|		}
 1122|       |		/* sanity check to make sure we don't overflow left */
 1123|  6.57k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1123:7): [True: 357, False: 6.21k]
  |  Branch (1123:23): [True: 562, False: 5.65k]
  ------------------
 1124|    919|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    919|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1125|    919|			goto fail;
 1126|    919|		}
 1127|  5.65k|		out_ptr += len;
 1128|  5.65k|		offset += len;
 1129|  5.65k|		left -= len;
 1130|  5.65k|	} while (left != 0);
  ------------------
  |  Branch (1130:11): [True: 3.43k, False: 2.21k]
  ------------------
 1131|       |
 1132|  2.21k|	return (int)out_len;
 1133|       |
 1134|  28.3k|fail:
 1135|  28.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  28.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  28.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  28.3k|	int _ret = r; \
  |  |  |  |  155|  28.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  28.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|  28.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  28.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  28.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|  28.3k|	return _ret; \
  |  |  |  |  163|  28.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1136|  28.3k|}
card-coolkey.c:coolkey_apdu_io:
  912|  54.6k|{
  913|  54.6k|	int r;
  914|  54.6k|	sc_apdu_t apdu;
  915|  54.6k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  916|  54.6k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  917|  54.6k|	u8 *rbuf;
  918|  54.6k|	size_t rbuflen;
  919|  54.6k|	int cse = 0;
  920|       |
  921|       |
  922|  54.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  54.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  54.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  54.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 54.6k]
  |  |  ------------------
  ------------------
  923|       |
  924|  54.6k|	sc_log(card->ctx,
  ------------------
  |  |   71|  54.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|  54.6k|		 "%02x %02x %02x %"SC_FORMAT_LEN_SIZE_T"u : %"SC_FORMAT_LEN_SIZE_T"u %"SC_FORMAT_LEN_SIZE_T"u\n",
  926|  54.6k|		 ins, p1, p2, sendbuflen, card->max_send_size,
  927|  54.6k|		 card->max_recv_size);
  928|       |
  929|  54.6k|	rbuf = rbufinitbuf;
  930|  54.6k|	rbuflen = sizeof(rbufinitbuf);
  931|       |
  932|       |	/* if caller provided a buffer and length */
  933|  54.6k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (933:6): [True: 45.1k, False: 9.56k]
  |  Branch (933:17): [True: 45.1k, False: 0]
  |  Branch (933:29): [True: 45.1k, False: 0]
  |  Branch (933:43): [True: 40.7k, False: 4.31k]
  ------------------
  934|  40.7k|		rbuf = *recvbuf;
  935|  40.7k|		rbuflen = *recvbuflen;
  936|  40.7k|	}
  937|       |
  938|  54.6k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (938:6): [True: 43.5k, False: 11.1k]
  |  Branch (938:17): [True: 0, False: 11.1k]
  ------------------
  939|  43.5k|		if (recvbuf) {
  ------------------
  |  Branch (939:7): [True: 33.9k, False: 9.56k]
  ------------------
  940|  33.9k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  33.9k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  941|  33.9k|		} else {
  942|  9.56k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  9.56k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  943|  9.56k|		}
  944|  43.5k|	} else {
  945|  11.1k|		if (recvbuf) {
  ------------------
  |  Branch (945:7): [True: 11.1k, False: 0]
  ------------------
  946|  11.1k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  11.1k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  947|  11.1k|		} else {
  948|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  949|      0|		}
  950|  11.1k|	}
  951|       |
  952|       |	/* append the nonce if we have it. Coolkey just blindly puts this at the end
  953|       |	 * of the APDU (while adjusting lc). This converts case 1 to case 3. coolkey
  954|       |	 * also always drops le in case 4 (which happens when proto = T0). nonces are
  955|       |	 * never used on case 2 commands, so we can simply append the nonce to the data
  956|       |	 * and we should be fine */
  957|  54.6k|	if (nonce) {
  ------------------
  |  Branch (957:6): [True: 33.9k, False: 20.7k]
  ------------------
  958|  33.9k|		u8 *buf = rsendbuf;
  959|  33.9k|		if (sendbuf) {
  ------------------
  |  Branch (959:7): [True: 33.9k, False: 0]
  ------------------
  960|  33.9k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   70|  33.9k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 33.9k, False: 0]
  |  |  ------------------
  ------------------
  961|  33.9k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  962|  33.9k|			buf += sendbuflen;
  963|  33.9k|		}
  964|  33.9k|		memcpy(buf, nonce, nonce_len);
  965|  33.9k|		sendbuflen += nonce_len;
  966|  33.9k|		sendbuf =rsendbuf;
  967|  33.9k|	}
  968|       |
  969|  54.6k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  970|       |
  971|  54.6k|	apdu.lc = sendbuflen;
  972|  54.6k|	apdu.datalen = sendbuflen;
  973|  54.6k|	apdu.data = sendbuf;
  974|       |
  975|       |
  976|       |	/* coolkey uses non-standard classes */
  977|  54.6k|	apdu.cla = cla;
  978|       |
  979|  54.6k|	if (recvbuf) {
  ------------------
  |  Branch (979:6): [True: 45.1k, False: 9.56k]
  ------------------
  980|  45.1k|		apdu.resp = rbuf;
  981|  45.1k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (981:13): [True: 8.78k, False: 36.3k]
  ------------------
  982|  45.1k|		apdu.resplen = rbuflen;
  983|  45.1k|	} else {
  984|  9.56k|		 apdu.resp =  rbuf;
  985|  9.56k|		 apdu.le = 0;
  986|  9.56k|		 apdu.resplen = 0;
  987|  9.56k|	}
  988|       |
  989|  54.6k|	sc_log(card->ctx,
  ------------------
  |  |   71|  54.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__
  |  |  ------------------
  ------------------
  990|  54.6k|		 "calling sc_transmit_apdu flags=%lx le=%"SC_FORMAT_LEN_SIZE_T"u, resplen=%"SC_FORMAT_LEN_SIZE_T"u, resp=%p",
  991|  54.6k|		 apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  992|       |
  993|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  994|  54.6k|	r = sc_transmit_apdu(card, &apdu);
  995|       |
  996|  54.6k|	sc_log(card->ctx,
  ------------------
  |  |   71|  54.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__
  |  |  ------------------
  ------------------
  997|  54.6k|		 "result r=%d apdu.resplen=%"SC_FORMAT_LEN_SIZE_T"u sw1=%02x sw2=%02x",
  998|  54.6k|		 r, apdu.resplen, apdu.sw1, apdu.sw2);
  999|       |
 1000|  54.6k|	if (r < 0) {
  ------------------
  |  Branch (1000:6): [True: 1.47k, False: 53.1k]
  ------------------
 1001|  1.47k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1002|  1.47k|		goto err;
 1003|  1.47k|	}
 1004|  53.1k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|  53.1k|	if (r < 0) {
  ------------------
  |  Branch (1005:6): [True: 33.9k, False: 19.2k]
  ------------------
 1006|  33.9k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  33.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1007|  33.9k|		goto err;
 1008|  33.9k|	}
 1009|       |
 1010|  19.2k|	if (recvbuflen) {
  ------------------
  |  Branch (1010:6): [True: 16.7k, False: 2.50k]
  ------------------
 1011|  16.7k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1011:7): [True: 16.7k, False: 0]
  |  Branch (1011:18): [True: 0, False: 16.7k]
  ------------------
 1012|      0|			*recvbuf =  malloc(apdu.resplen);
 1013|      0|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (1013:8): [True: 0, False: 0]
  ------------------
 1014|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1015|      0|				goto err;
 1016|      0|			}
 1017|      0|			memcpy(*recvbuf, rbuf, apdu.resplen);
 1018|      0|		}
 1019|  16.7k|		*recvbuflen =  apdu.resplen;
 1020|  16.7k|		r = (int)*recvbuflen;
 1021|  16.7k|	}
 1022|       |
 1023|  54.6k|err:
 1024|  54.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  54.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  54.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  54.6k|	int _ret = r; \
  |  |  |  |  155|  54.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 38.4k, False: 16.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|  38.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|  35.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 35.3k, False: 3.07k]
  |  |  |  |  ------------------
  |  |  |  |  157|  38.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  38.4k|	} else { \
  |  |  |  |  159|  16.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.2k|	} \
  |  |  |  |  162|  54.6k|	return _ret; \
  |  |  |  |  163|  54.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|  54.6k|}
card-coolkey.c:coolkey_find_object_by_id:
  825|  12.1k|{
  826|  12.1k|	int pos;
  827|  12.1k|	static sc_cardctl_coolkey_object_t cmp = {{
  828|  12.1k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  12.1k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  829|  12.1k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  12.1k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  12.1k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  830|  12.1k|	}, 0, 0, NULL};
  831|       |
  832|  12.1k|	cmp.id = object_id;
  833|  12.1k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (833:6): [True: 7.11k, False: 5.05k]
  ------------------
  834|  7.11k|		return NULL;
  835|       |
  836|  5.05k|	return list_get_at(list, pos);
  837|  12.1k|}
card-coolkey.c:coolkey_find_attribute:
 1424|  72.6k|{
 1425|  72.6k|	u8 object_record_type;
 1426|  72.6k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1427|  72.6k|	const u8 *obj = attribute->object->data;
 1428|  72.6k|	const u8 *attr = NULL;
 1429|  72.6k|	size_t buf_len = attribute->object->length;
 1430|  72.6k|	coolkey_object_header_t *object_head;
 1431|  72.6k|	int attribute_count,i;
 1432|  72.6k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1048|  72.6k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1433|  72.6k|	attribute->attribute_length = 0;
 1434|  72.6k|	attribute->attribute_value = NULL;
 1435|       |
 1436|  72.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  72.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  72.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  72.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  72.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 72.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|       |
 1438|  72.6k|	if (obj == NULL) {
  ------------------
  |  Branch (1438:6): [True: 30.3k, False: 42.3k]
  ------------------
 1439|       |		/* cast away const so we can cache the data value */
 1440|  30.3k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1441|  30.3k|		if (r < 0) {
  ------------------
  |  Branch (1441:7): [True: 28.2k, False: 2.15k]
  ------------------
 1442|  28.2k|			return r;
 1443|  28.2k|		}
 1444|  2.15k|		obj = attribute->object->data;
 1445|  2.15k|		if (obj == NULL) {
  ------------------
  |  Branch (1445:7): [True: 0, False: 2.15k]
  ------------------
 1446|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1447|      0|		}
 1448|  2.15k|	}
 1449|       |
 1450|       |	/* should be a static assert so we catch this at compile time */
 1451|  72.6k|	static_assert(sizeof(coolkey_object_header_t) >= sizeof(coolkey_v0_object_header_t), "internal error");
 1452|       |	/* make sure we have enough of the object to read the record_type */
 1453|  44.4k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1453:6): [True: 267, False: 44.1k]
  ------------------
 1454|    267|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    267|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1455|    267|	}
 1456|  44.1k|	object_head = (coolkey_object_header_t *)obj;
 1457|  44.1k|	object_record_type = object_head->record_type;
 1458|       |	/* make sure it's a type we recognize */
 1459|  44.1k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  44.1k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  5.10k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1459:6): [True: 5.10k, False: 39.0k]
  |  Branch (1459:51): [True: 1.25k, False: 3.84k]
  ------------------
 1460|  1.25k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  1.25k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1461|  1.25k|	}
 1462|       |
 1463|       |	/*
 1464|       |	 * now loop through all the attributes in the list. first find the start of the list
 1465|       |	 */
 1466|  42.9k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1467|  42.9k|	if (attr == NULL) {
  ------------------
  |  Branch (1467:6): [True: 309, False: 42.6k]
  ------------------
 1468|    309|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    309|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1469|    309|	}
 1470|  42.6k|	buf_len -= (attr-obj);
 1471|       |
 1472|       |	/* now get the count */
 1473|  42.6k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1474|   113k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1474:12): [True: 73.6k, False: 39.5k]
  ------------------
 1475|  73.6k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1476|       |		/* make sure we have the complete record */
 1477|  73.6k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1477:7): [True: 0, False: 73.6k]
  |  Branch (1477:31): [True: 435, False: 73.1k]
  ------------------
 1478|    435|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    435|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1479|    435|		}
 1480|       |		/* does the attribute match the one we are looking for */
 1481|  73.1k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1481:7): [True: 2.66k, False: 70.5k]
  ------------------
 1482|       |			/* yup, return it */
 1483|  2.66k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1484|  2.66k|		}
 1485|       |		/* go to the next attribute on the list */
 1486|  70.5k|		buf_len -= record_len;
 1487|  70.5k|		attr += record_len;
 1488|  70.5k|	}
 1489|       |	/* not find in attribute list, check the fixed attribute record */
 1490|  39.5k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  39.5k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1490:6): [True: 37.0k, False: 2.49k]
  ------------------
 1491|  37.0k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1492|       |
 1493|  37.0k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1494|  37.0k|	}
 1495|  2.49k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  2.49k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.49k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.49k|	int _ret = r; \
  |  |  |  |  155|  2.49k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.49k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.49k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.49k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.49k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.49k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.49k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.49k|	return _ret; \
  |  |  |  |  163|  2.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1496|  2.49k|}
card-coolkey.c:coolkey_attribute_start:
  421|  46.6k|{
  422|  46.6k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  229|  46.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (422:18): [True: 39.0k, False: 7.59k]
  ------------------
  423|  46.6k|			sizeof(coolkey_v0_object_header_t);
  424|       |
  425|  46.6k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  46.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  7.59k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (425:6): [True: 7.59k, False: 39.0k]
  |  Branch (425:51): [True: 0, False: 7.59k]
  ------------------
  426|      0|		return NULL;
  427|      0|	}
  428|  46.6k|	if (offset > buf_len) {
  ------------------
  |  Branch (428:6): [True: 309, False: 46.3k]
  ------------------
  429|    309|		return NULL;
  430|    309|	}
  431|  46.3k|	return obj + offset;
  432|  46.6k|}
card-coolkey.c:coolkey_get_attribute_count:
  502|  42.6k|{
  503|  42.6k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  42.6k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (503:6): [True: 3.84k, False: 38.7k]
  ------------------
  504|  3.84k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  505|  3.84k|	}
  506|  38.7k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  38.7k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (506:6): [True: 0, False: 38.7k]
  ------------------
  507|      0|		return 0;
  508|      0|	}
  509|  38.7k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  510|  38.7k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  440|  3.84k|{
  441|  3.84k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  442|  3.84k|	const u8 *attr;
  443|  3.84k|	int count = 0;
  444|  3.84k|	size_t attribute_data_len;
  445|       |
  446|       |	/* make sure we have enough of the object to read the record_type */
  447|  3.84k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (447:6): [True: 96, False: 3.75k]
  ------------------
  448|     96|		return 0;
  449|     96|	}
  450|       |	/*
  451|       |	 * now loop through all the attributes in the list. first find the start of the list
  452|       |	 */
  453|  3.75k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|  3.75k|#define COOLKEY_V0_OBJECT 0
  ------------------
  454|  3.75k|	if (attr == NULL) {
  ------------------
  |  Branch (454:6): [True: 0, False: 3.75k]
  ------------------
  455|      0|		return 0;
  456|      0|	}
  457|       |
  458|  3.75k|	buf_len -= (attr-obj);
  459|  3.75k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  460|  3.75k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (460:6): [True: 539, False: 3.21k]
  ------------------
  461|    539|		return 0;
  462|    539|	}
  463|       |
  464|  16.3k|	while (attribute_data_len) {
  ------------------
  |  Branch (464:9): [True: 16.0k, False: 296]
  ------------------
  465|  16.0k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  466|       |
  467|  16.0k|		if (len == 0) {
  ------------------
  |  Branch (467:7): [True: 0, False: 16.0k]
  ------------------
  468|      0|			break;
  469|      0|		}
  470|       |		/*  This is an error in the token data, don't parse the last attribute */
  471|  16.0k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (471:7): [True: 2.91k, False: 13.1k]
  ------------------
  472|  2.91k|			break;
  473|  2.91k|		}
  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|  13.1k|		if (len > buf_len)
  ------------------
  |  Branch (479:7): [True: 0, False: 13.1k]
  ------------------
  480|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  481|  13.1k|		count++;
  482|  13.1k|		attr += len;
  483|  13.1k|		buf_len -= len;
  484|  13.1k|		attribute_data_len -= len;
  485|  13.1k|	}
  486|  3.21k|	return count;
  487|  3.21k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  380|  27.4k|{
  381|  27.4k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  382|  27.4k|	size_t len;
  383|  27.4k|	int r;
  384|       |
  385|  27.4k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  386|  27.4k|	if (r < 0) {
  ------------------
  |  Branch (386:6): [True: 115, False: 27.3k]
  ------------------
  387|    115|		return buf_len; /* skip to the end, ignore the rest of the record */
  388|    115|	}
  389|  27.3k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  27.3k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 2.72k, False: 24.6k]
  |  |  ------------------
  ------------------
  390|  27.4k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  491|  38.7k|{
  492|  38.7k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  493|       |
  494|  38.7k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (494:6): [True: 7.33k, False: 31.4k]
  ------------------
  495|  7.33k|		return 0;
  496|  7.33k|	}
  497|  31.4k|	return bebytes2ushort(object_head->attribute_count);
  498|  38.7k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  394|  73.6k|{
  395|  73.6k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  73.6k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (395:6): [True: 11.4k, False: 62.1k]
  ------------------
  396|  11.4k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  397|  11.4k|	}
  398|  62.1k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  62.1k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (398:6): [True: 0, False: 62.1k]
  ------------------
  399|      0|		return buf_len; /* skip to the end */
  400|      0|	}
  401|  62.1k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  402|  62.1k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  364|   272k|{
  365|   272k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  366|   272k|	size_t len = 0;
  367|   272k|	int r;
  368|       |
  369|   272k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  370|   272k|	if (r < 0) {
  ------------------
  |  Branch (370:6): [True: 218k, False: 53.5k]
  ------------------
  371|   218k|		return buf_len; /* skip to the end, ignore the rest of the record */
  372|   218k|	}
  373|       |
  374|  53.5k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  53.5k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 17.7k, False: 35.8k]
  |  |  ------------------
  ------------------
  375|   272k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  674|  37.0k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  675|  37.0k|	unsigned long cka_id = fixed_attributes & 0xf;
  676|  37.0k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  677|  37.0k|	unsigned long mask, bit;
  678|       |
  679|  37.0k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  37.0k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (679:6): [True: 3.02k, False: 34.0k]
  ------------------
  680|  3.02k|		attr_out->attribute_length = 1;
  681|  3.02k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  682|  3.02k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.02k|#define SC_SUCCESS				0
  ------------------
  683|  3.02k|	}
  684|  34.0k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  34.0k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (684:6): [True: 11.5k, False: 22.4k]
  ------------------
  685|  11.5k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|  11.5k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  686|  11.5k|		attr_out->attribute_length = 4;
  687|  11.5k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  688|  11.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
  689|  11.5k|	}
  690|       |	/* If it matched, it must be one of the booleans */
  691|  22.4k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  692|  22.4k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  693|       |	/* attribute isn't in the list */
  694|  22.4k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (694:6): [True: 8.44k, False: 14.0k]
  ------------------
  695|  8.44k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  8.44k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  696|  8.44k|	}
  697|  14.0k|	attr_out->attribute_length = 1;
  698|  14.0k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (698:30): [True: 5.32k, False: 8.70k]
  ------------------
  699|  14.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  14.0k|#define SC_SUCCESS				0
  ------------------
  700|  22.4k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  620|  22.4k|{
  621|  22.4k|	switch(type) {
  622|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (622:2): [True: 0, False: 22.4k]
  ------------------
  623|  1.41k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  1.41k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (623:2): [True: 1.41k, False: 21.0k]
  ------------------
  624|  1.53k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  1.53k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (624:2): [True: 1.53k, False: 20.9k]
  ------------------
  625|  1.13k|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|  1.13k|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (625:2): [True: 1.13k, False: 21.3k]
  ------------------
  626|  1.13k|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|  1.13k|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (626:2): [True: 1.13k, False: 21.3k]
  ------------------
  627|  1.13k|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|  1.13k|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (627:2): [True: 1.13k, False: 21.3k]
  ------------------
  628|  1.13k|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|  1.13k|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (628:2): [True: 1.13k, False: 21.3k]
  ------------------
  629|  1.13k|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|  1.13k|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (629:2): [True: 1.13k, False: 21.3k]
  ------------------
  630|  1.13k|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|  1.13k|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (630:2): [True: 1.13k, False: 21.3k]
  ------------------
  631|  1.13k|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|  1.13k|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (631:2): [True: 1.13k, False: 21.3k]
  ------------------
  632|  1.13k|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|  1.13k|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (632:2): [True: 1.13k, False: 21.3k]
  ------------------
  633|  1.13k|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|  1.13k|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (633:2): [True: 1.13k, False: 21.3k]
  ------------------
  634|  1.13k|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|  1.13k|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (634:2): [True: 1.13k, False: 21.3k]
  ------------------
  635|  1.12k|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|  1.12k|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (635:2): [True: 1.12k, False: 21.3k]
  ------------------
  636|  1.13k|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|  1.13k|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (636:2): [True: 1.13k, False: 21.3k]
  ------------------
  637|  1.13k|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|  1.13k|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (637:2): [True: 1.13k, False: 21.3k]
  ------------------
  638|  1.13k|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|  1.13k|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (638:2): [True: 1.13k, False: 21.3k]
  ------------------
  639|  3.70k|	default: break;
  ------------------
  |  Branch (639:2): [True: 3.70k, False: 18.7k]
  ------------------
  640|  22.4k|	}
  641|  3.70k|	return 0; /* return no bits */
  642|  22.4k|}
card-coolkey.c:sc_get_driver:
 2449|  15.0k|{
 2450|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2451|       |
 2452|  15.0k|	coolkey_ops = *iso_drv->ops;
 2453|  15.0k|	coolkey_ops.match_card = coolkey_match_card;
 2454|  15.0k|	coolkey_ops.init = coolkey_init;
 2455|  15.0k|	coolkey_ops.finish = coolkey_finish;
 2456|       |
 2457|  15.0k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2458|  15.0k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2459|  15.0k|	coolkey_ops.read_binary = coolkey_read_binary;
 2460|  15.0k|	coolkey_ops.write_binary = coolkey_write_binary;
 2461|  15.0k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2462|  15.0k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2463|  15.0k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2464|  15.0k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2465|  15.0k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2466|  15.0k|	coolkey_ops.check_sw = coolkey_check_sw;
 2467|  15.0k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2468|  15.0k|	coolkey_ops.logout = coolkey_logout;
 2469|  15.0k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2470|       |
 2471|  15.0k|	return &coolkey_drv;
 2472|  15.0k|}
card-coolkey.c:coolkey_match_card:
 2288|  6.71k|{
 2289|  6.71k|	int r;
 2290|       |
 2291|  6.71k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.71k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.71k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.71k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.71k]
  |  |  ------------------
  ------------------
 2292|       |
 2293|  6.71k|	r = coolkey_select_applet(card);
 2294|  6.71k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  6.71k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2294:6): [True: 1.06k, False: 5.65k]
  ------------------
 2295|  1.06k|		sc_apdu_t apdu;
 2296|       |
 2297|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2298|       |		 * on Coolkey applet (reserved for GetMemory function),
 2299|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2300|       |		 */
 2301|  1.06k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.06k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   79|  1.06k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2302|  1.06k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   72|  1.06k|#define COOLKEY_CLASS           0xb0
  ------------------
 2303|  1.06k|		apdu.le = 0x00;
 2304|  1.06k|		apdu.resplen = 0;
 2305|  1.06k|		apdu.resp = NULL;
 2306|  1.06k|		r = sc_transmit_apdu(card, &apdu);
 2307|  1.06k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.12k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2307:7): [True: 1.05k, False: 7]
  |  Branch (2307:26): [True: 1.02k, False: 31]
  |  Branch (2307:46): [True: 1.02k, False: 6]
  ------------------
 2308|  1.02k|			return 1;
 2309|  1.02k|		}
 2310|     44|		return 0;
 2311|  1.06k|	}
 2312|  5.65k|	return 0;
 2313|  6.71k|}
card-coolkey.c:coolkey_select_applet:
 1074|  9.56k|{
 1075|  9.56k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1076|  9.56k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   71|  9.56k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   75|  9.56k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1077|  9.56k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1078|  9.56k|}
card-coolkey.c:coolkey_init:
 2317|  1.02k|{
 2318|  1.02k|	int r;
 2319|  1.02k|	unsigned long flags;
 2320|  1.02k|	unsigned long ext_flags;
 2321|  1.02k|	coolkey_private_data_t * priv;
 2322|       |
 2323|  1.02k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.02k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.02k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.02k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.02k]
  |  |  ------------------
  ------------------
 2324|       |
 2325|  1.02k|	r = coolkey_initialize(card);
 2326|  1.02k|	if (r < 0) {
  ------------------
  |  Branch (2326:6): [True: 390, False: 630]
  ------------------
 2327|    390|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    390|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    390|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    390|	int _ret = r; \
  |  |  |  |  155|    390|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 390, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    390|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    390|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 390, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    390|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    390|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    390|	return _ret; \
  |  |  |  |  163|    390|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2328|    390|	}
 2329|       |
 2330|    630|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2331|       |
 2332|       |	/* set Token Major/minor version */
 2333|    630|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|    630|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2334|       |
 2335|    630|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2336|    630|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2337|    630|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2338|       |
 2339|    630|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  183|    630|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  182|    630|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    630|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    630|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2340|    630|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    630|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    630|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2341|       |
 2342|    630|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2343|    630|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2344|    630|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2345|       |
 2346|       |
 2347|    630|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    630|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2348|    630|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2348:6): [True: 295, False: 335]
  ------------------
 2349|    295|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    295|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2350|    295|	}
 2351|       |
 2352|    630|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    630|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    630|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    630|	int _ret = r; \
  |  |  |  |  155|    630|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 630, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    630|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 630]
  |  |  |  |  ------------------
  |  |  |  |  157|    630|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    630|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    630|	return _ret; \
  |  |  |  |  163|    630|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2353|    630|}
card-coolkey.c:coolkey_initialize:
 2157|  1.02k|{
 2158|  1.02k|	int r;
 2159|  1.02k|	coolkey_private_data_t *priv = NULL;
 2160|  1.02k|	coolkey_life_cycle_t life_cycle;
 2161|  1.02k|	coolkey_object_info_t object_info;
 2162|  1.02k|	int combined_processed = 0;
 2163|       |
 2164|       |	/* already found? */
 2165|  1.02k|	if (card->drv_data) {
  ------------------
  |  Branch (2165:6): [True: 0, False: 1.02k]
  ------------------
 2166|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2167|      0|	}
 2168|  1.02k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2169|       |
 2170|  1.02k|	priv = coolkey_new_private_data();
 2171|  1.02k|	if (priv == NULL) {
  ------------------
  |  Branch (2171:6): [True: 0, False: 1.02k]
  ------------------
 2172|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2173|      0|		goto cleanup;
 2174|      0|	}
 2175|  1.02k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2176|  1.02k|	if (r < 0) {
  ------------------
  |  Branch (2176:6): [True: 66, False: 954]
  ------------------
 2177|     66|		goto cleanup;
 2178|     66|	}
 2179|       |
 2180|       |	/* Select a coolkey read the coolkey objects out */
 2181|    954|	r = coolkey_select_applet(card);
 2182|    954|	if (r < 0) {
  ------------------
  |  Branch (2182:6): [True: 6, False: 948]
  ------------------
 2183|      6|		goto cleanup;
 2184|      6|	}
 2185|       |
 2186|    948|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2187|    948|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2188|    948|	priv->pin_count = life_cycle.pin_count;
 2189|    948|	priv->life_cycle = life_cycle.life_cycle;
 2190|       |
 2191|       |	/* walk down the list of objects and read them off the token */
 2192|    948|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  104|    948|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2193|  10.0k|	while (r >= 0) {
  ------------------
  |  Branch (2193:9): [True: 9.22k, False: 816]
  ------------------
 2194|  9.22k|		unsigned long object_id;
 2195|  9.22k|		unsigned long object_len;
 2196|       |
 2197|       |		/* The card did not return what we expected: Lets try other objects */
 2198|  9.22k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2198:7): [True: 8, False: 9.22k]
  ------------------
 2199|      8|			break;
 2200|       |
 2201|       |		/* TODO also look at the ACL... */
 2202|       |
 2203|  9.22k|		object_id = bebytes2ulong(object_info.object_id);
 2204|  9.22k|		object_len = bebytes2ulong(object_info.object_length);
 2205|       |		/* Avoid insanely large data */
 2206|  9.22k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  9.22k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2206:7): [True: 14, False: 9.20k]
  ------------------
 2207|     14|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     14|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2208|     14|			goto cleanup;
 2209|     14|		}
 2210|       |
 2211|       |		/* the combined object is a single object that can store the other objects.
 2212|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2213|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2214|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2215|       |		 * process it separately so that we can have both combined objects managed
 2216|       |		 * by TPS and user managed certs on the same token */
 2217|  9.20k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  109|  9.20k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2217:7): [True: 113, False: 9.09k]
  ------------------
 2218|    113|			u8 *object = malloc(object_len);
 2219|    113|			if (object == NULL) {
  ------------------
  |  Branch (2219:8): [True: 0, False: 113]
  ------------------
 2220|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2221|      0|				break;
 2222|      0|			}
 2223|    113|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  109|    113|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2224|    113|				priv->nonce, sizeof(priv->nonce));
 2225|    113|			if (r < 0) {
  ------------------
  |  Branch (2225:8): [True: 59, False: 54]
  ------------------
 2226|     59|				free(object);
 2227|     59|				break;
 2228|     59|			}
 2229|     54|			r = coolkey_process_combined_object(card, priv, object, r);
 2230|     54|			free(object);
 2231|     54|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     54|#define SC_SUCCESS				0
  ------------------
  |  Branch (2231:8): [True: 51, False: 3]
  ------------------
 2232|     51|				break;
 2233|     51|			}
 2234|      3|			combined_processed = 1;
 2235|  9.09k|		} else {
 2236|  9.09k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  9.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2237|  9.09k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2238|  9.09k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  9.09k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2238:8): [True: 2.69k, False: 6.40k]
  ------------------
 2239|  2.69k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  2.69k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2240|  9.09k|		}
 2241|       |
 2242|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2243|  9.09k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  105|  9.09k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2244|  9.09k|	}
 2245|    934|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    934|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2245:6): [True: 285, False: 649]
  ------------------
 2246|       |		/* This means the card does not cooperate at all: bail out */
 2247|    285|		if (r >= 0) {
  ------------------
  |  Branch (2247:7): [True: 8, False: 277]
  ------------------
 2248|      8|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      8|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2249|      8|		}
 2250|    285|		goto cleanup;
 2251|    285|	}
 2252|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2253|    649|	if (!combined_processed) {
  ------------------
  |  Branch (2253:6): [True: 648, False: 1]
  ------------------
 2254|    648|		global_platform_cplc_data_t cplc_data;
 2255|       |		/* select the card manager, because a card with applet only will have
 2256|       |		   already selected the coolkey applet */
 2257|       |
 2258|    648|		r = gp_select_card_manager(card);
 2259|    648|		if (r < 0) {
  ------------------
  |  Branch (2259:7): [True: 7, False: 641]
  ------------------
 2260|      7|			goto cleanup;
 2261|      7|		}
 2262|       |
 2263|    641|		r = gp_get_cplc_data(card, &cplc_data);
 2264|    641|		if (r < 0) {
  ------------------
  |  Branch (2264:7): [True: 12, False: 629]
  ------------------
 2265|     12|			goto cleanup;
 2266|     12|		}
 2267|    629|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2268|    629|		priv->token_name = (u8 *)strdup("COOLKEY");
 2269|    629|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2269:7): [True: 0, False: 629]
  ------------------
 2270|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2271|      0|			goto cleanup;
 2272|      0|		}
 2273|    629|		priv->token_name_length = sizeof("COOLKEY")-1;
 2274|    629|	}
 2275|    630|	card->drv_data = priv;
 2276|    630|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    630|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    630|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    630|	int _ret = r; \
  |  |  |  |  155|    630|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 630, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    630|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 630]
  |  |  |  |  ------------------
  |  |  |  |  157|    630|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    630|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    630|	return _ret; \
  |  |  |  |  163|    630|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2277|       |
 2278|    390|cleanup:
 2279|    390|	if (priv) {
  ------------------
  |  Branch (2279:6): [True: 390, False: 0]
  ------------------
 2280|    390|		coolkey_free_private_data(priv);
 2281|    390|	}
 2282|    390|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    390|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    390|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    390|	int _ret = r; \
  |  |  |  |  155|    390|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 390, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    390|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    390|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 390, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    390|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    390|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    390|	return _ret; \
  |  |  |  |  163|    390|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2283|    390|}
card-coolkey.c:coolkey_new_private_data:
  772|  1.02k|{
  773|  1.02k|	coolkey_private_data_t *priv;
  774|       |
  775|       |	/* allocate priv and zero all the fields */
  776|  1.02k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  777|  1.02k|	if (!priv)
  ------------------
  |  Branch (777:6): [True: 0, False: 1.02k]
  ------------------
  778|      0|		return NULL;
  779|       |
  780|       |	/* set other fields as appropriate */
  781|  1.02k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|  1.02k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  782|  1.02k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (782:6): [True: 0, False: 1.02k]
  ------------------
  783|  1.02k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.02k]
  ------------------
  784|  1.02k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (784:6): [True: 0, False: 1.02k]
  ------------------
  785|      0|		coolkey_free_private_data(priv);
  786|      0|		return NULL;
  787|      0|	}
  788|       |
  789|  1.02k|	return priv;
  790|  1.02k|}
card-coolkey.c:coolkey_get_life_cycle:
 1032|  1.02k|{
 1033|  1.02k|	coolkey_status_t status;
 1034|  1.02k|	u8 *receive_buf;
 1035|  1.02k|	size_t receive_len;
 1036|  1.02k|	int len;
 1037|       |
 1038|  1.02k|	receive_len = sizeof(*life_cycle);
 1039|  1.02k|	receive_buf = (u8 *)life_cycle;
 1040|  1.02k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|  1.02k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|  1.02k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1041|  1.02k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1042|  1.02k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1042:6): [True: 951, False: 69]
  ------------------
 1043|    951|		return SC_SUCCESS;
  ------------------
  |  |   28|    951|#define SC_SUCCESS				0
  ------------------
 1044|    951|	}
 1045|       |
 1046|     69|	receive_len = 1;
 1047|     69|	receive_buf = &life_cycle->life_cycle;
 1048|     69|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|     69|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|     69|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1049|     69|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1050|     69|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1050:6): [True: 53, False: 16]
  ------------------
 1051|     53|		return len;
 1052|     53|	}
 1053|     16|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1053:6): [True: 2, False: 14]
  ------------------
 1054|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1055|      2|	}
 1056|     14|	receive_len = sizeof(status);
 1057|     14|	receive_buf = (u8 *)&status;
 1058|     14|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   72|     14|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   79|     14|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1059|     14|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1060|     14|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1060:6): [True: 7, False: 7]
  ------------------
 1061|      7|		return len;
 1062|      7|	}
 1063|      7|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1063:6): [True: 4, False: 3]
  ------------------
 1064|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1065|      4|	}
 1066|      3|	life_cycle->protocol_version_major = status.protocol_version_major;
 1067|      3|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1068|      3|	life_cycle->pin_count = status.pin_count;
 1069|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 1070|      7|}
card-coolkey.c:coolkey_list_object:
 2144|  10.0k|{
 2145|  10.0k|	u8 *rbuf = (u8 *) object_info;
 2146|  10.0k|	size_t rbuflen = sizeof(*object_info);
 2147|       |
 2148|  10.0k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   72|  10.0k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   81|  10.0k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2149|  10.0k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2150|       |
 2151|  10.0k|}
card-coolkey.c:coolkey_process_combined_object:
 2013|     54|{
 2014|     54|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2015|     54|	unsigned short compressed_offset;
 2016|     54|	unsigned short compressed_length;
 2017|     54|	unsigned short compressed_type;
 2018|     54|	unsigned short object_offset;
 2019|     54|	unsigned short object_count;
 2020|     54|	coolkey_decompressed_header_t *decompressed_header;
 2021|     54|	u8 *decompressed_object = NULL;
 2022|     54|	size_t decompressed_object_len = 0;
 2023|     54|	int free_decompressed = 0;
 2024|     54|	int i, r;
 2025|       |
 2026|     54|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2026:6): [True: 1, False: 53]
  ------------------
 2027|      1|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2028|      1|	}
 2029|     53|	compressed_offset = bebytes2ushort(header->compression_offset);
 2030|     53|	compressed_length = bebytes2ushort(header->compression_length);
 2031|     53|	compressed_type   = bebytes2ushort(header->compression_type);
 2032|       |
 2033|     53|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2033:6): [True: 6, False: 47]
  ------------------
 2034|      6|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      6|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2035|      6|	}
 2036|       |
 2037|       |	/* store the CUID */
 2038|     47|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2039|       |
 2040|     47|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  180|     47|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2040:6): [True: 8, False: 39]
  ------------------
 2041|      8|#ifdef ENABLE_ZLIB
 2042|      8|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|      8|#define COMPRESSION_AUTO	0
  ------------------
 2043|      8|		if (r)
  ------------------
  |  Branch (2043:7): [True: 6, False: 2]
  ------------------
 2044|      6|			goto done;
 2045|      2|		free_decompressed = 1;
 2046|       |#else
 2047|       |		sc_log(card->ctx, "Coolkey compression not supported, no zlib");
 2048|       |		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2049|       |#endif
 2050|     39|	}  else {
 2051|     39|		decompressed_object =&object[compressed_offset];
 2052|     39|		decompressed_object_len = (size_t) compressed_length;
 2053|     39|	}
 2054|       |
 2055|     41|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2056|       |
 2057|     41|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2057:6): [True: 5, False: 36]
  ------------------
 2058|      5|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      5|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2059|      5|		goto done;
 2060|      5|	}
 2061|     36|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2062|     36|	object_count = bebytes2ushort(decompressed_header->object_count);
 2063|       |
 2064|       |
 2065|       |	/*
 2066|       |	 * using 2 different tests here so we can log different errors if logging is
 2067|       |	 * turned on.
 2068|       |	 */
 2069|       |	/* make sure token_name doesn't overrun the buffer */
 2070|     36|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2070:6): [True: 0, False: 36]
  ------------------
 2071|     36|		offsetof(coolkey_decompressed_header_t, token_name) > decompressed_object_len) {
 2072|      0|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2073|      0|		goto done;
 2074|      0|	}
 2075|       |	/* make sure it doesn't overlap the object space */
 2076|     36|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2076:6): [True: 1, False: 35]
  ------------------
 2077|     36|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2078|      1|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2079|      1|		goto done;
 2080|      1|	}
 2081|       |
 2082|       |	/* store the token name in the priv structure so the emulator can set it */
 2083|     35|	free(priv->token_name);
 2084|     35|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2085|     35|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2085:6): [True: 0, False: 35]
  ------------------
 2086|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2087|      0|		goto done;
 2088|      0|	}
 2089|     35|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2090|     35|							decompressed_header->token_name_length);
 2091|     35|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2092|     35|	priv->token_name_length = decompressed_header->token_name_length;
 2093|       |
 2094|       |
 2095|     87|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2095:12): [True: 84, False: 3]
  ------------------
 2096|     84|		u8 *current_object = NULL;
 2097|     84|		coolkey_combined_object_header_t *object_header = NULL;
 2098|     84|		unsigned long object_id;
 2099|     84|		int current_object_len;
 2100|       |
 2101|       |		/* Can we read the object header at all? */
 2102|     84|		if ((object_offset + sizeof(coolkey_combined_object_header_t)) > decompressed_object_len) {
  ------------------
  |  Branch (2102:7): [True: 31, False: 53]
  ------------------
 2103|     31|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     31|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2104|     31|			goto done;
 2105|     31|		}
 2106|       |
 2107|     53|		current_object = &decompressed_object[object_offset];
 2108|     53|		object_header = (coolkey_combined_object_header_t *)current_object;
 2109|       |
 2110|       |		/* Parse object ID */
 2111|     53|		object_id = bebytes2ulong(object_header->object_id);
 2112|       |
 2113|       |		/* figure out how big it is */
 2114|     53|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2115|     53|		if (r < 0) {
  ------------------
  |  Branch (2115:7): [True: 0, False: 53]
  ------------------
 2116|      0|			goto done;
 2117|      0|		}
 2118|     53|		if ((size_t)r + object_offset > decompressed_object_len) {
  ------------------
  |  Branch (2118:7): [True: 0, False: 53]
  ------------------
 2119|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2120|      0|			goto done;
 2121|      0|		}
 2122|     53|		current_object_len = r;
 2123|     53|		object_offset += current_object_len;
 2124|       |
 2125|       |		/* record this object */
 2126|     53|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2127|     53|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2128|     53|		if (r) {
  ------------------
  |  Branch (2128:7): [True: 1, False: 52]
  ------------------
 2129|      1|			goto done;
 2130|      1|		}
 2131|       |
 2132|     53|	}
 2133|      3|	r = SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 2134|       |
 2135|     47|done:
 2136|     47|	if (free_decompressed) {
  ------------------
  |  Branch (2136:6): [True: 2, False: 45]
  ------------------
 2137|      2|		free(decompressed_object);
 2138|      2|	}
 2139|     47|	return r;
 2140|      3|}
card-coolkey.c:coolkey_v1_get_object_length:
  706|     53|{
  707|     53|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  708|     53|	int attribute_count;
  709|     53|	u8 *current_attribute;
  710|     53|	int j;
  711|     53|	size_t len;
  712|       |
  713|     53|	len = sizeof(coolkey_combined_object_header_t);
  714|     53|	if (buf_len <= len) {
  ------------------
  |  Branch (714:6): [True: 1, False: 52]
  ------------------
  715|      1|		return (int)buf_len;
  716|      1|	}
  717|     52|	attribute_count = bebytes2ushort(object_head->attribute_count);
  718|     52|	buf_len -= len;
  719|       |
  720|   210k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (720:45): [True: 210k, False: 52]
  ------------------
  721|   210k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  722|       |
  723|   210k|		len += attribute_len;
  724|   210k|		current_attribute += attribute_len;
  725|   210k|		buf_len -= attribute_len;
  726|   210k|	}
  727|     52|	return (int)len;
  728|     53|}
card-coolkey.c:coolkey_add_object:
 1972|  9.14k|{
 1973|  9.14k|	sc_cardctl_coolkey_object_t new_object;
 1974|  9.14k|	int r;
 1975|       |
 1976|  9.14k|	memset(&new_object, 0, sizeof(new_object));
 1977|  9.14k|	new_object.path = coolkey_template_path;
 1978|  9.14k|	new_object.path.len = 4;
 1979|  9.14k|	ulong2bebytes(new_object.path.value, object_id);
 1980|  9.14k|	new_object.id = object_id;
 1981|  9.14k|	new_object.length = object_length;
 1982|       |
 1983|       |	/* The object ID needs to be unique */
 1984|  9.14k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1984:6): [True: 2.69k, False: 6.45k]
  ------------------
 1985|  2.69k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.69k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1986|  2.69k|	}
 1987|       |
 1988|  6.45k|	if (object_data) {
  ------------------
  |  Branch (1988:6): [True: 52, False: 6.40k]
  ------------------
 1989|     52|		new_object.data = malloc(object_length + add_v1_record);
 1990|     52|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1990:7): [True: 0, False: 52]
  ------------------
 1991|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1992|      0|		}
 1993|     52|		if (add_v1_record) {
  ------------------
  |  Branch (1993:7): [True: 52, False: 0]
  ------------------
 1994|     52|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  229|     52|#define COOLKEY_V1_OBJECT 1
  ------------------
 1995|     52|			new_object.length++;
 1996|     52|		}
 1997|     52|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1998|     52|	}
 1999|       |
 2000|  6.45k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 2001|  6.45k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  6.45k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2001:6): [True: 0, False: 6.45k]
  ------------------
 2002|       |		/* if we didn't successfully put the object on the list,
 2003|       |		 * the data space didn't get adopted. free it before we return */
 2004|      0|		free(new_object.data);
 2005|       |		new_object.data = NULL;
 2006|      0|	}
 2007|  6.45k|	return r;
 2008|  6.45k|}
card-coolkey.c:coolkey_add_object_to_list:
  816|  6.45k|{
  817|  6.45k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (817:6): [True: 0, False: 6.45k]
  ------------------
  818|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  819|  6.45k|	return SC_SUCCESS;
  ------------------
  |  |   28|  6.45k|#define SC_SUCCESS				0
  ------------------
  820|  6.45k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1082|    629|{
 1083|    629|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1084|    629|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1085|    629|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1086|    629|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1087|    629|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1088|    629|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1089|    629|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1090|    629|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1091|    629|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1092|    629|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1093|    629|}
card-coolkey.c:coolkey_free_private_data:
  793|  1.02k|{
  794|  1.02k|	list_t *l = &priv->objects_list;
  795|  1.02k|	sc_cardctl_coolkey_object_t *o;
  796|       |
  797|       |	/* Clean up the allocated memory in the items */
  798|  1.02k|	list_iterator_start(l);
  799|  7.47k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (799:9): [True: 6.45k, False: 1.02k]
  ------------------
  800|  6.45k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  801|  6.45k|		free(o->data);
  802|  6.45k|		o->data = NULL;
  803|  6.45k|	}
  804|  1.02k|	list_iterator_stop(l);
  805|       |
  806|  1.02k|	list_destroy(&priv->objects_list);
  807|  1.02k|	free(priv->token_name);
  808|  1.02k|	free(priv);
  809|  1.02k|	return;
  810|  1.02k|}
card-coolkey.c:coolkey_finish:
 1960|    630|{
 1961|    630|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    630|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1962|       |
 1963|    630|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    630|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    630|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    630|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 630]
  |  |  ------------------
  ------------------
 1964|    630|	if (priv) {
  ------------------
  |  Branch (1964:6): [True: 630, False: 0]
  ------------------
 1965|    630|		coolkey_free_private_data(priv);
 1966|    630|	}
 1967|    630|	return SC_SUCCESS;
  ------------------
  |  |   28|    630|#define SC_SUCCESS				0
  ------------------
 1968|    630|}
card-coolkey.c:coolkey_select_file:
 1913|  1.89k|{
 1914|  1.89k|	int r;
 1915|  1.89k|	struct sc_file *file = NULL;
 1916|  1.89k|	coolkey_private_data_t *priv;
 1917|  1.89k|	unsigned long object_id;
 1918|       |
 1919|  1.89k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1919:6): [True: 0, False: 1.89k]
  |  Branch (1919:22): [True: 0, False: 1.89k]
  ------------------
 1920|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1921|       |
 1922|  1.89k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.89k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.89k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.89k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.89k]
  |  |  ------------------
  ------------------
 1923|       |
 1924|  1.89k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.89k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1925|       |
 1926|  1.89k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1926:6): [True: 3, False: 1.89k]
  ------------------
 1927|      3|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      3|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1928|      3|	}
 1929|  1.89k|	r = coolkey_select_applet(card);
 1930|  1.89k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.89k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1930:6): [True: 1.40k, False: 488]
  ------------------
 1931|  1.40k|		return r;
 1932|  1.40k|	}
 1933|    488|	object_id = bebytes2ulong(in_path->value);
 1934|    488|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1935|    488|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1935:6): [True: 470, False: 18]
  ------------------
 1936|    470|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    470|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1937|    470|	}
 1938|       |
 1939|     18|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|     18|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1940|     18|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  111|     18|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1940:6): [True: 0, False: 18]
  ------------------
 1941|      0|		priv->key_id = coolkey_get_key_id(object_id);
 1942|      0|	}
 1943|     18|	if (file_out) {
  ------------------
  |  Branch (1943:6): [True: 17, False: 1]
  ------------------
 1944|     17|		file = sc_file_new();
 1945|     17|		if (file == NULL)
  ------------------
  |  Branch (1945:7): [True: 0, False: 17]
  ------------------
 1946|     17|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1947|     17|		file->path = *in_path;
 1948|       |		/* this could be like the FCI */
 1949|     17|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     17|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1950|     17|		file->shareable = 0;
 1951|     17|		file->ef_structure = 0;
 1952|     17|		file->size = priv->obj->length;
 1953|     17|		*file_out = file;
 1954|     17|	}
 1955|       |
 1956|     18|	return SC_SUCCESS;
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
 1957|     18|}
card-coolkey.c:coolkey_class:
 1886|     18|static u8 coolkey_class(unsigned long object_id) {
 1887|     18|	return (object_id >> 24) & 0xff;
 1888|     18|}
card-coolkey.c:coolkey_read_binary:
 1184|    133|{
 1185|    133|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    133|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1186|    133|	int r = 0;
 1187|    133|	size_t len;
 1188|    133|	u8 *data = NULL;
 1189|       |
 1190|    133|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    133|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    133|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    133|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 133]
  |  |  ------------------
  ------------------
 1191|    133|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1191:6): [True: 0, False: 133]
  ------------------
 1192|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_END_REACHED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1193|      0|	}
 1194|       |
 1195|       |	/* if we've already read the data, just return it */
 1196|    133|	if (priv->obj->data) {
  ------------------
  |  Branch (1196:6): [True: 117, False: 16]
  ------------------
 1197|    117|		sc_log(card->ctx,
  ------------------
  |  |   71|    117|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1198|    117|			 "returning cached value idx=%u count=%"SC_FORMAT_LEN_SIZE_T"u",
 1199|    117|			 idx, count);
 1200|    117|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|    117|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 107, False: 10]
  |  |  ------------------
  ------------------
 1201|    117|		memcpy(buf, &priv->obj->data[idx], len);
 1202|    117|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|    117|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    117|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    117|	int _ret = r; \
  |  |  |  |  155|    117|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 117]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    117|	} else { \
  |  |  |  |  159|    117|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    117|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    117|	} \
  |  |  |  |  162|    117|	return _ret; \
  |  |  |  |  163|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|    117|	}
 1204|       |
 1205|     16|	sc_log(card->ctx,
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1206|     16|		 "clearing cache idx=%u count=%"SC_FORMAT_LEN_SIZE_T"u",
 1207|     16|		 idx, count);
 1208|       |
 1209|     16|	data = malloc(priv->obj->length);
 1210|     16|	if (data == NULL) {
  ------------------
  |  Branch (1210:6): [True: 0, False: 16]
  ------------------
 1211|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1212|      0|		goto done;
 1213|      0|	}
 1214|       |
 1215|       |
 1216|     16|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1217|     16|		priv->nonce, sizeof(priv->nonce));
 1218|     16|	if (r < 0)
  ------------------
  |  Branch (1218:6): [True: 5, False: 11]
  ------------------
 1219|      5|		goto done;
 1220|       |
 1221|     11|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1221:6): [True: 0, False: 11]
  ------------------
 1222|      0|		priv->obj->length = r;
 1223|      0|	}
 1224|       |
 1225|       |
 1226|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
 1227|     11|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     11|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 10, False: 1]
  |  |  ------------------
  ------------------
 1228|     11|	memcpy(buf, &data[idx], len);
 1229|     11|	r = (int)len;
 1230|       |	/* cache the data in the object */
 1231|     11|	priv->obj->data=data;
 1232|     11|	data = NULL;
 1233|       |
 1234|     16|done:
 1235|     16|	if (data)
  ------------------
  |  Branch (1235:6): [True: 5, False: 11]
  ------------------
 1236|      5|		free(data);
 1237|     16|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     11|	} else { \
  |  |  |  |  159|     11|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     11|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     11|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1238|     16|}
card-coolkey.c:coolkey_card_ctl:
 1589|  53.7k|{
 1590|  53.7k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  53.7k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1591|       |
 1592|  53.7k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  53.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  53.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  53.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  53.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 53.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1593|  53.7k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  53.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__
  |  |  ------------------
  ------------------
 1594|       |
 1595|  53.7k|	if (priv == NULL) {
  ------------------
  |  Branch (1595:6): [True: 0, False: 53.7k]
  ------------------
 1596|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1597|      0|	}
 1598|  53.7k|	switch(cmd) {
  ------------------
  |  Branch (1598:9): [True: 53.7k, False: 0]
  ------------------
 1599|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1599:3): [True: 0, False: 53.7k]
  ------------------
 1600|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1601|    629|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1601:3): [True: 629, False: 53.1k]
  ------------------
 1602|    629|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1603|  1.75k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1603:3): [True: 1.75k, False: 51.9k]
  ------------------
 1604|  1.75k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1605|    629|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1605:3): [True: 629, False: 53.1k]
  ------------------
 1606|    629|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1607|  5.48k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1607:3): [True: 5.48k, False: 48.2k]
  ------------------
 1608|  5.48k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1609|    629|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1609:3): [True: 629, False: 53.1k]
  ------------------
 1610|    629|			return coolkey_final_iterator(&priv->objects_list);
 1611|  44.6k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1611:3): [True: 44.6k, False: 9.12k]
  ------------------
 1612|  44.6k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1613|  53.7k|	}
 1614|       |
 1615|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1616|      0|}
card-coolkey.c:coolkey_get_token_info:
 1334|    629|{
 1335|    629|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    629|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1336|    629|	char *label = NULL;
 1337|    629|	char *manufacturer_id = NULL;
 1338|    629|	char *serial_number = NULL;
 1339|       |
 1340|    629|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    629|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    629|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    629|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    629|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 629]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|    629|	label = strdup((char *)priv->token_name);
 1342|    629|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1343|    629|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1344|       |
 1345|    629|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1345:6): [True: 629, False: 0]
  |  Branch (1345:15): [True: 629, False: 0]
  |  Branch (1345:34): [True: 629, False: 0]
  ------------------
 1346|    629|		free(token_info->label);
 1347|    629|		token_info->label = label;
 1348|    629|		free(token_info->manufacturer_id);
 1349|    629|		token_info->manufacturer_id = manufacturer_id;
 1350|    629|		free(token_info->serial_number);
 1351|    629|		token_info->serial_number = serial_number;
 1352|    629|		return SC_SUCCESS;
  ------------------
  |  |   28|    629|#define SC_SUCCESS				0
  ------------------
 1353|    629|	}
 1354|      0|	free(label);
 1355|      0|	free(manufacturer_id);
 1356|      0|	free(serial_number);
 1357|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1358|    629|}
card-coolkey.c:coolkey_get_manufacturer:
 1305|    629|{
 1306|    629|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1307|    629|	int i;
 1308|    629|	char *buf;
 1309|    629|	const char *manufacturer_string = "%04x Unknown";
 1310|    629|	size_t len;
 1311|    629|	int r;
 1312|       |
 1313|  3.76k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1313:12): [True: 3.13k, False: 625]
  ------------------
 1314|  3.13k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1314:7): [True: 4, False: 3.13k]
  ------------------
 1315|      4|			manufacturer_string = manufacturer_list[i].string;
 1316|      4|			break;
 1317|      4|		}
 1318|  3.13k|	}
 1319|    629|	len = strlen(manufacturer_string)+1;
 1320|    629|	buf= malloc(len);
 1321|    629|	if (buf == NULL) {
  ------------------
  |  Branch (1321:6): [True: 0, False: 629]
  ------------------
 1322|      0|		return NULL;
 1323|      0|	}
 1324|    629|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1325|    629|	if (r < 0) {
  ------------------
  |  Branch (1325:6): [True: 0, False: 629]
  ------------------
 1326|      0|		free(buf);
 1327|      0|		return NULL;
 1328|      0|	}
 1329|    629|	return buf;
 1330|    629|}
card-coolkey.c:coolkey_cuid_to_string:
 1280|    629|{
 1281|    629|	char *buf;
 1282|    629|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1283|    629|	buf = malloc(len);
 1284|    629|	if (buf == NULL) {
  ------------------
  |  Branch (1284:6): [True: 0, False: 629]
  ------------------
 1285|      0|		return NULL;
 1286|      0|	}
 1287|    629|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1288|    629|	return buf;
 1289|    629|}
card-coolkey.c:coolkey_find_object:
 1560|  1.75k|{
 1561|  1.75k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1562|  1.75k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.75k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1563|  1.75k|	int r;
 1564|       |
 1565|  1.75k|	switch (fobj->type) {
 1566|    384|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1059|    384|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1566:2): [True: 384, False: 1.36k]
  ------------------
 1567|    384|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1568|    384|		break;
 1569|  1.36k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1060|  1.36k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1569:2): [True: 1.36k, False: 384]
  ------------------
 1570|  1.36k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1571|  1.36k|		break;
 1572|      0|	default:
  ------------------
  |  Branch (1572:2): [True: 0, False: 1.75k]
  ------------------
 1573|      0|		break;
 1574|  1.75k|	}
 1575|  1.75k|	if (obj == NULL) {
  ------------------
  |  Branch (1575:6): [True: 1.07k, False: 673]
  ------------------
 1576|  1.07k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  1.07k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1577|  1.07k|	}
 1578|    673|	if (obj->data == NULL) {
  ------------------
  |  Branch (1578:6): [True: 35, False: 638]
  ------------------
 1579|     35|		r = coolkey_fill_object(card, obj);
 1580|     35|		if (r < 0) {
  ------------------
  |  Branch (1580:7): [True: 34, False: 1]
  ------------------
 1581|     34|			return r;
 1582|     34|		}
 1583|     35|	}
 1584|    639|	fobj->obj = obj;
 1585|    639|	return SC_SUCCESS;
  ------------------
  |  |   28|    639|#define SC_SUCCESS				0
  ------------------
 1586|    673|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1253|    629|{
 1254|    629|	*countp = list_size(list);
 1255|    629|	list_iterator_start(list);
 1256|    629|	return SC_SUCCESS;
  ------------------
  |  |   28|    629|#define SC_SUCCESS				0
  ------------------
 1257|    629|}
card-coolkey.c:coolkey_fetch_object:
 1261|  5.48k|{
 1262|  5.48k|	sc_cardctl_coolkey_object_t *ptr;
 1263|  5.48k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1263:6): [True: 0, False: 5.48k]
  ------------------
 1264|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1265|      0|	}
 1266|       |
 1267|  5.48k|	ptr = list_iterator_next(list);
 1268|  5.48k|	*coolkey_obj = *ptr;
 1269|  5.48k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.48k|#define SC_SUCCESS				0
  ------------------
 1270|  5.48k|}
card-coolkey.c:coolkey_final_iterator:
 1274|    629|{
 1275|    629|	list_iterator_stop(list);
 1276|    629|	return SC_SUCCESS;
  ------------------
  |  |   28|    629|#define SC_SUCCESS				0
  ------------------
 1277|    629|}
card-coolkey.c:coolkey_check_sw:
  876|  56.2k|{
  877|  56.2k|	sc_log(card->ctx,
  ------------------
  |  |   71|  56.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__
  |  |  ------------------
  ------------------
  878|  56.2k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  879|       |
  880|  56.2k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (880:6): [True: 21.3k, False: 34.9k]
  |  Branch (880:21): [True: 21.1k, False: 187]
  ------------------
  881|  21.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  21.1k|#define SC_SUCCESS				0
  ------------------
  882|       |
  883|  35.1k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (883:6): [True: 822, False: 34.3k]
  ------------------
  884|    822|		if (sw2 == 0xff) {
  ------------------
  |  Branch (884:7): [True: 13, False: 809]
  ------------------
  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|    809|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (888:7): [True: 46, False: 763]
  ------------------
  889|     46|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     46|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  890|     46|		}
  891|    763|		return coolkey_error_codes[sw2].sc_error;
  892|    809|	}
  893|       |
  894|       |	/* iso error */
  895|  34.3k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  896|  35.1k|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2427|  22.1k|{
 2428|  22.1k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  22.1k|#define SC_SUCCESS				0
  ------------------
 2429|       |
 2430|  22.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  22.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  22.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  22.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 22.1k]
  |  |  ------------------
  ------------------
 2431|       |
 2432|  22.1k|	if (was_reset > 0) {
  ------------------
  |  Branch (2432:6): [True: 0, False: 22.1k]
  ------------------
 2433|      0|		r = coolkey_select_applet(card);
 2434|      0|	}
 2435|       |
 2436|  22.1k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  22.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  22.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  22.1k|	int _ret = r; \
  |  |  |  |  155|  22.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 22.1k]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.1k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  22.1k|	return _ret; \
  |  |  |  |  163|  22.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2437|  22.1k|}

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

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

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

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

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

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

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

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

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

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

sc_get_gemsafeV1_driver:
  593|  15.0k|{
  594|  15.0k|	return sc_get_driver();
  595|  15.0k|}
card-gemsafeV1.c:sc_get_driver:
  568|  15.0k|{
  569|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  570|  15.0k|	if (!iso_ops)
  ------------------
  |  Branch (570:6): [True: 1, False: 15.0k]
  ------------------
  571|      1|		iso_ops = iso_drv->ops;
  572|       |	/* use the standard iso operations as default */
  573|  15.0k|	gemsafe_ops = *iso_drv->ops;
  574|       |	/* gemsafe specific functions */
  575|  15.0k|	gemsafe_ops.match_card	= gemsafe_match_card;
  576|  15.0k|	gemsafe_ops.init	= gemsafe_init;
  577|  15.0k|	gemsafe_ops.finish	= gemsafe_finish;
  578|  15.0k|	gemsafe_ops.select_file	= gemsafe_select_file;
  579|  15.0k|	gemsafe_ops.restore_security_env = gemsafe_restore_security_env;
  580|  15.0k|	gemsafe_ops.set_security_env     = gemsafe_set_security_env;
  581|  15.0k|	gemsafe_ops.decipher             = gemsafe_decipher;
  582|  15.0k|	gemsafe_ops.compute_signature    = gemsafe_compute_signature;
  583|  15.0k|	gemsafe_ops.get_challenge 		 = gemsafe_get_challenge;
  584|  15.0k|	gemsafe_ops.process_fci	= gemsafe_process_fci;
  585|  15.0k|	gemsafe_ops.pin_cmd		 = iso_ops->pin_cmd;
  586|  15.0k|	gemsafe_ops.card_reader_lock_obtained = gemsafe_card_reader_lock_obtained;
  587|  15.0k|	gemsafe_ops.logout = gemsafe_logout;
  588|       |
  589|  15.0k|	return &gemsafe_drv;
  590|  15.0k|}
card-gemsafeV1.c:gemsafe_match_card:
  124|  13.5k|{
  125|  13.5k|	int i;
  126|       |
  127|  13.5k|	i = _sc_match_atr(card, gemsafe_atrs, &card->type);
  128|  13.5k|	if (i < 0)
  ------------------
  |  Branch (128:6): [True: 12.7k, False: 885]
  ------------------
  129|  12.7k|		return 0;
  130|       |
  131|    885|	return 1;
  132|  13.5k|}
card-gemsafeV1.c:gemsafe_init:
  135|    885|{
  136|    885|	int	r;
  137|    885|	gemsafe_exdata *exdata = NULL;
  138|       |
  139|    885|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    885|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    885|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    885|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 885]
  |  |  ------------------
  ------------------
  140|       |
  141|    885|	card->name = "GemSAFE V1";
  142|    885|	card->cla  = 0x00;
  143|       |
  144|    885|	exdata = (gemsafe_exdata *)calloc(1, sizeof(gemsafe_exdata));
  145|    885|	if (!exdata)
  ------------------
  |  Branch (145:6): [True: 0, False: 885]
  ------------------
  146|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  147|    885|	exdata->aid_len = sizeof(exdata->aid);
  148|    885|	if(card->type == SC_CARD_TYPE_GEMSAFEV1_GENERIC) {
  ------------------
  |  Branch (148:5): [True: 1, False: 884]
  ------------------
  149|       |		/* try to get a AID from the config file */
  150|      1|		r = get_conf_aid(card, exdata->aid, &exdata->aid_len);
  151|      1|		if (r < 0) {
  ------------------
  |  Branch (151:7): [True: 1, False: 0]
  ------------------
  152|       |			/* failed, use default value */
  153|      1|			memcpy(exdata->aid, gemsafe_def_aid, sizeof(gemsafe_def_aid));
  154|      1|			exdata->aid_len = sizeof(gemsafe_def_aid);
  155|      1|		}
  156|    884|	} else if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID) {
  ------------------
  |  Branch (156:13): [True: 881, False: 3]
  ------------------
  157|    881|		memcpy(exdata->aid, gemsafe_pteid_aid, sizeof(gemsafe_pteid_aid));
  158|    881|		exdata->aid_len = sizeof(gemsafe_pteid_aid);
  159|    881|	} else if (card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (159:13): [True: 3, False: 0]
  ------------------
  160|      3|		memcpy(exdata->aid, gemsafe_seeid_aid, sizeof(gemsafe_seeid_aid));
  161|      3|		exdata->aid_len = sizeof(gemsafe_seeid_aid);
  162|      3|	}
  163|       |
  164|       |	/* increase lock_count here to prevent sc_unlock to select
  165|       |	 * applet twice in gp_select_applet */
  166|    885|	card->lock_count++;
  167|       |	/* SELECT applet */
  168|    885|	r = iso7816_select_aid(card, exdata->aid, exdata->aid_len, NULL, NULL);
  169|    885|	if (r < 0) {
  ------------------
  |  Branch (169:6): [True: 8, False: 877]
  ------------------
  170|      8|		free(exdata);
  171|      8|		sc_log(card->ctx,  "applet selection failed\n");
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  172|      8|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      8|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  173|      8|	}
  174|    877|	card->lock_count--;
  175|       |
  176|       |	/* set the supported algorithm */
  177|    877|	unsigned long flags;
  178|       |
  179|    877|	flags  = SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|    877|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    877|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|    877|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  180|    877|	flags |= SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  115|    877|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  181|    877|	flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    877|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  182|    877|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|    877|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  183|       |
  184|       |	/* GemSAFE V3 cards support SHA256 */
  185|    877|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (185:6): [True: 874, False: 3]
  ------------------
  186|      3|	    card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID)
  ------------------
  |  Branch (186:6): [True: 2, False: 1]
  ------------------
  187|    876|		flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  147|    876|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  188|       |
  189|    877|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  190|    877|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  191|    877|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  192|    877|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  193|    877|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  194|    877|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  195|       |
  196|       |	/* fake algorithm to persuade register_mechanisms()
  197|       |	 * to register these hashes */
  198|    877|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (198:6): [True: 874, False: 3]
  ------------------
  199|    876|	    card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (199:6): [True: 2, False: 1]
  ------------------
  200|    876|		flags  = SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  143|    876|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  201|    876|		flags |= SC_ALGORITHM_RSA_HASH_MD5;
  ------------------
  |  |  144|    876|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  202|    876|		flags |= SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  145|    876|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  203|    876|		flags |= SC_ALGORITHM_RSA_HASH_RIPEMD160;
  ------------------
  |  |  146|    876|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  204|       |
  205|    876|		_sc_card_add_rsa_alg(card,  512, flags, 0);
  206|    876|	}
  207|       |
  208|    877|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    877|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  209|    877|	card->drv_data = exdata;
  210|       |
  211|    877|	return SC_SUCCESS;
  ------------------
  |  |   28|    877|#define SC_SUCCESS				0
  ------------------
  212|    885|}
card-gemsafeV1.c:get_conf_aid:
   93|      1|{
   94|      1|	sc_context_t		*ctx = card->ctx;
   95|      1|	scconf_block		*conf_block, **blocks;
   96|      1|	int			i;
   97|      1|	const char		*str_aid;
   98|       |
   99|      1|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      1|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      1|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      1|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1]
  |  |  ------------------
  ------------------
  100|       |
  101|      1|	conf_block = NULL;
  102|      2|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (102:14): [True: 1, False: 1]
  ------------------
  103|      1|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  104|      1|						"card", "gemsafeV1");
  105|      1|		if (blocks != NULL && blocks[0] != NULL)
  ------------------
  |  Branch (105:7): [True: 1, False: 0]
  |  Branch (105:25): [True: 0, False: 1]
  ------------------
  106|      0|			conf_block = blocks[0];
  107|      1|		free(blocks);
  108|      1|	}
  109|       |
  110|      1|	if (!conf_block) {
  ------------------
  |  Branch (110:6): [True: 1, False: 0]
  ------------------
  111|      1|		sc_log(ctx,  "no card specific options configured, trying default AID\n");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  112|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
  113|      1|	}
  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|    877|{
  216|    877|	gemsafe_exdata *exdata = (gemsafe_exdata *)card->drv_data;
  217|       |
  218|    877|	if (exdata)
  ------------------
  |  Branch (218:6): [True: 877, False: 0]
  ------------------
  219|    877|		free(exdata);
  220|    877|	return SC_SUCCESS;
  ------------------
  |  |   28|    877|#define SC_SUCCESS				0
  ------------------
  221|    877|}
card-gemsafeV1.c:gemsafe_select_file:
  225|  7.29k|{
  226|       |	/* so far just call the iso select file (but this will change) */
  227|  7.29k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.29k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.29k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.29k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.29k]
  |  |  ------------------
  ------------------
  228|       |
  229|  7.29k|	return iso_ops->select_file(card, path, file_out);
  230|  7.29k|}
card-gemsafeV1.c:gemsafe_process_fci:
  321|  2.05k|{
  322|  2.05k|	int        r;
  323|  2.05k|	size_t     tlen;
  324|  2.05k|	const u8   *tag = NULL, *p = buf;
  325|  2.05k|	const char *type;
  326|  2.05k|	struct sc_context *ctx = card->ctx;
  327|       |
  328|  2.05k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.05k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.05k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.05k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.05k]
  |  |  ------------------
  ------------------
  329|       |
  330|  2.05k|	r = iso_ops->process_fci(card, file, buf, len);
  331|  2.05k|	if (r < 0)
  ------------------
  |  Branch (331:6): [True: 0, False: 2.05k]
  ------------------
  332|      0|		return r;
  333|  2.05k|	sc_log(ctx,
  ------------------
  |  |   71|  2.05k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  334|  2.05k|		"processing GemSAFE V1 specific FCI information\n");
  335|       |
  336|       |
  337|  2.05k|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &tlen);
  338|  2.05k|	if (!tag) {
  ------------------
  |  Branch (338:6): [True: 1.06k, False: 988]
  ------------------
  339|       |		/* no FDB => we have a DF */
  340|  1.06k|		type = "DF";
  341|  1.06k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  1.06k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  342|  1.06k|	} else {
  343|    988|		type = "EF";
  344|    988|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    988|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  345|    988|	}
  346|       |
  347|  2.05k|	sc_log(ctx,  "file type: %s\n", type);
  ------------------
  |  |   71|  2.05k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  348|       |
  349|  2.05k|	tag = sc_asn1_find_tag(ctx, p, len, 0x8C, &tlen);
  350|  2.05k|	if (tag && tlen > 1) {
  ------------------
  |  Branch (350:6): [True: 103, False: 1.95k]
  |  Branch (350:13): [True: 97, False: 6]
  ------------------
  351|     97|		r = gemsafe_setacl(card, file, tag, strcmp(type, "DF") ? 0 : 1);
  ------------------
  |  Branch (351:39): [True: 53, False: 44]
  ------------------
  352|     97|		if (r < 0) {
  ------------------
  |  Branch (352:7): [True: 0, False: 97]
  ------------------
  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|     97|	} else
  357|  1.95k|		sc_log(ctx,  "error: AM and SC bytes missing\n");
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
  358|       |
  359|  2.05k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.05k|#define SC_SUCCESS				0
  ------------------
  360|  2.05k|}
card-gemsafeV1.c:gemsafe_setacl:
  260|     97|{
  261|     97|	int       r;
  262|     97|	u8        cond;
  263|     97|	const u8 *p = data + 1;
  264|     97|	struct sc_context *ctx = card->ctx;
  265|       |
  266|     97|	if (is_df) {
  ------------------
  |  Branch (266:6): [True: 44, False: 53]
  ------------------
  267|     44|		if (*data & 0x04)	/* CREATE DF */
  ------------------
  |  Branch (267:7): [True: 26, False: 18]
  ------------------
  268|     26|			cond = *p++;
  269|     18|		else
  270|     18|			cond = 0xff;
  271|     44|		sc_log(ctx,
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  272|     44|			"DF security byte CREATE DF: %02x\n", cond);
  273|     44|		r = gemsafe_sc2acl(file, SC_AC_OP_CREATE, cond);
  ------------------
  |  |  169|     44|#define SC_AC_OP_CREATE			3
  ------------------
  274|     44|		if (r < 0)
  ------------------
  |  Branch (274:7): [True: 0, False: 44]
  ------------------
  275|      0|			return r;
  276|     44|		if (*data & 0x02)	/* CREATE EF */
  ------------------
  |  Branch (276:7): [True: 24, False: 20]
  ------------------
  277|     24|			cond = *p;
  278|     20|		else
  279|     20|			cond = 0xff;
  280|     44|		sc_log(ctx,
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  281|     44|			"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|     44|		r = gemsafe_sc2acl(file, SC_AC_OP_CREATE, cond);
  ------------------
  |  |  169|     44|#define SC_AC_OP_CREATE			3
  ------------------
  285|     44|		if (r < 0)
  ------------------
  |  Branch (285:7): [True: 0, False: 44]
  ------------------
  286|      0|			return r;
  287|     53|	} else {
  288|       |		/* XXX: ACTIVATE FILE and DEACTIVATE FILE ac are currently not
  289|       |		 * supported => ignore them */
  290|     53|		if (*data & 0x02)	/* UPDATE BINARY, ERASE BINARY */
  ------------------
  |  Branch (290:7): [True: 40, False: 13]
  ------------------
  291|     40|			cond = *p++;
  292|     13|		else
  293|     13|			cond = 0xff;
  294|     53|		sc_log(ctx,
  ------------------
  |  |   71|     53|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  295|     53|			"EF security byte UPDATE/ERASE BINARY: %02x\n", cond);
  296|     53|		r = gemsafe_sc2acl(file, SC_AC_OP_UPDATE, cond);
  ------------------
  |  |  189|     53|#define SC_AC_OP_UPDATE			23
  ------------------
  297|     53|		if (r < 0)
  ------------------
  |  Branch (297:7): [True: 0, False: 53]
  ------------------
  298|      0|			return r;
  299|     53|		r = gemsafe_sc2acl(file, SC_AC_OP_WRITE, cond);
  ------------------
  |  |  190|     53|#define SC_AC_OP_WRITE			24
  ------------------
  300|     53|		if (r < 0)
  ------------------
  |  Branch (300:7): [True: 0, False: 53]
  ------------------
  301|      0|			return r;
  302|     53|		r = gemsafe_sc2acl(file, SC_AC_OP_ERASE, cond);
  ------------------
  |  |  202|     53|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     53|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  303|     53|		if (r < 0)
  ------------------
  |  Branch (303:7): [True: 0, False: 53]
  ------------------
  304|      0|			return r;
  305|     53|		if (*data & 0x01)	/* READ BINARY */
  ------------------
  |  Branch (305:7): [True: 38, False: 15]
  ------------------
  306|     38|			cond = *p;
  307|     15|		else
  308|     15|			cond = 0xff;
  309|     53|		sc_log(ctx,
  ------------------
  |  |   71|     53|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  310|     53|			"EF security byte READ BINARY: %02x\n", cond);
  311|     53|		r = gemsafe_sc2acl(file, SC_AC_OP_READ, cond);
  ------------------
  |  |  188|     53|#define SC_AC_OP_READ			22
  ------------------
  312|     53|		if (r < 0)
  ------------------
  |  Branch (312:7): [True: 0, False: 53]
  ------------------
  313|      0|			return r;
  314|     53|	}
  315|       |
  316|     97|	return SC_SUCCESS;
  ------------------
  |  |   28|     97|#define SC_SUCCESS				0
  ------------------
  317|     97|}
card-gemsafeV1.c:gemsafe_sc2acl:
  233|    300|{
  234|    300|	int r;
  235|    300|	unsigned int meth = 0;
  236|       |
  237|    300|	if (sc_byte == 0xff) {
  ------------------
  |  Branch (237:6): [True: 98, False: 202]
  ------------------
  238|     98|		r = sc_file_add_acl_entry(file, ops, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     98|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  239|     98|		return r;
  240|     98|	}
  241|    202|	if (sc_byte == 0x00) {
  ------------------
  |  Branch (241:6): [True: 24, False: 178]
  ------------------
  242|     24|		r = sc_file_add_acl_entry(file, ops, SC_AC_NONE, 0);
  ------------------
  |  |  150|     24|#define SC_AC_NONE			0x00000000
  ------------------
  243|     24|		return r;
  244|     24|	}
  245|       |
  246|       |	/* XXX: OR combination of access rights are currently not supported
  247|       |	 * hence ignored */
  248|    178|	if (sc_byte & 0x40)
  ------------------
  |  Branch (248:6): [True: 121, False: 57]
  ------------------
  249|    121|		meth |= SC_AC_PRO;
  ------------------
  |  |  153|    121|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  250|    178|	if (sc_byte & 0x20)
  ------------------
  |  Branch (250:6): [True: 136, False: 42]
  ------------------
  251|    136|		meth |= SC_AC_AUT | SC_AC_TERM;
  ------------------
  |  |  154|    136|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
              		meth |= SC_AC_AUT | SC_AC_TERM;
  ------------------
  |  |  152|    136|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  252|    178|	if (sc_byte & 0x10)
  ------------------
  |  Branch (252:6): [True: 117, False: 61]
  ------------------
  253|    117|		meth |= SC_AC_CHV;
  ------------------
  |  |  151|    117|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  254|       |
  255|    178|	return sc_file_add_acl_entry(file, ops, meth, sc_byte & 0x0f);
  256|    202|}
card-gemsafeV1.c:gemsafe_card_reader_lock_obtained:
  547|    877|{
  548|    877|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    877|#define SC_SUCCESS				0
  ------------------
  549|    877|	gemsafe_exdata *exdata = (gemsafe_exdata *)card->drv_data;
  550|       |
  551|    877|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    877|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    877|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    877|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 877]
  |  |  ------------------
  ------------------
  552|       |
  553|    877|	if (was_reset > 0 && exdata) {
  ------------------
  |  Branch (553:6): [True: 0, False: 877]
  |  Branch (553:23): [True: 0, False: 0]
  ------------------
  554|      0|		r = iso7816_select_aid(card, exdata->aid, exdata->aid_len, NULL, NULL);
  555|      0|	}
  556|       |
  557|    877|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    877|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    877|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    877|	int _ret = r; \
  |  |  |  |  155|    877|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 877, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    877|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 877]
  |  |  |  |  ------------------
  |  |  |  |  157|    877|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    877|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    877|	return _ret; \
  |  |  |  |  163|    877|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  558|    877|}

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

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

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

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

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

jpki_select_ap:
   46|  2.70k|{
   47|  2.70k|	int rc;
   48|  2.70k|	sc_path_t path;
   49|       |
   50|  2.70k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.70k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.70k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.70k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.70k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.70k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   51|       |
   52|       |	/* Select JPKI application */
   53|  2.70k|	sc_format_path(AID_JPKI, &path);
  ------------------
  |  |   27|  2.70k|#define AID_JPKI "D392f000260100000001"
  ------------------
   54|  2.70k|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.70k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   55|  2.70k|	rc = sc_select_file(card, &path, NULL);
   56|  2.70k|	LOG_TEST_RET(card->ctx, rc, "select JPKI AP failed");
  ------------------
  |  |  174|  2.70k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.70k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.70k|	int _ret = (r); \
  |  |  |  |  168|  2.70k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.62k, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.62k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.62k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.62k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.62k|		return _ret; \
  |  |  |  |  172|  2.62k|	} \
  |  |  |  |  173|  2.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 87]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   57|       |
   58|     87|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     87|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     87|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     87|	int _ret = r; \
  |  |  |  |  155|     87|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 87, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     87|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  157|     87|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     87|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     87|	return _ret; \
  |  |  |  |  163|     87|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|     87|}
sc_get_jpki_driver:
  388|  15.0k|{
  389|  15.0k|	return sc_get_driver();
  390|  15.0k|}
card-jpki.c:sc_get_driver:
  369|  15.0k|{
  370|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  371|       |
  372|  15.0k|	jpki_ops = *iso_drv->ops;
  373|  15.0k|	jpki_ops.match_card = jpki_match_card;
  374|  15.0k|	jpki_ops.init = jpki_init;
  375|  15.0k|	jpki_ops.finish = jpki_finish;
  376|  15.0k|	jpki_ops.select_file = jpki_select_file;
  377|  15.0k|	jpki_ops.pin_cmd = jpki_pin_cmd;
  378|  15.0k|	jpki_ops.set_security_env = jpki_set_security_env;
  379|  15.0k|	jpki_ops.compute_signature = jpki_compute_signature;
  380|  15.0k|	jpki_ops.card_reader_lock_obtained = jpki_card_reader_lock_obtained;
  381|  15.0k|	jpki_ops.logout = jpki_logout;
  382|       |
  383|  15.0k|	return &jpki_drv;
  384|  15.0k|}
card-jpki.c:jpki_match_card:
   63|  2.66k|{
   64|  2.66k|	int i, rc;
   65|       |
   66|  2.66k|	i = _sc_match_atr(card, jpki_atrs, &card->type);
   67|  2.66k|	if (i >= 0) {
  ------------------
  |  Branch (67:6): [True: 1, False: 2.65k]
  ------------------
   68|      1|		return 1;
   69|      1|	}
   70|       |
   71|  2.65k|	rc = jpki_select_ap(card);
   72|  2.65k|	if (rc == SC_SUCCESS) {
  ------------------
  |  |   28|  2.65k|#define SC_SUCCESS				0
  ------------------
  |  Branch (72:6): [True: 48, False: 2.61k]
  ------------------
   73|     48|		card->type = SC_CARD_TYPE_JPKI_BASE;
   74|     48|		return 1;
   75|     48|	}
   76|  2.61k|	return 0;
   77|  2.65k|}
card-jpki.c:jpki_init:
   97|     49|{
   98|     49|	struct jpki_private_data *drvdata;
   99|     49|	sc_file_t *mf;
  100|     49|	int flags;
  101|       |
  102|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  103|       |
  104|     49|	drvdata = malloc(sizeof (struct jpki_private_data));
  105|     49|	if (!drvdata)
  ------------------
  |  Branch (105:6): [True: 0, False: 49]
  ------------------
  106|     49|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|       |
  108|     49|	memset(drvdata, 0, sizeof (struct jpki_private_data));
  109|       |
  110|       |	/* create virtual MF */
  111|     49|	mf = sc_file_new();
  112|     49|	if (!mf) {
  ------------------
  |  Branch (112:6): [True: 0, False: 49]
  ------------------
  113|      0|		free(drvdata);
  114|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  115|      0|	}
  116|     49|	sc_format_path("3f00", &mf->path);
  117|     49|	mf->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     49|#define SC_FILE_TYPE_DF			0x04
  ------------------
  118|     49|	mf->shareable = 0;
  119|     49|	mf->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     49|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  120|     49|	mf->size = 0;
  121|     49|	mf->id = 0x3f00;
  122|     49|	mf->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     49|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  123|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_SELECT, SC_AC_NONE, 0);
  ------------------
  |  |  166|     49|#define SC_AC_OP_SELECT			0
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_SELECT, SC_AC_NONE, 0);
  ------------------
  |  |  150|     49|#define SC_AC_NONE			0x00000000
  ------------------
  124|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_LIST_FILES, SC_AC_NONE, 0);
  ------------------
  |  |  172|     49|#define SC_AC_OP_LIST_FILES		6
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_LIST_FILES, SC_AC_NONE, 0);
  ------------------
  |  |  150|     49|#define SC_AC_NONE			0x00000000
  ------------------
  125|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_LOCK, SC_AC_NEVER, 0);
  ------------------
  |  |  167|     49|#define SC_AC_OP_LOCK			1
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_LOCK, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     49|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  126|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_DELETE, SC_AC_NEVER, 0);
  ------------------
  |  |  168|     49|#define SC_AC_OP_DELETE			2
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_DELETE, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     49|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  127|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_CREATE, SC_AC_NEVER, 0);
  ------------------
  |  |  169|     49|#define SC_AC_OP_CREATE			3
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_CREATE, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     49|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  128|     49|	drvdata->mf = mf;
  129|     49|	drvdata->selected = SELECT_MF;
  ------------------
  |  |   24|     49|#define SELECT_MF 0
  ------------------
  130|       |
  131|     49|	card->name = "jpki";
  132|     49|	card->drv_data = drvdata;
  133|       |
  134|     49|	flags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  142|     49|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	flags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  135|     49|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  136|       |
  137|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|     49|}
card-jpki.c:jpki_finish:
   81|     49|{
   82|     49|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|     49|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
   83|       |
   84|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|     49|	if (drvdata) {
  ------------------
  |  Branch (85:6): [True: 49, False: 0]
  ------------------
   86|     49|		if (drvdata->mf) {
  ------------------
  |  Branch (86:7): [True: 49, False: 0]
  ------------------
   87|     49|			free(drvdata->mf);
   88|     49|		}
   89|     49|		free(drvdata);
   90|     49|		card->drv_data = NULL;
   91|     49|	}
   92|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   93|     49|}
card-jpki.c:jpki_select_file:
  143|  3.04k|{
  144|  3.04k|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|  3.04k|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
  145|  3.04k|	int rc;
  146|  3.04k|	sc_apdu_t apdu;
  147|  3.04k|	struct sc_file *file = NULL;
  148|       |
  149|  3.04k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.04k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.04k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|  3.04k|	sc_log(card->ctx,
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  151|  3.04k|	       "jpki_select_file: path=%s, len=%"SC_FORMAT_LEN_SIZE_T"u",
  152|  3.04k|	       sc_print_path(path), path->len);
  153|  3.04k|	if (path->len == 2 && memcmp(path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (153:6): [True: 121, False: 2.92k]
  |  Branch (153:24): [True: 0, False: 121]
  ------------------
  154|      0|		drvdata->selected = SELECT_MF;
  ------------------
  |  |   24|      0|#define SELECT_MF 0
  ------------------
  155|      0|		if (file_out) {
  ------------------
  |  Branch (155:7): [True: 0, False: 0]
  ------------------
  156|      0|			sc_file_dup(file_out, drvdata->mf);
  157|      0|			if (*file_out == NULL) {
  ------------------
  |  Branch (157:8): [True: 0, False: 0]
  ------------------
  158|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|      0|			}
  160|      0|		}
  161|      0|		return 0;
  162|      0|	}
  163|       |
  164|  3.04k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  293|  3.04k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  165|  3.04k|	switch (path->type) {
  166|    114|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|    114|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (166:2): [True: 114, False: 2.92k]
  ------------------
  167|    114|		apdu.p1 = 2;
  168|    114|		break;
  169|  2.77k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  2.77k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (169:2): [True: 2.77k, False: 268]
  ------------------
  170|  2.77k|		apdu.p1 = 4;
  171|  2.77k|		break;
  172|    154|	default:
  ------------------
  |  Branch (172:2): [True: 154, False: 2.88k]
  ------------------
  173|    154|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    154|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    154|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    154|	int _ret = r; \
  |  |  |  |  155|    154|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 154, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    154|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    154|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 154, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    154|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    154|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    154|	return _ret; \
  |  |  |  |  163|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|  3.04k|	}
  175|  2.88k|	apdu.p2 = 0x0C;
  176|  2.88k|	apdu.data = path->value;
  177|  2.88k|	apdu.datalen = path->len;
  178|  2.88k|	apdu.lc = path->len;
  179|       |
  180|  2.88k|	rc = sc_transmit_apdu(card, &apdu);
  181|  2.88k|	LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|  2.88k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.88k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.88k|	int _ret = (r); \
  |  |  |  |  168|  2.88k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 2.87k]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|  2.88k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|  2.87k|	rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  183|  2.87k|	LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|  2.87k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.87k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.87k|	int _ret = (r); \
  |  |  |  |  168|  2.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.67k, False: 194]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.67k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.67k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.67k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.67k|		return _ret; \
  |  |  |  |  172|  2.67k|	} \
  |  |  |  |  173|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 194]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|    194|	if (!file_out) {
  ------------------
  |  Branch (184:6): [True: 168, False: 26]
  ------------------
  185|    168|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    168|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    168|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    168|	int _ret = r; \
  |  |  |  |  155|    168|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 168, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    168|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 168]
  |  |  |  |  ------------------
  |  |  |  |  157|    168|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    168|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    168|	return _ret; \
  |  |  |  |  163|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  186|    168|	}
  187|       |
  188|       |	/* read certificate file size */
  189|     26|	if (path->len == 2 && (
  ------------------
  |  Branch (189:6): [True: 26, False: 0]
  ------------------
  190|     26|		    memcmp(path->value, "\x00\x0A", 2) == 0 ||
  ------------------
  |  Branch (190:7): [True: 16, False: 10]
  ------------------
  191|     10|		    memcmp(path->value, "\x00\x01", 2) == 0 ||
  ------------------
  |  Branch (191:7): [True: 10, False: 0]
  ------------------
  192|      0|		    memcmp(path->value, "\x00\x0B", 2) == 0 ||
  ------------------
  |  Branch (192:7): [True: 0, False: 0]
  ------------------
  193|      0|		    memcmp(path->value, "\x00\x02", 2) == 0 )
  ------------------
  |  Branch (193:7): [True: 0, False: 0]
  ------------------
  194|     26|		) {
  195|     26|		u8 buf[4];
  196|     26|		rc = sc_read_binary(card, 0, buf, 4, 0);
  197|     26|		LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|     26|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     26|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     26|	int _ret = (r); \
  |  |  |  |  168|     26|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|     17|		if (rc < 4)
  ------------------
  |  Branch (198:7): [True: 3, False: 14]
  ------------------
  199|     17|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|     14|		file = sc_file_new();
  201|     14|		if (!file) {
  ------------------
  |  Branch (201:7): [True: 0, False: 14]
  ------------------
  202|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  203|      0|		}
  204|     14|		file->path = *path;
  205|     14|		file->size = (buf[2] << 8 | buf[3]) + 4;
  206|     14|		*file_out = file;
  207|     14|	}
  208|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  209|     14|}
card-jpki.c:jpki_pin_cmd:
  213|     74|{
  214|     74|	int rc;
  215|     74|	sc_path_t path;
  216|     74|	sc_apdu_t apdu;
  217|     74|	struct jpki_private_data *priv = JPKI_DRVDATA(card);
  ------------------
  |  |   36|     74|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
  218|     74|	int max_tries = 0;
  219|       |
  220|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  221|       |
  222|     74|	switch (data->pin_reference) {
  223|     39|	case 1:
  ------------------
  |  Branch (223:2): [True: 39, False: 35]
  ------------------
  224|     39|		sc_format_path(JPKI_AUTH_PIN, &path);
  ------------------
  |  |   29|     39|#define JPKI_AUTH_PIN "0018"
  ------------------
  225|     39|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     39|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  226|     39|		rc = sc_select_file(card, &path, NULL);
  227|     39|		max_tries = JPKI_AUTH_PIN_MAX_TRIES;
  ------------------
  |  |   30|     39|#define JPKI_AUTH_PIN_MAX_TRIES 3
  ------------------
  228|     39|		break;
  229|     35|	case 2:
  ------------------
  |  Branch (229:2): [True: 35, False: 39]
  ------------------
  230|     35|		sc_format_path(JPKI_SIGN_PIN, &path);
  ------------------
  |  |   33|     35|#define JPKI_SIGN_PIN "001B"
  ------------------
  231|     35|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     35|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  232|     35|		rc = sc_select_file(card, &path, NULL);
  233|     35|		max_tries = JPKI_SIGN_PIN_MAX_TRIES;
  ------------------
  |  |   34|     35|#define JPKI_SIGN_PIN_MAX_TRIES 5
  ------------------
  234|     35|		break;
  235|      0|	default:
  ------------------
  |  Branch (235:2): [True: 0, False: 74]
  ------------------
  236|      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__
  |  |  ------------------
  ------------------
  237|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  238|     74|	}
  239|     74|	LOG_TEST_RET(card->ctx, rc, "SELECT_FILE error");
  ------------------
  |  |  174|     74|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     74|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     74|	int _ret = (r); \
  |  |  |  |  168|     74|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 58]
  |  |  |  |  ------------------
  |  |  |  |  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|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 58]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|       |
  241|     58|	switch (data->cmd) {
  242|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (242:2): [True: 0, False: 58]
  ------------------
  243|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
  244|      0|		if (data->pin1.len == 0 && !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (244:7): [True: 0, False: 0]
  |  Branch (244:30): [True: 0, False: 0]
  ------------------
  245|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0x20, 0x00, 0x80);
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
  247|      0|		apdu.data = data->pin1.data;
  248|      0|		apdu.datalen = data->pin1.len;
  249|      0|		apdu.lc = data->pin1.len;
  250|      0|		rc = sc_transmit_apdu(card, &apdu);
  251|      0|		LOG_TEST_RET(card->ctx, rc, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|      0|		rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  253|      0|		if (rc == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (253:7): [True: 0, False: 0]
  ------------------
  254|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  255|      0|			data->pin1.tries_left = max_tries;
  256|      0|		} else {
  257|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
  258|      0|			data->pin1.tries_left = apdu.sw2 & 0xF;
  259|      0|		}
  260|      0|		priv->logged_in = data->pin1.logged_in;
  261|      0|		LOG_TEST_RET(card->ctx, rc, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|      0|		break;
  263|     58|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|     58|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (263:2): [True: 58, False: 0]
  ------------------
  264|     58|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0x00, 0x80);
  ------------------
  |  |  291|     58|#define SC_APDU_CASE_1			0x01
  ------------------
  265|     58|		rc = sc_transmit_apdu(card, &apdu);
  266|     58|		LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  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: 3, False: 55]
  |  |  |  |  ------------------
  |  |  |  |  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|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 55]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  267|     55|		if (apdu.sw1 != 0x63) {
  ------------------
  |  Branch (267:7): [True: 7, False: 48]
  ------------------
  268|      7|			sc_log(card->ctx, "VERIFY GET_INFO error");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  269|      7|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  270|      7|		}
  271|     48|		data->pin1.logged_in = priv->logged_in;
  272|     48|		data->pin1.tries_left = apdu.sw2 & 0xF;
  273|     48|		break;
  274|      0|	default:
  ------------------
  |  Branch (274:2): [True: 0, False: 58]
  ------------------
  275|      0|		sc_log(card->ctx, "Card does not support PIN command: %d", data->cmd);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  276|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  277|     58|	}
  278|       |
  279|     48|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     48|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     48|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     48|	int _ret = r; \
  |  |  |  |  155|     48|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 48, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     48|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  157|     48|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     48|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     48|	return _ret; \
  |  |  |  |  163|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|     48|}
card-jpki.c:jpki_card_reader_lock_obtained:
  350|  2.74k|{
  351|  2.74k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.74k|#define SC_SUCCESS				0
  ------------------
  352|       |
  353|  2.74k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.74k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.74k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.74k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.74k]
  |  |  ------------------
  ------------------
  354|       |
  355|  2.74k|	if (was_reset > 0) {
  ------------------
  |  Branch (355:6): [True: 0, False: 2.74k]
  ------------------
  356|      0|		r = jpki_select_ap(card);
  357|      0|	}
  358|       |
  359|  2.74k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.74k|	int _ret = r; \
  |  |  |  |  155|  2.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.74k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.74k|	return _ret; \
  |  |  |  |  163|  2.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|  2.74k|}

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

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

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

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

sc_get_myeid_driver:
 2133|  15.0k|{
 2134|  15.0k|	return sc_get_driver();
 2135|  15.0k|}
card-myeid.c:sc_get_driver:
 2098|  15.0k|{
 2099|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2100|       |
 2101|  15.0k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2101:6): [True: 1, False: 15.0k]
  ------------------
 2102|      1|		iso_ops = iso_drv->ops;
 2103|       |
 2104|  15.0k|	myeid_ops			= *iso_drv->ops;
 2105|  15.0k|	myeid_ops.match_card		= myeid_match_card;
 2106|  15.0k|	myeid_ops.init			= myeid_init;
 2107|  15.0k|	myeid_ops.finish		= myeid_finish;
 2108|       |	/* no record oriented file services */
 2109|  15.0k|	myeid_ops.read_record		= NULL;
 2110|  15.0k|	myeid_ops.write_record		= NULL;
 2111|  15.0k|	myeid_ops.append_record		= NULL;
 2112|       |	myeid_ops.update_record		= NULL;
 2113|  15.0k|	myeid_ops.select_file		= myeid_select_file;
 2114|  15.0k|	myeid_ops.get_response		= iso_ops->get_response;
 2115|  15.0k|	myeid_ops.logout		= myeid_logout;
 2116|  15.0k|	myeid_ops.create_file		= myeid_create_file;
 2117|  15.0k|	myeid_ops.delete_file		= myeid_delete_file;
 2118|  15.0k|	myeid_ops.list_files		= myeid_list_files;
 2119|  15.0k|	myeid_ops.set_security_env	= myeid_set_security_env;
 2120|  15.0k|	myeid_ops.compute_signature	= myeid_compute_signature;
 2121|  15.0k|	myeid_ops.decipher		= myeid_decipher;
 2122|  15.0k|	myeid_ops.process_fci		= myeid_process_fci;
 2123|  15.0k|	myeid_ops.card_ctl		= myeid_card_ctl;
 2124|  15.0k|	myeid_ops.pin_cmd		= myeid_pin_cmd;
 2125|  15.0k|	myeid_ops.wrap			= myeid_wrap_key;
 2126|  15.0k|	myeid_ops.unwrap		= myeid_unwrap_key;
 2127|  15.0k|	myeid_ops.encrypt_sym		= myeid_encrypt_sym;
 2128|  15.0k|	myeid_ops.decrypt_sym		= myeid_decrypt_sym;
 2129|  15.0k|	return &myeid_drv;
 2130|  15.0k|}
card-myeid.c:myeid_match_card:
  122|  8.30k|{
  123|  8.30k|	size_t len = card->reader->atr_info.hist_bytes_len;
  124|       |	/* Normally the historical bytes are exactly "MyEID", but there might
  125|       |	 * be some historic units which have a small prefix byte sequence. */
  126|  8.30k|	if (len >= 5) {
  ------------------
  |  Branch (126:6): [True: 3.14k, False: 5.16k]
  ------------------
  127|  3.14k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "MyEID", 5)) {
  ------------------
  |  Branch (127:7): [True: 146, False: 3.00k]
  ------------------
  128|    146|			sc_log(card->ctx, "Matched MyEID card");
  ------------------
  |  |   71|    146|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|    146|			card->type = SC_CARD_TYPE_MYEID_GENERIC;
  130|    146|			return 1;
  131|    146|		}
  132|       |		/* The software implementation of MyEID is identified by OsEID bytes */
  133|  3.00k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "OsEID", 5)) {
  ------------------
  |  Branch (133:7): [True: 22, False: 2.98k]
  ------------------
  134|     22|			sc_log(card->ctx, "Matched OsEID card");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  135|     22|			card->type = SC_CARD_TYPE_MYEID_OSEID;
  136|     22|			return 1;
  137|     22|		}
  138|  3.00k|	}
  139|  8.14k|	return 0;
  140|  8.30k|}
card-myeid.c:myeid_init:
  171|    168|{
  172|    168|	unsigned long flags = 0, ext_flags = 0;
  173|    168|	myeid_private_data_t *priv;
  174|    168|	u8 appletInfo[20];
  175|    168|	size_t appletInfoLen;
  176|    168|	myeid_card_caps_t card_caps;
  177|    168|	static struct sc_aid myeid_aid = { "\xA0\x00\x00\x00\x63\x50\x4B\x43\x53\x2D\x31\x35", 0x0C };
  178|    168|	int rv = 0;
  179|    168|	void *old_drv_data = card->drv_data;
  180|       |
  181|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|       |
  183|    168|	switch (card->type) {
  184|     22|	case SC_CARD_TYPE_MYEID_OSEID:
  ------------------
  |  Branch (184:2): [True: 22, False: 146]
  ------------------
  185|     22|		card->name = oseid_card_name;
  186|     22|		break;
  187|    146|	case SC_CARD_TYPE_MYEID_GENERIC:
  ------------------
  |  Branch (187:2): [True: 146, False: 22]
  ------------------
  188|    146|		card->name = myeid_card_name;
  189|    146|		break;
  190|      0|	default:
  ------------------
  |  Branch (190:2): [True: 0, False: 168]
  ------------------
  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|    168|	}
  193|       |
  194|    168|	priv = calloc(1, sizeof(myeid_private_data_t));
  195|       |
  196|    168|	if (!priv)
  ------------------
  |  Branch (196:6): [True: 0, False: 168]
  ------------------
  197|    168|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|    168|	rv = myeid_load_options (card->ctx, priv);
  200|    168|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Unable to read options from opensc.conf");
  ------------------
  |  |  184|    168|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    168|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    168|	int _ret = (r); \
  |  |  |  |  178|    168|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 168]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 168]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|    168|	priv->card_state = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|    168|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  203|    168|	card->drv_data = priv;
  204|       |
  205|       |	/* Ensure that the MyEID applet is selected. */
  206|    168|	rv = iso7816_select_aid(card, myeid_aid.value, myeid_aid.len, NULL, NULL);
  207|    168|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Failed to select MyEID applet.");
  ------------------
  |  |  184|    168|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    168|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    168|	int _ret = (r); \
  |  |  |  |  178|    168|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 10, False: 158]
  |  |  |  |  ------------------
  |  |  |  |  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|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 158]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  208|       |
  209|       |	/* find out MyEID version */
  210|       |
  211|    158|	appletInfoLen = 20;
  212|       |
  213|    158|	if (0 > myeid_get_info(card, appletInfo, appletInfoLen))
  ------------------
  |  Branch (213:6): [True: 79, False: 79]
  ------------------
  214|    158|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to get MyEID applet information.");
  ------------------
  |  |  184|     79|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     79|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     79|	int _ret = (r); \
  |  |  |  |  178|     79|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 79, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     79|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     79|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     79|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     79|		goto err; \
  |  |  |  |  182|     79|	} \
  |  |  |  |  183|     79|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|       |
  216|     79|	priv->change_counter = appletInfo[19] | appletInfo[18] << 8;
  217|       |
  218|     79|	memset(&card_caps, 0, sizeof(myeid_card_caps_t));
  219|     79|	card_caps.max_ecc_key_length = 256;
  220|     79|	card_caps.max_rsa_key_length = 2048;
  221|       |
  222|     79|	if (card->version.fw_major >= 40) {
  ------------------
  |  Branch (222:6): [True: 70, False: 9]
  ------------------
  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|     70|	    if (myeid_get_card_caps(card, &card_caps) != SC_SUCCESS) {
  ------------------
  |  |   28|     70|#define SC_SUCCESS				0
  ------------------
  |  Branch (225:10): [True: 24, False: 46]
  ------------------
  226|     24|			sc_log(card->ctx, "Failed to get card capabilities. Using default max ECC key length 256.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  227|     24|	    }
  228|     70|	}
  229|       |
  230|     79|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|     79|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     79|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  231|     79|	if (priv->disable_hw_pkcs1_padding == 0)
  ------------------
  |  Branch (231:6): [True: 79, False: 0]
  ------------------
  232|     79|		flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|     79|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|     79|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|     79|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  233|     79|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|     79|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  234|       |
  235|     79|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  236|     79|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  237|     79|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  238|     79|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
  239|     79|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  240|       |
  241|     79|	if (card_caps.card_supported_features & MYEID_CARD_CAP_RSA) {
  ------------------
  |  |   50|     79|#define MYEID_CARD_CAP_RSA		0x01
  ------------------
  |  Branch (241:6): [True: 43, False: 36]
  ------------------
  242|     43|		if (card_caps.max_rsa_key_length >= 3072)
  ------------------
  |  Branch (242:7): [True: 31, False: 12]
  ------------------
  243|     31|			_sc_card_add_rsa_alg(card, 3072, flags, 0);
  244|     43|		if (card_caps.max_rsa_key_length >= 4096)
  ------------------
  |  Branch (244:7): [True: 24, False: 19]
  ------------------
  245|     24|			_sc_card_add_rsa_alg(card, 4096, flags, 0);
  246|     43|	}
  247|       |
  248|       |	/* show ECC algorithms if the applet version of the inserted card supports them */
  249|     79|	if (card->version.fw_major >= 35) {
  ------------------
  |  Branch (249:6): [True: 73, False: 6]
  ------------------
  250|     73|		int i;
  251|       |
  252|     73|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  183|     73|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  182|     73|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     73|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  253|     73|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|     73|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|     73|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  254|     73|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|     73|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|     73|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  255|       |
  256|    365|		for (i=0; ec_curves[i].curve_name != NULL; i++) {
  ------------------
  |  Branch (256:13): [True: 292, False: 73]
  ------------------
  257|    292|			if (card_caps.max_ecc_key_length >= ec_curves[i].size)
  ------------------
  |  Branch (257:8): [True: 203, False: 89]
  ------------------
  258|    203|				_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].curve_oid);
  259|    292|		}
  260|     73|	}
  261|       |
  262|       |	/* show supported symmetric algorithms */
  263|     79|	flags = 0;
  264|     79|	if (card_caps.card_supported_features & MYEID_CARD_CAP_3DES) {
  ------------------
  |  |   51|     79|#define MYEID_CARD_CAP_3DES		0x02
  ------------------
  |  Branch (264:6): [True: 41, False: 38]
  ------------------
  265|     41|		if (card_caps.max_des_key_length >= 64)
  ------------------
  |  Branch (265:7): [True: 32, False: 9]
  ------------------
  266|     32|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_DES, 64, flags);
  ------------------
  |  |   85|     32|#define SC_ALGORITHM_DES		64
  ------------------
  267|     41|		if (card_caps.max_des_key_length >= 128)
  ------------------
  |  Branch (267:7): [True: 30, False: 11]
  ------------------
  268|     30|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 128, flags);
  ------------------
  |  |   86|     30|#define SC_ALGORITHM_3DES		65
  ------------------
  269|     41|		if (card_caps.max_des_key_length >= 192)
  ------------------
  |  Branch (269:7): [True: 25, False: 16]
  ------------------
  270|     25|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 192, flags);
  ------------------
  |  |   86|     25|#define SC_ALGORITHM_3DES		65
  ------------------
  271|     41|	}
  272|     79|	if (card_caps.card_supported_features & MYEID_CARD_CAP_AES) {
  ------------------
  |  |   52|     79|#define MYEID_CARD_CAP_AES		0x04
  ------------------
  |  Branch (272:6): [True: 37, False: 42]
  ------------------
  273|     37|		if (card_caps.max_aes_key_length >= 128)
  ------------------
  |  Branch (273:7): [True: 29, False: 8]
  ------------------
  274|     29|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 128, flags);
  ------------------
  |  |   88|     29|#define SC_ALGORITHM_AES		67
  ------------------
  275|     37|		if (card_caps.max_aes_key_length >= 256)
  ------------------
  |  Branch (275:7): [True: 23, False: 14]
  ------------------
  276|     23|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 256, flags);
  ------------------
  |  |   88|     23|#define SC_ALGORITHM_AES		67
  ------------------
  277|     37|	}
  278|       |
  279|       |	/* State that we have an RNG */
  280|     79|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  557|     79|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|     79|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  281|       |
  282|     79|	if ((card->version.fw_major == 40 && card->version.fw_minor >= 10 )
  ------------------
  |  Branch (282:7): [True: 5, False: 74]
  |  Branch (282:39): [True: 2, False: 3]
  ------------------
  283|     77|		|| card->version.fw_major >= 41)
  ------------------
  |  Branch (283:6): [True: 65, False: 12]
  ------------------
  284|     67|		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  579|     67|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
              		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  581|     67|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
  285|     67|			   | SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |  576|     67|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
  286|       |
  287|     79|	if (card->version.fw_major >= 45)
  ------------------
  |  Branch (287:6): [True: 63, False: 16]
  ------------------
  288|     63|		priv->cap_chaining = 1;
  289|     79|	if (card->version.fw_major >= 40)
  ------------------
  |  Branch (289:6): [True: 70, False: 9]
  ------------------
  290|     70|		card->max_recv_size = 256;
  291|      9|	else
  292|      9|		card->max_recv_size = 255;
  293|     79|	card->max_send_size = 255;
  294|       |
  295|     79|	rv = SC_SUCCESS;
  ------------------
  |  |   28|     79|#define SC_SUCCESS				0
  ------------------
  296|       |
  297|    168|err:
  298|    168|	if (rv < 0) {
  ------------------
  |  Branch (298:6): [True: 10, False: 158]
  ------------------
  299|     10|		free(priv);
  300|     10|		card->drv_data = old_drv_data;
  301|     10|	}
  302|       |
  303|    168|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    168|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    168|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    168|	int _ret = r; \
  |  |  |  |  155|    168|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 168, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    168|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 158]
  |  |  |  |  ------------------
  |  |  |  |  157|    168|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    168|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    168|	return _ret; \
  |  |  |  |  163|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|    168|}
card-myeid.c:myeid_load_options:
  143|    168|{
  144|    168|	int r;
  145|    168|	size_t i, j;
  146|    168|	scconf_block **found_blocks, *block;
  147|       |
  148|    168|	if (!ctx || !priv) {
  ------------------
  |  Branch (148:6): [True: 0, False: 168]
  |  Branch (148:14): [True: 0, False: 168]
  ------------------
  149|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  150|      0|		goto err;
  151|      0|	}
  152|    168|	priv->disable_hw_pkcs1_padding = 0;
  153|    336|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (153:14): [True: 168, False: 168]
  ------------------
  154|    168|		found_blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  155|    168|				"card_driver", "myeid");
  156|    168|		if (!found_blocks)
  ------------------
  |  Branch (156:7): [True: 0, False: 168]
  ------------------
  157|      0|			continue;
  158|    168|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (158:40): [True: 0, False: 168]
  ------------------
  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|    168|		free(found_blocks);
  163|    168|	}
  164|    168|	r = SC_SUCCESS;
  ------------------
  |  |   28|    168|#define SC_SUCCESS				0
  ------------------
  165|       |
  166|    168|err:
  167|    168|	return r;
  168|    168|}
card-myeid.c:myeid_get_info:
 1690|    171|{
 1691|    171|	sc_apdu_t apdu;
 1692|    171|	int r;
 1693|       |
 1694|    171|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1695|       |
 1696|    171|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xA0);
  ------------------
  |  |  292|    171|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1697|    171|	apdu.resp    = rbuf;
 1698|    171|	apdu.resplen = buflen;
 1699|    171|	apdu.le      = buflen;
 1700|       |
 1701|    171|	r = sc_transmit_apdu(card, &apdu);
 1702|    171|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|    171|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    171|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    171|	int _ret = (r); \
  |  |  |  |  168|    171|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  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|    171|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1703|       |
 1704|    159|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1704:6): [True: 61, False: 98]
  |  Branch (1704:26): [True: 8, False: 90]
  ------------------
 1705|     69|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     69|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1706|       |
 1707|     90|	if (apdu.resplen != 20)
  ------------------
  |  Branch (1707:6): [True: 9, False: 81]
  ------------------
 1708|      9|	{
 1709|      9|		sc_log(card->ctx, "Unexpected response to GET DATA (applet info)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1710|      9|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      9|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1711|      9|	}
 1712|       |
 1713|       |	/* store the applet version */
 1714|     81|	card->version.fw_major = rbuf[5] * 10 + rbuf[6];
 1715|     81|	card->version.fw_minor = rbuf[7];
 1716|       |	/* add version to name */
 1717|     81|	snprintf(card_name_buf, sizeof(card_name_buf),
 1718|     81|			"%s %d.%d.%d", card->name, rbuf[5], rbuf[6], rbuf[7]);
 1719|     81|	card->name = card_name_buf;
 1720|       |
 1721|     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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1722|     81|}
card-myeid.c:myeid_get_card_caps:
 1773|     70|{
 1774|     70|	sc_apdu_t apdu;
 1775|     70|	int r;
 1776|     70|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1777|       |
 1778|     70|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     70|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     70|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     70|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     70|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 70]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|       |
 1780|     70|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xAA);
  ------------------
  |  |  292|     70|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1781|     70|	apdu.resp    = rbuf;
 1782|     70|	apdu.resplen = sizeof(myeid_card_caps_t);
 1783|     70|	apdu.le      = sizeof(myeid_card_caps_t);
 1784|       |
 1785|     70|	r = sc_transmit_apdu(card, &apdu);
 1786|     70|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|     70|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     70|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     70|	int _ret = (r); \
  |  |  |  |  168|     70|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1787|       |
 1788|     69|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1788:6): [True: 18, False: 51]
  |  Branch (1788:26): [True: 3, False: 48]
  ------------------
 1789|     21|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     21|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1790|       |
 1791|     48|	if (apdu.resplen < 11) {
  ------------------
  |  Branch (1791:6): [True: 2, False: 46]
  ------------------
 1792|      2|		sc_log(card->ctx, "Unexpected response to GET DATA (MyEIC card capabilities)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1793|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1794|      2|	}
 1795|       |
 1796|     46|	card_caps->card_caps_ver = rbuf[0];
 1797|       |	/* the card returns big endian values */
 1798|     46|	card_caps->card_supported_features = (unsigned short) rbuf[1] << 8 | rbuf[2];
 1799|     46|	card_caps->max_rsa_key_length = (unsigned short) rbuf[3] << 8 | rbuf[4];
 1800|     46|	card_caps->max_des_key_length = (unsigned short) rbuf[5] << 8 | rbuf[6];
 1801|     46|	card_caps->max_aes_key_length = (unsigned short) rbuf[7] << 8 | rbuf[8];
 1802|     46|	card_caps->max_ecc_key_length = (unsigned short) rbuf[9] << 8 | rbuf[10];
 1803|       |
 1804|     46|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     46|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     46|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     46|	int _ret = r; \
  |  |  |  |  155|     46|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 46, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  157|     46|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     46|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     46|	return _ret; \
  |  |  |  |  163|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1805|     46|}
card-myeid.c:myeid_finish:
 1843|    158|{
 1844|    158|	struct myeid_private_data *priv = (struct myeid_private_data *) card->drv_data;
 1845|    158|	free(priv);
 1846|    158|	return SC_SUCCESS;
  ------------------
  |  |   28|    158|#define SC_SUCCESS				0
  ------------------
 1847|    158|}
card-myeid.c:myeid_select_file:
  392|    780|{
  393|    780|	int r;
  394|       |
  395|    780|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    780|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    780|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    780|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    780|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 780]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|    780|	r = iso_ops->select_file(card, in_path, file);
  397|       |
  398|    780|	if (r == 0 && file != NULL && *file != NULL)
  ------------------
  |  Branch (398:6): [True: 114, False: 666]
  |  Branch (398:16): [True: 72, False: 42]
  |  Branch (398:32): [True: 72, False: 0]
  ------------------
  399|     72|		parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  400|       |
  401|    780|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    780|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    780|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    780|	int _ret = r; \
  |  |  |  |  155|    780|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 780, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    780|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    666|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 666, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  157|    780|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    780|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    780|	return _ret; \
  |  |  |  |  163|    780|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|    780|}
card-myeid.c:parse_sec_attr:
  350|     72|{
  351|     72|	int i;
  352|     72|	const int df_ops[4] =
  353|     72|		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|     72|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|     72|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|     72|#define SC_AC_OP_DELETE			2
  ------------------
  354|     72|	const int ef_ops[4] =
  355|     72|		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  188|     72|#define SC_AC_OP_READ			22
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  189|     72|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|     72|#define SC_AC_OP_DELETE			2
  ------------------
  356|     72|	const int key_ops[4] =
  357|     72|		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  173|     72|#define SC_AC_OP_CRYPTO			7
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  189|     72|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  168|     72|#define SC_AC_OP_DELETE			2
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  192|     72|#define SC_AC_OP_GENERATE		26
  ------------------
  358|       |
  359|     72|	const int *ops;
  360|       |
  361|     72|	if (len < 2)
  ------------------
  |  Branch (361:6): [True: 45, False: 27]
  ------------------
  362|     45|		return;
  363|       |
  364|     27|	switch (file->type) {
  365|      4|	case SC_FILE_TYPE_WORKING_EF:
  ------------------
  |  |  216|      4|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (365:2): [True: 4, False: 23]
  ------------------
  366|      4|		ops = ef_ops;
  367|      4|		break;
  368|      3|	case SC_FILE_TYPE_INTERNAL_EF:
  ------------------
  |  |  215|      3|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (368:2): [True: 3, False: 24]
  ------------------
  369|      3|		ops = key_ops;
  370|      3|		break;
  371|      3|	case SC_FILE_TYPE_DF:
  ------------------
  |  |  214|      3|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (371:2): [True: 3, False: 24]
  ------------------
  372|      3|		ops = df_ops;
  373|      3|		break;
  374|     17|	default:
  ------------------
  |  Branch (374:2): [True: 17, False: 10]
  ------------------
  375|     17|		ops = key_ops;
  376|     17|		break;
  377|     27|	}
  378|       |
  379|    135|	for (i = 0; i < 4; i++)
  ------------------
  |  Branch (379:14): [True: 108, False: 27]
  ------------------
  380|    108|	{
  381|    108|		if (ops[i] == -1)
  ------------------
  |  Branch (381:7): [True: 7, False: 101]
  ------------------
  382|      7|			continue;
  383|    101|		if ((i & 1) == 0)
  ------------------
  |  Branch (383:7): [True: 54, False: 47]
  ------------------
  384|     54|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] >> 4));
  385|     47|		else
  386|     47|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] & 0x0F));
  387|    101|	}
  388|     27|}
card-myeid.c:add_acl_entry:
  330|    101|{
  331|    101|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    101|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  332|       |
  333|    101|	switch (byte)
  334|    101|	{
  335|     35|	case 0:
  ------------------
  |  Branch (335:2): [True: 35, False: 66]
  ------------------
  336|     35|		method = SC_AC_NONE;
  ------------------
  |  |  150|     35|#define SC_AC_NONE			0x00000000
  ------------------
  337|     35|		break;
  338|     25|	case 15:
  ------------------
  |  Branch (338:2): [True: 25, False: 76]
  ------------------
  339|     25|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     25|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  340|     25|		break;
  341|     41|	default:
  ------------------
  |  Branch (341:2): [True: 41, False: 60]
  ------------------
  342|     41|		method = SC_AC_CHV;
  ------------------
  |  |  151|     41|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  343|     41|		key_ref = byte;
  344|     41|		break;
  345|    101|	}
  346|    101|	sc_file_add_acl_entry(file, op, method, key_ref);
  347|    101|}
card-myeid.c:myeid_process_fci:
  442|     68|{
  443|     68|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  444|     68|	size_t taglen = 0;
  445|     68|	const u8 *tag = NULL;
  446|     68|	int r;
  447|       |
  448|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  449|     68|	r = iso_ops->process_fci(card, file, buf, buflen);
  450|     68|	if (r < 0)
  ------------------
  |  Branch (450:6): [True: 0, False: 68]
  ------------------
  451|     68|	 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|     68|	if(file->type == SC_FILE_EF_UNKNOWN)
  ------------------
  |  |  220|     68|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  |  Branch (453:5): [True: 51, False: 17]
  ------------------
  454|     51|	{
  455|     51|		tag = sc_asn1_find_tag(NULL, buf, buflen, 0x82, &taglen);
  456|     51|		if (tag != NULL && taglen > 0 && *tag == 17)
  ------------------
  |  Branch (456:7): [True: 15, False: 36]
  |  Branch (456:22): [True: 11, False: 4]
  |  Branch (456:36): [True: 5, False: 6]
  ------------------
  457|      5|		{
  458|      5|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      5|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  459|      5|		}
  460|     51|	}
  461|     68|	if(file->sec_attr_len >= 3)
  ------------------
  |  Branch (461:5): [True: 14, False: 54]
  ------------------
  462|     14|	{
  463|     14|		sc_log(card->ctx, "id (%X) sec_attr (%X %X %X)", file->id,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  464|     14|			file->sec_attr[0],file->sec_attr[1],file->sec_attr[2]);
  465|     14|	}
  466|       |
  467|     68|	priv->card_state = file->status;
  468|     68|	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: 65]
  ------------------
  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|      5|		case SC_FILE_STATUS_ACTIVATED:
  ------------------
  |  |  236|      5|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  |  Branch (473:3): [True: 5, False: 63]
  ------------------
  474|      5|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_ACTIVATED", file->id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  475|      5|			break;
  476|     60|		default:
  ------------------
  |  Branch (476:3): [True: 60, False: 8]
  ------------------
  477|     60|			sc_log(card->ctx, "File id (%X) unusual status (0x%X)", file->id, file->status);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  478|     68|	}
  479|       |
  480|     68|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|     68|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     68|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     68|	int _ret = r; \
  |  |  |  |  155|     68|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 68, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     68|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     68|	return _ret; \
  |  |  |  |  163|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|     68|}
card-myeid.c:myeid_card_ctl:
 1808|     13|{
 1809|     13|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     13|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1810|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1811|       |
 1812|     13|	switch(cmd) {
  ------------------
  |  Branch (1812:9): [True: 13, False: 0]
  ------------------
 1813|      0|	case SC_CARDCTL_MYEID_PUTDATA:
  ------------------
  |  Branch (1813:2): [True: 0, False: 13]
  ------------------
 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: 13]
  ------------------
 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: 13]
  ------------------
 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: 13]
  ------------------
 1826|      0|		r = myeid_activate_card(card);
 1827|      0|		break;
 1828|     13|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1828:2): [True: 13, False: 0]
  ------------------
 1829|     13|		r = myeid_get_serialnr(card, (sc_serial_number_t *)ptr);
 1830|     13|		break;
 1831|      0|	case SC_CARDCTL_GET_CHANGE_COUNTER:
  ------------------
  |  Branch (1831:2): [True: 0, False: 13]
  ------------------
 1832|      0|		r = myeid_get_change_counter(card, (size_t *)ptr);
 1833|      0|		break;
 1834|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1834:2): [True: 0, False: 13]
  ------------------
 1835|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1835:2): [True: 0, False: 13]
  ------------------
 1836|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1836:2): [True: 0, False: 13]
  ------------------
 1837|      0|		break;
 1838|     13|	}
 1839|     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|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1840|     13|}
card-myeid.c:myeid_get_serialnr:
 1725|     13|{
 1726|     13|	int r;
 1727|     13|	u8  rbuf[256];
 1728|       |
 1729|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|     13|	r = myeid_get_info(card, rbuf, sizeof(rbuf));
 1739|     13|	LOG_TEST_RET(card->ctx, r,  "Get applet info 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: 11, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1740|       |
 1741|       |	/* cache serial number */
 1742|      2|	memcpy(card->serialnr.value, &rbuf[8], 10);
 1743|      2|	card->serialnr.len = 10;
 1744|       |
 1745|       |	/* copy and return serial number */
 1746|      2|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1747|       |
 1748|      2|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1749|      2|}
card-myeid.c:myeid_pin_cmd:
  667|     13|{
  668|     13|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  669|       |
  670|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  671|       |
  672|     13|	sc_log(card->ctx, "ref (%d), pin1 len(%zu), pin2 len (%zu)\n",
  ------------------
  |  |   71|     13|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  673|     13|			data->pin_reference, data->pin1.len, data->pin2.len);
  674|       |
  675|     13|	if(data->pin1.len > 8 || data->pin2.len > 8)
  ------------------
  |  Branch (675:5): [True: 0, False: 13]
  |  Branch (675:27): [True: 0, False: 13]
  ------------------
  676|     13|		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|     13|	data->pin1.pad_length = data->pin2.pad_length = 8;
  679|     13|	data->pin1.pad_char = data->pin2.pad_char = 0xFF;
  680|       |
  681|     13|	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  422|     26|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  240|      0|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (681:6): [True: 0, False: 13]
  |  Branch (681:40): [True: 0, False: 0]
  ------------------
  682|      0|		sc_log(card->ctx, "Card in creation state, no need to verify");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  683|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  684|      0|	}
  685|       |
  686|     13|	LOG_FUNC_RETURN(card->ctx, iso_ops->pin_cmd(card, data));
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|     13|}

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

sc_get_nqApplet_driver:
  471|  15.0k|{
  472|  15.0k|	sc_card_driver_t *iso_driver = sc_get_iso7816_driver();
  473|       |
  474|  15.0k|	if (iso_operations == NULL) {
  ------------------
  |  Branch (474:6): [True: 1, False: 15.0k]
  ------------------
  475|      1|		iso_operations = iso_driver->ops;
  476|      1|	}
  477|       |
  478|  15.0k|	nqapplet_operations = *iso_driver->ops;
  479|       |
  480|       |	/* supported operations */
  481|  15.0k|	nqapplet_operations.match_card = nqapplet_match_card;
  482|  15.0k|	nqapplet_operations.init = nqapplet_init;
  483|  15.0k|	nqapplet_operations.finish = nqapplet_finish;
  484|  15.0k|	nqapplet_operations.get_response = nqapplet_get_response;
  485|  15.0k|	nqapplet_operations.get_challenge = nqapplet_get_challenge;
  486|  15.0k|	nqapplet_operations.logout = nqapplet_logout;
  487|  15.0k|	nqapplet_operations.set_security_env = nqapplet_set_security_env;
  488|  15.0k|	nqapplet_operations.decipher = nqapplet_decipher;
  489|  15.0k|	nqapplet_operations.compute_signature = nqapplet_compute_signature;
  490|  15.0k|	nqapplet_operations.check_sw = nqapplet_check_sw;
  491|  15.0k|	nqapplet_operations.get_data = nqapplet_get_data;
  492|  15.0k|	nqapplet_operations.select_file = nqapplet_select_file;
  493|  15.0k|	nqapplet_operations.card_ctl = nqapplet_card_ctl;
  494|  15.0k|	nqapplet_operations.pin_cmd = nqapplet_pin_cmd;
  495|       |
  496|       |	/* unsupported operations */
  497|  15.0k|	nqapplet_operations.read_binary = NULL;
  498|  15.0k|	nqapplet_operations.write_binary = NULL;
  499|  15.0k|	nqapplet_operations.update_binary = NULL;
  500|  15.0k|	nqapplet_operations.erase_binary = NULL;
  501|  15.0k|	nqapplet_operations.read_record = NULL;
  502|  15.0k|	nqapplet_operations.write_record = NULL;
  503|  15.0k|	nqapplet_operations.append_record = NULL;
  504|  15.0k|	nqapplet_operations.update_record = NULL;
  505|       |
  506|  15.0k|	nqapplet_operations.verify = NULL;
  507|  15.0k|	nqapplet_operations.restore_security_env = NULL;
  508|  15.0k|	nqapplet_operations.change_reference_data = NULL;
  509|  15.0k|	nqapplet_operations.reset_retry_counter = NULL;
  510|  15.0k|	nqapplet_operations.create_file = NULL;
  511|  15.0k|	nqapplet_operations.delete_file = NULL;
  512|  15.0k|	nqapplet_operations.list_files = NULL;
  513|  15.0k|	nqapplet_operations.process_fci = NULL;
  514|  15.0k|	nqapplet_operations.construct_fci = NULL;
  515|  15.0k|	nqapplet_operations.put_data = NULL;
  516|  15.0k|	nqapplet_operations.delete_record = NULL;
  517|  15.0k|	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.0k|	return &nqapplet_driver;
  526|  15.0k|}
card-nqApplet.c:nqapplet_match_card:
  143|  2.47k|{
  144|  2.47k|	int rv = _sc_match_atr(card, nqapplet_atrs, &card->type);
  145|  2.47k|	return (rv >= 0);
  146|  2.47k|}
card-nqApplet.c:nqapplet_init:
  149|    126|{
  150|    126|	u8 version_major;
  151|    126|	u8 version_minor;
  152|    126|	u8 serial_nr[APPLET_SERIALNR_LEN];
  153|    126|	size_t cb_serial_nr = sizeof(serial_nr);
  154|    126|	unsigned long rsa_flags = 0;
  155|       |
  156|    126|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    126|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    126|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    126|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    126|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 126]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|    126|	int rv =
  158|    126|		select_nqapplet(card, &version_major, &version_minor, serial_nr, cb_serial_nr, &cb_serial_nr);
  159|    126|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    126|#define SC_SUCCESS				0
  ------------------
  |  Branch (159:6): [True: 64, False: 62]
  ------------------
  160|     64|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "Cannot select NQ-Applet.");
  ------------------
  |  |  174|     64|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     64|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     64|	int _ret = (r); \
  |  |  |  |  168|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     64|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     64|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     64|		return _ret; \
  |  |  |  |  172|     64|	} \
  |  |  |  |  173|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|     64|	}
  162|       |
  163|     62|	rv = init_driver_data(card, version_major, version_minor);
  164|     62|	LOG_TEST_RET(card->ctx, rv, "Failed to initialize driver data.");
  ------------------
  |  |  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: 0, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 62]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|       |
  166|     62|	card->max_send_size = 255;
  167|     62|	card->max_recv_size = 256;
  168|     62|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  557|     62|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|     62|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  169|     62|	rsa_flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|     62|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  170|     62|	_sc_card_add_rsa_alg(card, 3072, rsa_flags, 0);
  171|       |
  172|     62|	card->serialnr.len = MIN(sizeof(card->serialnr.value), cb_serial_nr);
  ------------------
  |  |   70|     62|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 62]
  |  |  ------------------
  ------------------
  173|     62|	memcpy(card->serialnr.value, serial_nr, card->serialnr.len);
  174|       |
  175|     62|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     62|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     62|	int _ret = r; \
  |  |  |  |  155|     62|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     62|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  176|     62|}
card-nqApplet.c:select_nqapplet:
  110|    126|{
  111|    126|	int rv;
  112|    126|	sc_context_t *ctx = card->ctx;
  113|    126|	u8 buffer[APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN + 2];
  114|    126|	size_t cb_buffer = sizeof(buffer);
  115|    126|	size_t cb_aid = sizeof(nqapplet_aid);
  116|       |
  117|    126|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    126|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    126|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    126|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    126|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 126]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  118|       |
  119|    126|	rv = iso7816_select_aid(card, nqapplet_aid, cb_aid, buffer, &cb_buffer);
  120|    126|	LOG_TEST_RET(card->ctx, rv, "Failed to select NQ-Applet.");
  ------------------
  |  |  174|    126|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    126|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    126|	int _ret = (r); \
  |  |  |  |  168|    126|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 46, False: 80]
  |  |  |  |  ------------------
  |  |  |  |  169|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     46|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     46|		return _ret; \
  |  |  |  |  172|     46|	} \
  |  |  |  |  173|    126|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 80]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|     80|	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   30|     80|#define APPLET_VERSION_LEN  2
  ------------------
              	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   31|     80|#define APPLET_MEMTYPE_LEN  1
  ------------------
              	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   32|     80|#define APPLET_SERIALNR_LEN 8
  ------------------
  |  Branch (122:6): [True: 18, False: 62]
  ------------------
  123|     18|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  124|     18|	}
  125|       |
  126|     62|	if (version_major != NULL) {
  ------------------
  |  Branch (126:6): [True: 62, False: 0]
  ------------------
  127|     62|		*version_major = buffer[0];
  128|     62|	}
  129|     62|	if (version_minor != NULL) {
  ------------------
  |  Branch (129:6): [True: 62, False: 0]
  ------------------
  130|     62|		*version_minor = buffer[1];
  131|     62|	}
  132|     62|	if (serial_nr != NULL && cb_serial_nr > 0 && serial_nr_len != NULL) {
  ------------------
  |  Branch (132:6): [True: 62, False: 0]
  |  Branch (132:27): [True: 62, False: 0]
  |  Branch (132:47): [True: 62, False: 0]
  ------------------
  133|     62|		size_t cb = MIN(APPLET_SERIALNR_LEN, cb_serial_nr);
  ------------------
  |  |   70|     62|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 62]
  |  |  ------------------
  ------------------
  134|     62|		memcpy(serial_nr, buffer + 3, cb);
  135|     62|		*serial_nr_len = cb;
  136|     62|	}
  137|       |
  138|     62|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     62|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     62|	int _ret = r; \
  |  |  |  |  155|     62|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     62|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  139|     62|}
card-nqApplet.c:init_driver_data:
   82|     62|{
   83|     62|	nqapplet_driver_data_ptr data = calloc(1, sizeof(struct nqapplet_driver_data));
   84|     62|	if (data == NULL) {
  ------------------
  |  Branch (84:6): [True: 0, False: 62]
  ------------------
   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|     62|	data->version_major = version_major;
   89|     62|	data->version_minor = version_minor;
   90|     62|	data->key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|     62|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
   91|     62|	card->drv_data = (void *)data;
   92|     62|	return SC_SUCCESS;
  ------------------
  |  |   28|     62|#define SC_SUCCESS				0
  ------------------
   93|     62|}
card-nqApplet.c:nqapplet_finish:
  179|     62|{
  180|     62|	nqapplet_driver_data_ptr data = (nqapplet_driver_data_ptr)card->drv_data;
  181|       |
  182|     62|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     62|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     62|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     62|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     62|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 62]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|     62|	if (data != NULL) {
  ------------------
  |  Branch (183:6): [True: 62, False: 0]
  ------------------
  184|     62|		free(data);
  185|     62|		card->drv_data = NULL;
  186|     62|	}
  187|     62|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     62|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     62|	int _ret = r; \
  |  |  |  |  155|     62|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     62|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|     62|}
card-nqApplet.c:nqapplet_get_response:
  192|    863|{
  193|    863|	struct sc_apdu apdu = {0};
  194|    863|	int rv;
  195|    863|	size_t resplen;
  196|       |
  197|    863|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    863|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    863|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    863|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    863|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 863]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|    863|	resplen = MIN(sc_get_max_recv_size(card), *cb_resp);
  ------------------
  |  |   70|    863|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 863]
  |  |  ------------------
  ------------------
  199|       |
  200|    863|	sc_format_apdu_ex(&apdu, 0x80, 0xC0, 0x00, 0x00, NULL, 0, resp, resplen);
  201|    863|	apdu.flags |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|    863|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  202|       |
  203|    863|	rv = sc_transmit_apdu(card, &apdu);
  204|    863|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    863|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    863|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    863|	int _ret = (r); \
  |  |  |  |  168|    863|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 861]
  |  |  |  |  ------------------
  |  |  |  |  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|    863|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 861]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|       |
  206|    861|	*cb_resp = apdu.resplen;
  207|       |
  208|    861|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (208:6): [True: 33, False: 828]
  ------------------
  209|     33|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|     33|	}
  211|    828|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (211:6): [True: 16, False: 812]
  |  Branch (211:26): [True: 7, False: 9]
  ------------------
  212|      7|		rv = SC_SUCCESS;
  ------------------
  |  |   28|      7|#define SC_SUCCESS				0
  ------------------
  213|    821|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (213:13): [True: 756, False: 65]
  ------------------
  214|    756|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (214:8): [True: 248, False: 508]
  ------------------
  215|    756|	} else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (215:13): [True: 9, False: 56]
  |  Branch (215:33): [True: 2, False: 7]
  ------------------
  216|      2|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  217|      2|	}
  218|       |
  219|    828|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    828|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    828|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    828|	int _ret = r; \
  |  |  |  |  155|    828|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 72, False: 756]
  |  |  |  |  ------------------
  |  |  |  |  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|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 70]
  |  |  |  |  ------------------
  |  |  |  |  157|     72|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    756|	} else { \
  |  |  |  |  159|    756|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    756|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    756|	} \
  |  |  |  |  162|    828|	return _ret; \
  |  |  |  |  163|    828|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|    828|}
card-nqApplet.c:nqapplet_check_sw:
  374|    147|{
  375|    147|	const int nqapplet_error_count = sizeof(nqapplet_errors) / sizeof(struct sc_card_error);
  376|    147|	int i;
  377|       |
  378|    147|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    147|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    147|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    147|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    147|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 147]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|    147|	sc_log(card->ctx, "Checking sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  ------------------
  |  |   71|    147|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  380|       |
  381|  1.54k|	for (i = 0; i < nqapplet_error_count; i++) {
  ------------------
  |  Branch (381:14): [True: 1.43k, False: 105]
  ------------------
  382|  1.43k|		if (nqapplet_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (382:7): [True: 42, False: 1.39k]
  ------------------
  383|     42|			LOG_TEST_RET(card->ctx, nqapplet_errors[i].errorno, nqapplet_errors[i].errorstr);
  ------------------
  |  |  174|     42|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     42|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     42|	int _ret = (r); \
  |  |  |  |  168|     42|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 42, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     42|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     42|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     42|		return _ret; \
  |  |  |  |  172|     42|	} \
  |  |  |  |  173|     42|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|     42|		}
  385|  1.43k|	}
  386|       |
  387|    105|	return iso_operations->check_sw(card, sw1, sw2);
  388|    147|}
card-nqApplet.c:nqapplet_get_data:
  391|     90|{
  392|     90|	struct sc_apdu apdu;
  393|     90|	int rv;
  394|       |
  395|     90|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     90|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     90|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     90|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     90|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|       |
  397|     90|	sc_format_apdu_ex(&apdu, 0x80, 0xB0, 0x00, (u8)id, NULL, 0, resp, cb_resp);
  398|     90|	apdu.le = 256;
  399|       |
  400|     90|	rv = sc_transmit_apdu(card, &apdu);
  401|     90|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     90|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     90|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     90|	int _ret = (r); \
  |  |  |  |  168|     90|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 76]
  |  |  |  |  ------------------
  |  |  |  |  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|     90|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|       |
  403|     76|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (403:6): [True: 40, False: 36]
  |  Branch (403:26): [True: 36, False: 4]
  ------------------
  404|     36|		rv = (int)apdu.resplen;
  405|     40|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (405:13): [True: 0, False: 40]
  ------------------
  406|      0|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (406:8): [True: 0, False: 0]
  ------------------
  407|     40|	} else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (407:13): [True: 7, False: 33]
  |  Branch (407:33): [True: 1, False: 6]
  ------------------
  408|      1|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  409|      1|	}
  410|       |
  411|     76|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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: 42, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  157|     42|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     42|	} else { \
  |  |  |  |  159|     34|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     34|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     34|	} \
  |  |  |  |  162|     76|	return _ret; \
  |  |  |  |  163|     76|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|     76|}
card-nqApplet.c:nqapplet_select_file:
  416|    226|{
  417|    226|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    226|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    226|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    226|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    226|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 226]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    226|	if (in_path->type == SC_PATH_TYPE_PATH && in_path->len == 2 &&
  ------------------
  |  |  119|    452|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (421:6): [True: 102, False: 124]
  |  Branch (421:44): [True: 0, False: 102]
  ------------------
  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|    226|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    226|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    226|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    226|	int _ret = r; \
  |  |  |  |  155|    226|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 226, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    226|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    226|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 226, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    226|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    226|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    226|	return _ret; \
  |  |  |  |  163|    226|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|    226|}

sc_get_oberthur_driver:
 2343|  15.0k|{
 2344|  15.0k|	return sc_get_driver();
 2345|  15.0k|}
card-oberthur.c:sc_get_driver:
 2312|  15.0k|{
 2313|  15.0k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2313:6): [True: 1, False: 15.0k]
  ------------------
 2314|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2315|       |
 2316|  15.0k|	auth_ops = *iso_ops;
 2317|  15.0k|	auth_ops.match_card = auth_match_card;
 2318|  15.0k|	auth_ops.init = auth_init;
 2319|  15.0k|	auth_ops.finish = auth_finish;
 2320|  15.0k|	auth_ops.select_file = auth_select_file;
 2321|  15.0k|	auth_ops.list_files = auth_list_files;
 2322|  15.0k|	auth_ops.delete_file = auth_delete_file;
 2323|  15.0k|	auth_ops.create_file = auth_create_file;
 2324|  15.0k|	auth_ops.read_binary = auth_read_binary;
 2325|  15.0k|	auth_ops.update_binary = auth_update_binary;
 2326|  15.0k|	auth_ops.read_record = auth_read_record;
 2327|  15.0k|	auth_ops.delete_record = auth_delete_record;
 2328|  15.0k|	auth_ops.card_ctl = auth_card_ctl;
 2329|  15.0k|	auth_ops.set_security_env = auth_set_security_env;
 2330|  15.0k|	auth_ops.restore_security_env = auth_restore_security_env;
 2331|  15.0k|	auth_ops.compute_signature = auth_compute_signature;
 2332|  15.0k|	auth_ops.decipher = auth_decipher;
 2333|  15.0k|	auth_ops.process_fci = auth_process_fci;
 2334|  15.0k|	auth_ops.pin_cmd = auth_pin_cmd;
 2335|  15.0k|	auth_ops.logout = auth_logout;
 2336|  15.0k|	auth_ops.check_sw = auth_check_sw;
 2337|  15.0k|	return &auth_drv;
 2338|  15.0k|}
card-oberthur.c:auth_match_card:
  204|  11.0k|{
  205|  11.0k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 10.3k, False: 739]
  ------------------
  206|  10.3k|		return 0;
  207|    739|	else
  208|    739|		return 1;
  209|  11.0k|}
card-oberthur.c:auth_init:
  214|    739|{
  215|    739|	struct auth_private_data *data;
  216|    739|	struct sc_path path;
  217|    739|	unsigned long flags;
  218|    739|	int rv = 0;
  219|       |
  220|    739|	data = calloc(1, sizeof(struct auth_private_data));
  221|    739|	if (!data)
  ------------------
  |  Branch (221:6): [True: 0, False: 739]
  ------------------
  222|    739|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|    739|	card->cla = 0x00;
  225|    739|	card->drv_data = data;
  226|       |
  227|    739|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    739|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  228|    739|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  564|    739|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  229|       |
  230|    739|	if (auth_select_aid(card)) {
  ------------------
  |  Branch (230:6): [True: 45, False: 694]
  ------------------
  231|     45|		sc_log(card->ctx, "Failed to initialize %s", card->name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     45|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     45|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  233|     45|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to initialize");
  ------------------
  |  |  184|     45|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     45|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     45|	int _ret = (r); \
  |  |  |  |  178|     45|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     45|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     45|		goto err; \
  |  |  |  |  182|     45|	} \
  |  |  |  |  183|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     45|	}
  235|       |
  236|    694|	sc_format_path("3F00", &path);
  237|    694|	rv = auth_select_file(card, &path, NULL);
  238|       |
  239|    739|err:
  240|    739|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    739|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:6): [True: 694, False: 45]
  ------------------
  241|    694|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  120|    694|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    694|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|    694|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  115|    694|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  242|    694|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|    694|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    694|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    694|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|       |
  245|    694|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  246|    694|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  247|    694|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  248|    694|	} else {
  249|     45|		free(card->drv_data);
  250|     45|		card->drv_data = NULL;
  251|     45|	}
  252|       |
  253|    739|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    739|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    739|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    739|	int _ret = r; \
  |  |  |  |  155|    739|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 739, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    739|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 694]
  |  |  |  |  ------------------
  |  |  |  |  157|    739|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    739|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    739|	return _ret; \
  |  |  |  |  163|    739|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|    739|}
card-oberthur.c:auth_select_aid:
  145|    739|{
  146|    739|	struct sc_apdu apdu;
  147|    739|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  148|    739|	struct auth_private_data *data = (struct auth_private_data *)card->drv_data;
  149|    739|	int rv, ii;
  150|    739|	struct sc_path tmp_path;
  151|       |
  152|       |	/* Select Card Manager (to deselect previously selected application) */
  153|    739|	rv = gp_select_card_manager(card);
  154|    739|	LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 23, False: 716]
  |  |  |  |  ------------------
  |  |  |  |  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|    739|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 716]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Get smart card serial number */
  157|    716|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  292|    716|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  158|    716|	apdu.cla = 0x80;
  159|    716|	apdu.le = 0x2D;
  160|    716|	apdu.resplen = 0x30;
  161|    716|	apdu.resp = apdu_resp;
  162|       |
  163|    716|	rv = sc_transmit_apdu(card, &apdu);
  164|    716|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    716|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    716|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    716|	int _ret = (r); \
  |  |  |  |  168|    716|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 715]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|    716|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 715]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|    715|	if (apdu.resplen < 20) {
  ------------------
  |  Branch (165:6): [True: 8, False: 707]
  ------------------
  166|      8|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect length");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      8|	}
  168|    707|	card->serialnr.len = 4;
  169|    707|	memcpy(card->serialnr.value, apdu.resp+15, 4);
  170|       |
  171|  3.53k|	for (ii=0, data->sn = 0; ii < 4; ii++)
  ------------------
  |  Branch (171:27): [True: 2.82k, False: 707]
  ------------------
  172|  2.82k|		data->sn += (long int)(*(apdu.resp + 15 + ii)) << (3-ii)*8;
  173|       |
  174|    707|	sc_log(card->ctx, "serial number %li/0x%lX", data->sn, data->sn);
  ------------------
  |  |   71|    707|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  175|       |
  176|    707|	memset(&tmp_path, 0, sizeof(struct sc_path));
  177|    707|	tmp_path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    707|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  178|    707|	memcpy(tmp_path.value, aidAuthentIC_V5, lenAidAuthentIC_V5);
  179|    707|	tmp_path.len = lenAidAuthentIC_V5;
  180|       |
  181|    707|	rv = iso_ops->select_file(card, &tmp_path, NULL);
  182|    707|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    707|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    707|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    707|	int _ret = (r); \
  |  |  |  |  168|    707|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 702]
  |  |  |  |  ------------------
  |  |  |  |  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|    707|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 702]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    702|	sc_format_path("3F00", &tmp_path);
  185|    702|	sc_file_free(auth_current_df);
  186|    702|	auth_current_df = NULL;
  187|    702|	rv = iso_ops->select_file(card, &tmp_path, &auth_current_df);
  188|    702|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    702|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    702|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    702|	int _ret = (r); \
  |  |  |  |  168|    702|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 694]
  |  |  |  |  ------------------
  |  |  |  |  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|    702|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 694]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|       |
  190|    694|	sc_file_free(auth_current_ef);
  191|    694|	auth_current_ef = NULL;
  192|    694|	sc_file_dup(&auth_current_ef, auth_current_df);
  193|       |
  194|    694|	memcpy(data->aid, aidAuthentIC_V5, lenAidAuthentIC_V5);
  195|    694|	data->aid_len = lenAidAuthentIC_V5;
  196|    694|	card->name = nameAidAuthentIC_V5;
  197|       |
  198|    694|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    694|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    694|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    694|	int _ret = r; \
  |  |  |  |  155|    694|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 694, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    694|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 694]
  |  |  |  |  ------------------
  |  |  |  |  157|    694|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    694|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    694|	return _ret; \
  |  |  |  |  163|    694|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|    694|}
card-oberthur.c:auth_finish:
  137|    694|{
  138|    694|	free(card->drv_data);
  139|    694|	return SC_SUCCESS;
  ------------------
  |  |   28|    694|#define SC_SUCCESS				0
  ------------------
  140|    694|}
card-oberthur.c:auth_select_file:
  445|  10.6k|{
  446|  10.6k|	struct sc_path path;
  447|  10.6k|	struct sc_file *tmp_file = NULL;
  448|  10.6k|	size_t offs, ii;
  449|  10.6k|	int rv;
  450|       |
  451|  10.6k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (451:6): [True: 0, False: 10.6k]
  |  Branch (451:22): [True: 0, False: 10.6k]
  ------------------
  452|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  453|       |
  454|  10.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  10.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|       |
  456|  10.6k|	memcpy(&path, in_path, sizeof(struct sc_path));
  457|       |
  458|  10.6k|	if (!auth_current_df)
  ------------------
  |  Branch (458:6): [True: 0, False: 10.6k]
  ------------------
  459|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  460|       |
  461|  10.6k|	sc_log(card->ctx, "in_path; type=%d, path=%s, out %p",
  ------------------
  |  |   71|  10.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  462|  10.6k|			in_path->type, sc_print_path(in_path), file_out);
  463|  10.6k|	sc_log(card->ctx, "current path; type=%d, path=%s",
  ------------------
  |  |   71|  10.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|  10.6k|			auth_current_df->path.type, sc_print_path(&auth_current_df->path));
  465|  10.6k|	if (auth_current_ef)
  ------------------
  |  Branch (465:6): [True: 5.31k, False: 5.30k]
  ------------------
  466|  5.31k|		sc_log(card->ctx, "current file; type=%d, path=%s",
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  467|  10.6k|				auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
  468|       |
  469|  10.6k|	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  123|  21.2k|#define SC_PATH_TYPE_PARENT		5
  ------------------
              	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  10.5k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (469:6): [True: 110, False: 10.5k]
  |  Branch (469:42): [True: 4.44k, False: 6.06k]
  ------------------
  470|  4.55k|		sc_file_free(auth_current_ef);
  471|  4.55k|		auth_current_ef = NULL;
  472|       |
  473|  4.55k|		rv = iso_ops->select_file(card, &path, &tmp_file);
  474|  4.55k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  4.55k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.55k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.55k|	int _ret = (r); \
  |  |  |  |  168|  4.55k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.16k, False: 2.38k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.16k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.16k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.16k|		return _ret; \
  |  |  |  |  172|  2.16k|	} \
  |  |  |  |  173|  4.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.38k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|  2.38k|		if (!tmp_file)
  ------------------
  |  Branch (475:7): [True: 0, False: 2.38k]
  ------------------
  476|      0|			return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  477|       |
  478|  2.38k|		if (path.type == SC_PATH_TYPE_PARENT) {
  ------------------
  |  |  123|  2.38k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (478:7): [True: 51, False: 2.33k]
  ------------------
  479|     51|			memcpy(&tmp_file->path, &auth_current_df->path, sizeof(struct sc_path));
  480|     51|			if (tmp_file->path.len > 2)
  ------------------
  |  Branch (480:8): [True: 51, False: 0]
  ------------------
  481|     51|				tmp_file->path.len -= 2;
  482|       |
  483|     51|			sc_file_free(auth_current_df);
  484|     51|			auth_current_df = NULL;
  485|     51|			sc_file_dup(&auth_current_df, tmp_file);
  486|  2.33k|		} else {
  487|  2.33k|			if (tmp_file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  2.33k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (487:8): [True: 374, False: 1.96k]
  ------------------
  488|    374|				sc_concatenate_path(&tmp_file->path, &auth_current_df->path, &path);
  489|       |
  490|    374|				sc_file_free(auth_current_df);
  491|    374|				auth_current_df = NULL;
  492|    374|				sc_file_dup(&auth_current_df, tmp_file);
  493|  1.96k|			} else {
  494|  1.96k|				sc_file_free(auth_current_ef);
  495|  1.96k|				auth_current_ef = NULL;
  496|       |
  497|  1.96k|				sc_file_dup(&auth_current_ef, tmp_file);
  498|  1.96k|				sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path);
  499|  1.96k|			}
  500|  2.33k|		}
  501|  2.38k|		if (file_out) {
  ------------------
  |  Branch (501:7): [True: 1.85k, False: 536]
  ------------------
  502|  1.85k|			sc_file_free(*file_out);
  503|  1.85k|			sc_file_dup(file_out, tmp_file);
  504|  1.85k|		}
  505|       |
  506|  2.38k|		sc_file_free(tmp_file);
  507|  6.06k|	} else if (path.type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  6.06k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (507:13): [True: 1.25k, False: 4.80k]
  ------------------
  508|  1.25k|		rv = iso_ops->select_file(card, &path, NULL);
  509|  1.25k|		if (rv) {
  ------------------
  |  Branch (509:7): [True: 1.20k, False: 50]
  ------------------
  510|  1.20k|			sc_file_free(auth_current_ef);
  511|  1.20k|			auth_current_ef = NULL;
  512|  1.20k|		}
  513|  1.25k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  1.25k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.25k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.25k|	int _ret = (r); \
  |  |  |  |  168|  1.25k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.20k, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  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.25k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|  4.80k|	} else {
  515|  10.8k|		for (offs = 0; offs < path.len && offs < auth_current_df->path.len; offs += 2)
  ------------------
  |  Branch (515:18): [True: 10.1k, False: 696]
  |  Branch (515:37): [True: 6.15k, False: 3.96k]
  ------------------
  516|  6.15k|			if (path.value[offs] != auth_current_df->path.value[offs] ||
  ------------------
  |  Branch (516:8): [True: 120, False: 6.03k]
  ------------------
  517|  6.03k|					path.value[offs + 1] != auth_current_df->path.value[offs + 1])
  ------------------
  |  Branch (517:6): [True: 33, False: 6.00k]
  ------------------
  518|    153|				break;
  519|       |
  520|  4.80k|		sc_log(card->ctx, "offs %"SC_FORMAT_LEN_SIZE_T"u", offs);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
  521|  4.80k|		if (offs && offs < auth_current_df->path.len) {
  ------------------
  |  Branch (521:7): [True: 4.75k, False: 52]
  |  Branch (521:15): [True: 102, False: 4.65k]
  ------------------
  522|    102|			size_t deep = auth_current_df->path.len - offs;
  523|       |
  524|    102|			sc_log(card->ctx, "deep %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  525|    102|			       deep);
  526|    153|			for (ii = 0; ii < deep; ii += 2) {
  ------------------
  |  Branch (526:17): [True: 110, False: 43]
  ------------------
  527|    110|				struct sc_path tmp_path;
  528|       |
  529|    110|				memcpy(&tmp_path, &auth_current_df->path,  sizeof(struct sc_path));
  530|    110|				tmp_path.type = SC_PATH_TYPE_PARENT;
  ------------------
  |  |  123|    110|#define SC_PATH_TYPE_PARENT		5
  ------------------
  531|       |
  532|    110|				if (file_out) {
  ------------------
  |  Branch (532:9): [True: 23, False: 87]
  ------------------
  533|     23|					sc_file_free(*file_out);
  534|     23|					*file_out = NULL;
  535|     23|				}
  536|       |
  537|    110|				rv = auth_select_file (card, &tmp_path, file_out);
  538|    110|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  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: 59, False: 51]
  |  |  |  |  ------------------
  |  |  |  |  169|     59|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     59|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     59|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     59|		return _ret; \
  |  |  |  |  172|     59|	} \
  |  |  |  |  173|    110|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 51]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    110|			}
  540|    102|		}
  541|       |
  542|  4.75k|		if (path.len > offs) {
  ------------------
  |  Branch (542:7): [True: 4.05k, False: 696]
  ------------------
  543|  4.05k|			struct sc_path tmp_path;
  544|       |
  545|  4.05k|			memset(&tmp_path, 0, sizeof(struct sc_path));
  546|  4.05k|			tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  4.05k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  547|  4.05k|			tmp_path.len = 2;
  548|       |
  549|  6.39k|			for (ii = 0; ii < path.len - offs; ii += 2) {
  ------------------
  |  Branch (549:17): [True: 4.44k, False: 1.94k]
  ------------------
  550|  4.44k|				memcpy(tmp_path.value, path.value + offs + ii, 2);
  551|       |
  552|  4.44k|				if (file_out) {
  ------------------
  |  Branch (552:9): [True: 3.10k, False: 1.33k]
  ------------------
  553|  3.10k|					sc_file_free(*file_out);
  554|  3.10k|					*file_out = NULL;
  555|  3.10k|				}
  556|       |
  557|  4.44k|				rv = auth_select_file(card, &tmp_path, file_out);
  558|  4.44k|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  4.44k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.44k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.44k|	int _ret = (r); \
  |  |  |  |  168|  4.44k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.10k, False: 2.33k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.10k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.10k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.10k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.10k|		return _ret; \
  |  |  |  |  172|  2.10k|	} \
  |  |  |  |  173|  4.44k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.33k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|  4.44k|			}
  560|  4.05k|		} else if (path.len - offs == 0 && file_out) {
  ------------------
  |  Branch (560:14): [True: 696, False: 0]
  |  Branch (560:38): [True: 1, False: 695]
  ------------------
  561|      1|			if (sc_compare_path(&path, &auth_current_df->path) && file_out) {
  ------------------
  |  Branch (561:8): [True: 0, False: 1]
  |  Branch (561:58): [True: 0, False: 0]
  ------------------
  562|      0|				sc_file_free(*file_out);
  563|      0|				sc_file_dup(file_out, auth_current_df);
  564|      1|			} else  if (auth_current_ef && file_out) {
  ------------------
  |  Branch (564:16): [True: 1, False: 0]
  |  Branch (564:35): [True: 1, False: 0]
  ------------------
  565|      1|				sc_file_free(*file_out);
  566|      1|				sc_file_dup(file_out, auth_current_ef);
  567|      1|			} else {
  568|      0|				LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "No current EF");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|      0|			}
  570|      1|		}
  571|  4.75k|	}
  572|       |
  573|  5.07k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  5.07k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.07k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.07k|	int _ret = r; \
  |  |  |  |  155|  5.07k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.07k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.07k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5.07k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.07k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.07k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.07k|	return _ret; \
  |  |  |  |  163|  5.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  574|  5.07k|}
card-oberthur.c:auth_read_binary:
 2122|  4.57k|{
 2123|  4.57k|	int rv;
 2124|  4.57k|	size_t sz;
 2125|  4.57k|	struct sc_pkcs15_bignum bn[2];
 2126|  4.57k|	unsigned char *out = NULL;
 2127|  4.57k|	bn[0].data = NULL;
 2128|  4.57k|	bn[1].data = NULL;
 2129|       |
 2130|  4.57k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  4.57k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.57k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.57k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.57k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.57k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2131|       |
 2132|  4.57k|	if (!auth_current_ef)
  ------------------
  |  Branch (2132:6): [True: 18, False: 4.55k]
  ------------------
 2133|  4.57k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid auth_current_ef");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     18|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     18|		return _ret; \
  |  |  |  |  172|     18|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2134|       |
 2135|  4.55k|	sc_log(card->ctx,
  ------------------
  |  |   71|  9.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 82, False: 4.47k]
  |  |  ------------------
  ------------------
 2136|  4.55k|	       "offset %i; size %"SC_FORMAT_LEN_SIZE_T"u; flags 0x%lX",
 2137|  4.55k|	       offset, count, flags ? *flags : 0);
 2138|  4.55k|	sc_log(card->ctx,"last selected : magic %X; ef %X",
  ------------------
  |  |   71|  4.55k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2139|  4.55k|			auth_current_ef->magic, auth_current_ef->ef_structure);
 2140|       |
 2141|  4.55k|	if (offset & ~0x7FFF)
  ------------------
  |  Branch (2141:6): [True: 1, False: 4.55k]
  ------------------
 2142|  4.55k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid file offset");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2143|       |
 2144|  4.55k|	if (auth_current_ef->magic == SC_FILE_MAGIC &&
  ------------------
  |  |   57|  9.11k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  |  Branch (2144:6): [True: 4.55k, False: 0]
  ------------------
 2145|  4.55k|			auth_current_ef->ef_structure == SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC) {
  ------------------
  |  Branch (2145:4): [True: 147, False: 4.40k]
  ------------------
 2146|    147|		int jj;
 2147|    147|		unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 2148|    147|		size_t resp_len, out_len;
 2149|    147|		struct sc_pkcs15_pubkey_rsa key;
 2150|       |
 2151|    147|		resp_len = sizeof(resp);
 2152|    147|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2153|    147|				2, resp, resp_len);
 2154|    147|		LOG_TEST_RET(card->ctx, rv, "read component failed");
  ------------------
  |  |  174|    147|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    147|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    147|	int _ret = (r); \
  |  |  |  |  168|    147|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  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|    147|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2155|       |
 2156|    327|		for (jj=0; jj<rv && *(resp+jj)==0; jj++)
  ------------------
  |  Branch (2156:14): [True: 311, False: 16]
  |  Branch (2156:23): [True: 200, False: 111]
  ------------------
 2157|    200|			;
 2158|       |
 2159|    127|		if (rv - jj == 0)
  ------------------
  |  Branch (2159:7): [True: 16, False: 111]
  ------------------
 2160|     16|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     16|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2161|    111|		bn[0].data = calloc(1, rv - jj);
 2162|    111|		if (!bn[0].data) {
  ------------------
  |  Branch (2162:7): [True: 0, False: 111]
  ------------------
 2163|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2164|      0|			goto err;
 2165|      0|		}
 2166|    111|		bn[0].len = rv - jj;
 2167|    111|		memcpy(bn[0].data, resp + jj, rv - jj);
 2168|       |
 2169|    111|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2170|    111|				1, resp, resp_len);
 2171|    111|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Cannot read RSA public key component");
  ------------------
  |  |  184|    111|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    111|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    111|	int _ret = (r); \
  |  |  |  |  178|    111|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 9, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  179|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      9|		goto err; \
  |  |  |  |  182|      9|	} \
  |  |  |  |  183|    111|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2172|       |
 2173|    102|		bn[1].data = calloc(1, rv);
 2174|    102|		if (!bn[1].data) {
  ------------------
  |  Branch (2174:7): [True: 0, False: 102]
  ------------------
 2175|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2176|      0|			goto err;
 2177|      0|		}
 2178|    102|		bn[1].len = rv;
 2179|    102|		memcpy(bn[1].data, resp, rv);
 2180|       |
 2181|    102|		key.exponent = bn[0];
 2182|    102|		key.modulus = bn[1];
 2183|       |
 2184|    102|		if (sc_pkcs15_encode_pubkey_rsa(card->ctx, &key, &out, &out_len) != SC_SUCCESS) {
  ------------------
  |  |   28|    102|#define SC_SUCCESS				0
  ------------------
  |  Branch (2184:7): [True: 6, False: 96]
  ------------------
 2185|      6|			rv = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2186|      6|			LOG_TEST_GOTO_ERR(card->ctx, rv, "cannot encode RSA public key");
  ------------------
  |  |  184|      6|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      6|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      6|	int _ret = (r); \
  |  |  |  |  178|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      6|		goto err; \
  |  |  |  |  182|      6|	} \
  |  |  |  |  183|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2187|      6|		}
 2188|     96|		else {
 2189|     96|			if (out_len < offset) {
  ------------------
  |  Branch (2189:8): [True: 8, False: 88]
  ------------------
 2190|      8|				rv = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      8|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2191|      8|				goto err;
 2192|      8|			}
 2193|     88|			sz = MIN(out_len - offset, count);
  ------------------
  |  |   70|     88|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 71, False: 17]
  |  |  ------------------
  ------------------
 2194|     88|			memcpy(buf, out + offset, sz);
 2195|       |
 2196|     88|			sc_log_hex(card->ctx, "write_publickey", buf, sz);
  ------------------
  |  |  129|     88|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     88|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2197|     88|			rv = (int)sz;
 2198|     88|		}
 2199|  4.40k|	} else {
 2200|  4.40k|		rv = iso_ops->read_binary(card, offset, buf, count, 0);
 2201|  4.40k|	}
 2202|       |
 2203|  4.51k|err:
 2204|  4.51k|	free(bn[0].data);
 2205|  4.51k|	free(bn[1].data);
 2206|  4.51k|	free(out);
 2207|       |
 2208|  4.51k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  4.51k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.51k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.51k|	int _ret = r; \
  |  |  |  |  155|  4.51k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 861, False: 3.65k]
  |  |  |  |  ------------------
  |  |  |  |  156|    861|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    794|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 794, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  157|    861|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.65k|	} else { \
  |  |  |  |  159|  3.65k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.65k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.65k|	} \
  |  |  |  |  162|  4.51k|	return _ret; \
  |  |  |  |  163|  4.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2209|  4.51k|}
card-oberthur.c:auth_read_component:
 1481|    258|{
 1482|    258|	struct sc_apdu apdu;
 1483|    258|	int rv;
 1484|    258|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 1485|       |
 1486|    258|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    258|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    258|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    258|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    258|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 258]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|    258|	sc_log(card->ctx, "num %i, outlen %"SC_FORMAT_LEN_SIZE_T"u, type %i",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1488|    258|	       num, outlen, type);
 1489|       |
 1490|    258|	if (!outlen || type!=SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC)
  ------------------
  |  Branch (1490:6): [True: 0, False: 258]
  |  Branch (1490:17): [True: 0, False: 258]
  ------------------
 1491|    258|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1492|       |
 1493|    258|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB4,	num, 0x00);
  ------------------
  |  |  292|    258|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1494|    258|	apdu.cla |= 0x80;
 1495|    258|	apdu.le = outlen;
 1496|    258|	apdu.resp = resp;
 1497|    258|	apdu.resplen = sizeof(resp);
 1498|    258|	rv = sc_transmit_apdu(card, &apdu);
 1499|    258|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    258|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    258|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    258|	int _ret = (r); \
  |  |  |  |  168|    258|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 254]
  |  |  |  |  ------------------
  |  |  |  |  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|    258|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 254]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1500|       |
 1501|    254|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1502|    254|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    254|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    254|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    254|	int _ret = (r); \
  |  |  |  |  168|    254|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 229]
  |  |  |  |  ------------------
  |  |  |  |  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|    254|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 229]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1503|       |
 1504|    229|	if (outlen < apdu.resplen)
  ------------------
  |  Branch (1504:6): [True: 0, False: 229]
  ------------------
 1505|    229|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1506|       |
 1507|    229|	memcpy(out, apdu.resp, apdu.resplen);
 1508|    229|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    229|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    229|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    229|	int _ret = r; \
  |  |  |  |  155|    229|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15, False: 214]
  |  |  |  |  ------------------
  |  |  |  |  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|    214|	} else { \
  |  |  |  |  159|    214|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    214|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    214|	} \
  |  |  |  |  162|    229|	return _ret; \
  |  |  |  |  163|    229|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1509|    229|}
card-oberthur.c:auth_read_record:
 2215|    411|{
 2216|    411|	struct sc_apdu apdu;
 2217|    411|	int rv = 0;
 2218|    411|	unsigned char recvbuf[SC_MAX_APDU_BUFFER_SIZE];
 2219|       |
 2220|    411|	sc_log(card->ctx,
  ------------------
  |  |   71|    411|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2221|    411|	       "auth_read_record(): nr_rec %i; count %"SC_FORMAT_LEN_SIZE_T"u",
 2222|    411|	       nr_rec, count);
 2223|       |
 2224|    411|	if (nr_rec > 0xFF || idx != 0)
  ------------------
  |  Branch (2224:6): [True: 0, False: 411]
  |  Branch (2224:23): [True: 39, False: 372]
  ------------------
 2225|    411|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     39|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2226|       |
 2227|    372|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB2, nr_rec, 0);
  ------------------
  |  |  292|    372|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 2228|    372|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1300|    372|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
 2229|    372|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1305|    372|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (2229:6): [True: 372, False: 0]
  ------------------
 2230|    372|		apdu.p2 |= 0x04;
 2231|       |
 2232|    372|	apdu.le = MIN(count, SC_MAX_APDU_BUFFER_SIZE);
  ------------------
  |  |   70|    372|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 372, False: 0]
  |  |  ------------------
  ------------------
 2233|    372|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    372|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 2234|    372|	apdu.resp = recvbuf;
 2235|       |
 2236|    372|	rv = sc_transmit_apdu(card, &apdu);
 2237|    372|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    372|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    372|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    372|	int _ret = (r); \
  |  |  |  |  168|    372|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 369]
  |  |  |  |  ------------------
  |  |  |  |  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|    372|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 369]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2238|    369|	if (apdu.resplen == 0)
  ------------------
  |  Branch (2238:6): [True: 86, False: 283]
  ------------------
 2239|    369|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 36, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2240|    283|	if (count < apdu.resplen)
  ------------------
  |  Branch (2240:6): [True: 1, False: 282]
  ------------------
 2241|    283|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2242|    282|	memcpy(buf, recvbuf, apdu.resplen);
 2243|       |
 2244|    282|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2245|    282|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    282|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    282|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    282|	int _ret = (r); \
  |  |  |  |  168|    282|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 277]
  |  |  |  |  ------------------
  |  |  |  |  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|    282|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 277]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2246|       |
 2247|    277|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    277|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    277|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    277|	int _ret = r; \
  |  |  |  |  155|    277|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 277]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    277|	} else { \
  |  |  |  |  159|    277|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    277|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    277|	} \
  |  |  |  |  162|    277|	return _ret; \
  |  |  |  |  163|    277|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2248|    277|}
card-oberthur.c:auth_card_ctl:
 1453|      4|{
 1454|      4|	switch (cmd) {
 1455|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1455:2): [True: 0, False: 4]
  ------------------
 1456|      0|		return auth_get_default_key(card,
 1457|      0|				(struct sc_cardctl_default_key *) ptr);
 1458|      0|	case SC_CARDCTL_OBERTHUR_GENERATE_KEY:
  ------------------
  |  Branch (1458:2): [True: 0, False: 4]
  ------------------
 1459|      0|		return auth_generate_key(card, 0,
 1460|      0|				(struct sc_cardctl_oberthur_genkey_info *) ptr);
 1461|      0|	case SC_CARDCTL_OBERTHUR_UPDATE_KEY:
  ------------------
  |  Branch (1461:2): [True: 0, False: 4]
  ------------------
 1462|      0|		return auth_update_key(card,
 1463|      0|				(struct sc_cardctl_oberthur_updatekey_info *) ptr);
 1464|      0|	case SC_CARDCTL_OBERTHUR_CREATE_PIN:
  ------------------
  |  Branch (1464:2): [True: 0, False: 4]
  ------------------
 1465|      0|		return auth_create_reference_data(card,
 1466|      0|				(struct sc_cardctl_oberthur_createpin_info *) ptr);
 1467|      4|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1467:2): [True: 4, False: 0]
  ------------------
 1468|      4|		return auth_get_serialnr(card, (struct sc_serial_number *)ptr);
 1469|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1469:2): [True: 0, False: 4]
  ------------------
 1470|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1470:2): [True: 0, False: 4]
  ------------------
 1471|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1472|      0|	default:
  ------------------
  |  Branch (1472:2): [True: 0, False: 4]
  ------------------
 1473|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1474|      4|	}
 1475|      4|}
card-oberthur.c:auth_init_pin_info:
 1540|    770|{
 1541|    770|	pin->offset = 0;
 1542|    770|	pin->pad_char   = 0xFF;
 1543|    770|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    770|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1544|       |
 1545|    770|	if (type == OBERTHUR_AUTH_TYPE_PIN) {
  ------------------
  |  |   92|    770|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
  |  Branch (1545:6): [True: 770, False: 0]
  ------------------
 1546|    770|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|    770|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1547|    770|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|    770|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1548|    770|	} else {
 1549|      0|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1550|      0|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1551|      0|	}
 1552|    770|}
card-oberthur.c:auth_get_serialnr:
 2273|      4|{
 2274|      4|	if (!serial)
  ------------------
  |  Branch (2274:6): [True: 0, False: 4]
  ------------------
 2275|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|       |
 2277|      4|	if (card->serialnr.len==0)
  ------------------
  |  Branch (2277:6): [True: 0, False: 4]
  ------------------
 2278|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2279|       |
 2280|      4|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2281|       |
 2282|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2283|      4|}
card-oberthur.c:auth_process_fci:
  297|  2.34k|{
  298|  2.34k|	unsigned char type;
  299|  2.34k|	const unsigned char *attr;
  300|  2.34k|	size_t attr_len = 0;
  301|       |
  302|  2.34k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.34k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.34k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.34k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.34k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.34k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|  2.34k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  304|  2.34k|	if (!attr || attr_len < 1)
  ------------------
  |  Branch (304:6): [True: 529, False: 1.81k]
  |  Branch (304:15): [True: 11, False: 1.80k]
  ------------------
  305|  2.34k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    540|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    540|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    540|	int _ret = r; \
  |  |  |  |  155|    540|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 540, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    540|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    540|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 540, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    540|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    540|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    540|	return _ret; \
  |  |  |  |  163|    540|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|  1.80k|	type = attr[0];
  307|       |
  308|  1.80k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x83, &attr_len);
  309|  1.80k|	if (!attr || attr_len < 2)
  ------------------
  |  Branch (309:6): [True: 28, False: 1.77k]
  |  Branch (309:15): [True: 10, False: 1.76k]
  ------------------
  310|  1.80k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     38|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     38|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     38|	int _ret = r; \
  |  |  |  |  155|     38|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     38|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     38|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     38|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     38|	return _ret; \
  |  |  |  |  163|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  311|  1.76k|	file->id = attr[0]*0x100 + attr[1];
  312|       |
  313|  1.76k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, type==0x01 ? 0x80 : 0x85, &attr_len);
  ------------------
  |  Branch (313:50): [True: 875, False: 892]
  ------------------
  314|  1.76k|	switch (type) {
  315|    875|	case 0x01:
  ------------------
  |  Branch (315:2): [True: 875, False: 892]
  ------------------
  316|    875|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (316:7): [True: 13, False: 862]
  |  Branch (316:16): [True: 10, False: 852]
  ------------------
  317|    875|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     23|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     23|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|    852|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    852|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  319|    852|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    852|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    852|		file->size = attr[0]*0x100 + attr[1];
  321|    852|		break;
  322|    110|	case 0x04:
  ------------------
  |  Branch (322:2): [True: 110, False: 1.65k]
  ------------------
  323|    110|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (323:7): [True: 10, False: 100]
  |  Branch (323:16): [True: 10, False: 90]
  ------------------
  324|    110|			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|     90|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     90|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  326|     90|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|     90|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  327|     90|		file->size = attr[0];
  328|     90|		attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  329|     90|		if (!attr || attr_len < 5)
  ------------------
  |  Branch (329:7): [True: 0, False: 90]
  |  Branch (329:16): [True: 23, False: 67]
  ------------------
  330|     90|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     23|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     23|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|     67|		file->record_length = attr[2]*0x100+attr[3];
  332|     67|		file->record_count = attr[4];
  333|     67|		break;
  334|     38|	case 0x11:
  ------------------
  |  Branch (334:2): [True: 38, False: 1.72k]
  ------------------
  335|     38|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (335:7): [True: 11, False: 27]
  |  Branch (335:16): [True: 10, False: 17]
  ------------------
  336|     38|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|     17|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     17|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  338|     17|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_DES;
  339|     17|		file->size = attr[0]*0x100 + attr[1];
  340|     17|		file->size /= 8;
  341|     17|		break;
  342|    160|	case 0x12:
  ------------------
  |  Branch (342:2): [True: 160, False: 1.60k]
  ------------------
  343|    160|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (343:7): [True: 10, False: 150]
  |  Branch (343:16): [True: 10, False: 140]
  ------------------
  344|    160|			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|    140|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    140|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  346|    140|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC;
  347|       |
  348|    140|		file->size = attr[0]*0x100 + attr[1];
  349|    140|		if (file->size==512)
  ------------------
  |  Branch (349:7): [True: 30, False: 110]
  ------------------
  350|     30|			file->size = PUBKEY_512_ASN1_SIZE;
  ------------------
  |  |  100|     30|#define PUBKEY_512_ASN1_SIZE	0x4A
  ------------------
  351|    110|		else if (file->size==1024)
  ------------------
  |  Branch (351:12): [True: 13, False: 97]
  ------------------
  352|     13|			file->size = PUBKEY_1024_ASN1_SIZE;
  ------------------
  |  |  101|     13|#define PUBKEY_1024_ASN1_SIZE	0x8C
  ------------------
  353|     97|		else if (file->size==2048)
  ------------------
  |  Branch (353:12): [True: 1, False: 96]
  ------------------
  354|      1|			file->size = PUBKEY_2048_ASN1_SIZE;
  ------------------
  |  |  102|      1|#define PUBKEY_2048_ASN1_SIZE	0x10E
  ------------------
  355|     96|		else {
  356|     96|			sc_log(card->ctx,
  ------------------
  |  |   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|			       "Not supported public key size: %"SC_FORMAT_LEN_SIZE_T"u",
  358|     96|			       file->size);
  359|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|     96|		}
  361|     44|		break;
  362|     80|	case 0x14:
  ------------------
  |  Branch (362:2): [True: 80, False: 1.68k]
  ------------------
  363|     80|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (363:7): [True: 24, False: 56]
  |  Branch (363:16): [True: 10, False: 46]
  ------------------
  364|     80|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  365|     46|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     46|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  366|     46|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_CRT;
  367|     46|		file->size = attr[0]*0x100 + attr[1];
  368|     46|		break;
  369|    482|	case 0x38:
  ------------------
  |  Branch (369:2): [True: 482, False: 1.28k]
  ------------------
  370|    482|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (370:7): [True: 11, False: 471]
  |  Branch (370:16): [True: 10, False: 461]
  ------------------
  371|    482|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|    461|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    461|#define SC_FILE_TYPE_DF			0x04
  ------------------
  373|    461|		file->size = attr[0];
  374|    461|		if (SC_SUCCESS != sc_file_set_type_attr(file,attr,attr_len))
  ------------------
  |  |   28|    461|#define SC_SUCCESS				0
  ------------------
  |  Branch (374:7): [True: 0, False: 461]
  ------------------
  375|    461|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    461|		break;
  377|    461|	default:
  ------------------
  |  Branch (377:2): [True: 22, False: 1.74k]
  ------------------
  378|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|  1.76k|	}
  380|       |
  381|  1.48k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x86, &attr_len);
  382|  1.48k|	if (!attr || attr_len < 8)
  ------------------
  |  Branch (382:6): [True: 1.21k, False: 274]
  |  Branch (382:15): [True: 35, False: 239]
  ------------------
  383|  1.48k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.24k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.24k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.24k|	int _ret = r; \
  |  |  |  |  155|  1.24k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.24k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.24k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.24k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.24k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.24k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.24k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.24k|	return _ret; \
  |  |  |  |  163|  1.24k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|       |
  385|    239|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    239|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (385:6): [True: 138, False: 101]
  ------------------
  386|    138|		add_acl_entry(card, file, SC_AC_OP_CREATE, attr[0]);
  ------------------
  |  |  169|    138|#define SC_AC_OP_CREATE			3
  ------------------
  387|    138|		add_acl_entry(card, file, SC_AC_OP_CRYPTO, attr[1]);
  ------------------
  |  |  173|    138|#define SC_AC_OP_CRYPTO			7
  ------------------
  388|    138|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, attr[2]);
  ------------------
  |  |  172|    138|#define SC_AC_OP_LIST_FILES		6
  ------------------
  389|    138|		add_acl_entry(card, file, SC_AC_OP_DELETE, attr[3]);
  ------------------
  |  |  168|    138|#define SC_AC_OP_DELETE			2
  ------------------
  390|    138|		add_acl_entry(card, file, SC_AC_OP_PIN_DEFINE, attr[4]);
  ------------------
  |  |  183|    138|#define SC_AC_OP_PIN_DEFINE		17
  ------------------
  391|    138|		add_acl_entry(card, file, SC_AC_OP_PIN_CHANGE, attr[5]);
  ------------------
  |  |  184|    138|#define SC_AC_OP_PIN_CHANGE		18
  ------------------
  392|    138|		add_acl_entry(card, file, SC_AC_OP_PIN_RESET, attr[6]);
  ------------------
  |  |  185|    138|#define SC_AC_OP_PIN_RESET		19
  ------------------
  393|    138|		sc_log(card->ctx, "SC_FILE_TYPE_DF:CRYPTO %X", attr[1]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  394|    138|	} else if (file->type == SC_FILE_TYPE_INTERNAL_EF) { /* EF */
  ------------------
  |  |  215|    101|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (394:13): [True: 51, False: 50]
  ------------------
  395|     51|		switch (file->ef_structure) {
  ------------------
  |  Branch (395:11): [True: 51, False: 0]
  ------------------
  396|     16|		case SC_CARDCTL_OBERTHUR_KEY_DES:
  ------------------
  |  Branch (396:3): [True: 16, False: 35]
  ------------------
  397|     16|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     16|#define SC_AC_OP_UPDATE			23
  ------------------
  398|     16|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     16|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  399|     16|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     16|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  400|     16|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_CHECKSUM, attr[3]);
  ------------------
  |  |  179|     16|#define SC_AC_OP_PSO_COMPUTE_CHECKSUM	13
  ------------------
  401|     16|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_CHECKSUM, attr[4]);
  ------------------
  |  |  180|     16|#define SC_AC_OP_PSO_VERIFY_CHECKSUM	14
  ------------------
  402|     16|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     16|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  403|     16|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     16|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  404|     16|			break;
  405|     15|		case SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC:
  ------------------
  |  Branch (405:3): [True: 15, False: 36]
  ------------------
  406|     15|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     15|#define SC_AC_OP_UPDATE			23
  ------------------
  407|     15|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     15|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  408|     15|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_SIGNATURE, attr[4]);
  ------------------
  |  |  178|     15|#define SC_AC_OP_PSO_VERIFY_SIGNATURE	12
  ------------------
  409|     15|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     15|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  410|     15|			break;
  411|     20|		case SC_CARDCTL_OBERTHUR_KEY_RSA_CRT:
  ------------------
  |  Branch (411:3): [True: 20, False: 31]
  ------------------
  412|     20|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     20|#define SC_AC_OP_UPDATE			23
  ------------------
  413|     20|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     20|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  414|     20|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_SIGNATURE, attr[3]);
  ------------------
  |  |  177|     20|#define SC_AC_OP_PSO_COMPUTE_SIGNATURE	11
  ------------------
  415|     20|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     20|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  416|     20|			break;
  417|     51|		}
  418|     51|	} else {
  419|     50|		switch (file->ef_structure) {
  ------------------
  |  Branch (419:11): [True: 50, False: 0]
  ------------------
  420|     40|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     40|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (420:3): [True: 40, False: 10]
  ------------------
  421|     40|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     40|#define SC_AC_OP_WRITE			24
  ------------------
  422|     40|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     40|#define SC_AC_OP_UPDATE			23
  ------------------
  423|     40|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     40|#define SC_AC_OP_READ			22
  ------------------
  424|     40|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     40|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     40|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  425|     40|			break;
  426|     10|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     10|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (426:3): [True: 10, False: 40]
  ------------------
  427|     10|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     10|#define SC_AC_OP_WRITE			24
  ------------------
  428|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  429|     10|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     10|#define SC_AC_OP_READ			22
  ------------------
  430|     10|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     10|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     10|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  431|     10|			break;
  432|     50|		}
  433|     50|	}
  434|       |
  435|    239|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    239|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  436|    239|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    239|#define SC_FILE_MAGIC			0x14426950
  ------------------
  437|       |
  438|    239|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      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|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  439|    239|}
card-oberthur.c:add_acl_entry:
  260|  1.41k|{
  261|  1.41k|	if ((acl_byte & 0xE0) == 0x60) {
  ------------------
  |  Branch (261:6): [True: 156, False: 1.26k]
  ------------------
  262|    156|		sc_log(card->ctx, "called; op 0x%X; SC_AC_PRO; ref 0x%X", op, acl_byte);
  ------------------
  |  |   71|    156|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  263|    156|		sc_file_add_acl_entry(file, op, SC_AC_PRO, acl_byte);
  ------------------
  |  |  153|    156|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  264|    156|		return;
  265|    156|	}
  266|       |
  267|  1.26k|	switch (acl_byte) {
  268|    224|	case 0x00:
  ------------------
  |  Branch (268:2): [True: 224, False: 1.03k]
  ------------------
  269|    224|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    224|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    224|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  270|    224|		break;
  271|       |	/* User and OneTime PINs are locals */
  272|     79|	case 0x21:
  ------------------
  |  Branch (272:2): [True: 79, False: 1.18k]
  ------------------
  273|    125|	case 0x22:
  ------------------
  |  Branch (273:2): [True: 46, False: 1.21k]
  ------------------
  274|    125|		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |  151|    125|#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|    125|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
  275|    125|		break;
  276|       |	/* Local SOPIN is only for the unblocking. */
  277|    156|	case 0x24:
  ------------------
  |  Branch (277:2): [True: 156, False: 1.10k]
  ------------------
  278|    219|	case 0x25:
  ------------------
  |  Branch (278:2): [True: 63, False: 1.19k]
  ------------------
  279|    219|		if (op == SC_AC_OP_PIN_RESET)
  ------------------
  |  |  185|    219|#define SC_AC_OP_PIN_RESET		19
  ------------------
  |  Branch (279:7): [True: 37, False: 182]
  ------------------
  280|     37|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x84);
  ------------------
  |  |  151|     37|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  281|    182|		else
  282|    182|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x04);
  ------------------
  |  |  151|    182|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  283|    219|		break;
  284|    119|	case 0xFF:
  ------------------
  |  Branch (284:2): [True: 119, False: 1.14k]
  ------------------
  285|    119|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    119|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    119|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  286|    119|		break;
  287|    575|	default:
  ------------------
  |  Branch (287:2): [True: 575, False: 687]
  ------------------
  288|    575|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    575|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    575|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  289|    575|		break;
  290|  1.26k|	}
  291|  1.26k|}
card-oberthur.c:auth_pin_cmd:
 1894|    774|{
 1895|    774|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    774|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1896|       |
 1897|    774|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    774|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    774|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    774|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    774|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 774]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1898|    774|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    774|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1898:6): [True: 0, False: 774]
  ------------------
 1899|    774|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "auth_pin_cmd() unsupported PIN type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1900|       |
 1901|    774|	sc_log(card->ctx, "PIN CMD:%i; reference:%i; pin1:%p/%zu, pin2:%p/%zu", data->cmd,
  ------------------
  |  |   71|    774|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1902|    774|			data->pin_reference, data->pin1.data, data->pin1.len,
 1903|    774|			data->pin2.data, data->pin2.len);
 1904|    774|	switch (data->cmd) {
 1905|    770|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|    770|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1905:2): [True: 770, False: 4]
  ------------------
 1906|    770|		rv = auth_pin_verify(card, SC_AC_CHV, data);
  ------------------
  |  |  151|    770|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1907|    770|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|    770|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    770|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    770|	int _ret = (r); \
  |  |  |  |  168|    770|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 87, False: 683]
  |  |  |  |  ------------------
  |  |  |  |  169|     87|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     87|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     87|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     87|		return _ret; \
  |  |  |  |  172|     87|	} \
  |  |  |  |  173|    770|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 683]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1908|    683|		break;
 1909|    683|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1909:2): [True: 0, False: 774]
  ------------------
 1910|      0|		rv = auth_pin_change(card, SC_AC_CHV, data);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1911|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1912|      0|		break;
 1913|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1913:2): [True: 0, False: 774]
  ------------------
 1914|      0|		rv = auth_pin_reset(card, SC_AC_CHV, data);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1915|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1916|      0|		break;
 1917|      4|	default:
  ------------------
  |  Branch (1917:2): [True: 4, False: 770]
  ------------------
 1918|      4|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN operation");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1919|    774|	}
 1920|       |
 1921|    683|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    683|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    683|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    683|	int _ret = r; \
  |  |  |  |  155|    683|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 683, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    683|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 683]
  |  |  |  |  ------------------
  |  |  |  |  157|    683|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    683|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    683|	return _ret; \
  |  |  |  |  163|    683|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1922|    683|}
card-oberthur.c:auth_pin_verify:
 1614|    770|{
 1615|    770|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1616|    770|	int rv;
 1617|       |
 1618|    770|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    770|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    770|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    770|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    770|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 770]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|    770|	if (type != SC_AC_CHV)
  ------------------
  |  |  151|    770|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1620:6): [True: 0, False: 770]
  ------------------
 1621|    770|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "PIN type other then SC_AC_CHV is not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|    770|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|    770|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1624|       |
 1625|    770|	auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|    770|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1626|       |
 1627|       |	/* User PIN is always local. */
 1628|    770|	if (data->pin_reference == OBERTHUR_PIN_REFERENCE_USER
  ------------------
  |  |   42|  1.54k|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1628:6): [True: 353, False: 417]
  ------------------
 1629|    417|			|| data->pin_reference == OBERTHUR_PIN_REFERENCE_ONETIME)
  ------------------
  |  |   43|    417|#define OBERTHUR_PIN_REFERENCE_ONETIME	0x82
  ------------------
  |  Branch (1629:7): [True: 0, False: 417]
  ------------------
 1630|    353|		data->pin_reference  |= OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|    353|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1631|       |
 1632|    770|        rv = auth_pin_is_verified(card, data->pin_reference, &data->pin1.tries_left);
 1633|    770|    	sc_log(card->ctx, "auth_pin_is_verified returned rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1634|       |
 1635|       |	/* Return if only PIN status has been asked. */
 1636|    770|	if (data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1636:6): [True: 770, False: 0]
  |  Branch (1636:25): [True: 770, False: 0]
  ------------------
 1637|    770|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    770|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    770|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    770|	int _ret = r; \
  |  |  |  |  155|    770|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 770, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    770|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     87|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 87, False: 683]
  |  |  |  |  ------------------
  |  |  |  |  157|    770|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    770|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    770|	return _ret; \
  |  |  |  |  163|    770|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1638|       |
 1639|       |	/* Return SUCCESS without verifying if
 1640|       |	 * PIN has been already verified and PIN pad has to be used. */
 1641|      0|	if (!rv && !data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1641:6): [True: 0, False: 0]
  |  Branch (1641:13): [True: 0, False: 0]
  |  Branch (1641:33): [True: 0, False: 0]
  ------------------
 1642|      0|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1643|       |
 1644|      0|	if (!data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1644:6): [True: 0, False: 0]
  |  Branch (1644:26): [True: 0, False: 0]
  ------------------
 1645|      0|		rv = auth_pin_verify_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1646|      0|	else
 1647|      0|		rv = iso_drv->ops->pin_cmd(card, data);
 1648|       |
 1649|      0|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|      0|}
card-oberthur.c:auth_pin_is_verified:
 1655|    770|{
 1656|    770|	struct sc_apdu apdu;
 1657|    770|	int rv;
 1658|       |
 1659|    770|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_reference);
  ------------------
  |  |  291|    770|#define SC_APDU_CASE_1			0x01
  ------------------
 1660|       |
 1661|    770|	rv = sc_transmit_apdu(card, &apdu);
 1662|    770|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    770|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    770|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    770|	int _ret = (r); \
  |  |  |  |  168|    770|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 767]
  |  |  |  |  ------------------
  |  |  |  |  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|    770|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 767]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1663|       |
 1664|    767|	if (tries_left && apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1664:6): [True: 767, False: 0]
  |  Branch (1664:20): [True: 34, False: 733]
  |  Branch (1664:40): [True: 17, False: 17]
  ------------------
 1665|     17|		*tries_left = apdu.sw2 & 0x0F;
 1666|       |
 1667|       |	/* Replace 'no tries left' with 'auth method blocked' */
 1668|    767|	if (apdu.sw1 == 0x63 && apdu.sw2 == 0xC0) {
  ------------------
  |  Branch (1668:6): [True: 34, False: 733]
  |  Branch (1668:26): [True: 4, False: 30]
  ------------------
 1669|      4|		apdu.sw1 = 0x69;
 1670|      4|		apdu.sw2 = 0x83;
 1671|      4|	}
 1672|       |
 1673|    767|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1674|       |
 1675|    767|	return rv;
 1676|    770|}
card-oberthur.c:auth_check_sw:
 2296|  13.7k|{
 2297|  13.7k|	int ii;
 2298|       |
 2299|  27.4k|	for (ii = 0; auth_warnings[ii].SWs; ii++) {
  ------------------
  |  Branch (2299:15): [True: 13.7k, False: 13.6k]
  ------------------
 2300|  13.7k|		if (auth_warnings[ii].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (2300:7): [True: 93, False: 13.6k]
  ------------------
 2301|     93|			sc_log(card->ctx, "%s", auth_warnings[ii].errorstr);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2302|     93|			return auth_warnings[ii].errorno;
 2303|     93|		}
 2304|  13.7k|	}
 2305|       |
 2306|  13.6k|	return iso_ops->check_sw(card, sw1, sw2);
 2307|  13.7k|}

populate_blobs_to_mf:
  381|    633|{
  382|    633|	pgp_do_info_t	*info;
  383|  38.2k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (383:33): [True: 38.2k, False: 0]
  |  Branch (383:51): [True: 37.6k, False: 633]
  ------------------
  384|  37.6k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (384:7): [True: 27.8k, False: 9.77k]
  |  Branch (384:53): [True: 12.0k, False: 15.8k]
  ------------------
  385|  12.0k|			pgp_blob_t *child = NULL;
  386|  12.0k|			sc_file_t *file = sc_file_new();
  387|       |
  388|  12.0k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  389|       |
  390|       |			/* catch out of memory condition */
  391|  12.0k|			if (child == NULL) {
  ------------------
  |  Branch (391:8): [True: 0, False: 12.0k]
  ------------------
  392|      0|				sc_file_free(file);
  393|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|      0|			}
  395|  12.0k|		}
  396|  37.6k|	}
  397|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|    633|}
_pgp_handle_curve25519:
  717|  2.86k|{
  718|  2.86k|	if (!card || !key_info)
  ------------------
  |  Branch (718:6): [True: 0, False: 2.86k]
  |  Branch (718:15): [True: 0, False: 2.86k]
  ------------------
  719|      0|		return 0;
  720|  2.86k|	if (!sc_compare_oid(&key_info->u.ec.oid, &curve25519_oid) &&
  ------------------
  |  Branch (720:6): [True: 2.86k, False: 0]
  ------------------
  721|  2.86k|			!sc_compare_oid(&key_info->u.ec.oid, &X25519_oid))
  ------------------
  |  Branch (721:4): [True: 517, False: 2.35k]
  ------------------
  722|    517|		return 0;
  723|       |
  724|       |	/* CKM_XEDDSA supports both Sign and Derive, but
  725|       |	* OpenPGP card supports only derivation using these
  726|       |	* keys as far as I know */
  727|  2.35k|	_sc_card_add_xeddsa_alg(card, key_info->u.ec.key_length,
  728|  2.35k|			SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  182|  2.35k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              			SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  102|  2.35k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  729|  2.35k|	sc_log(card->ctx, "DO %uX: Added XEDDSA algorithm (%d), mod_len = %zu",
  ------------------
  |  |   71|  2.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  730|  2.35k|	    do_num, SC_ALGORITHM_XEDDSA, key_info->u.ec.key_length);
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  2.35k|#define SC_ALGORITHM_XEDDSA		5
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  730|  2.35k|	    do_num, SC_ALGORITHM_XEDDSA, key_info->u.ec.key_length);
  731|  2.35k|	return 1;
  732|  2.86k|}
_pgp_add_algo:
  736|  3.20k|{
  737|  3.20k|	unsigned long flags = 0, ext_flags = 0;
  738|       |
  739|  3.20k|	if (!card || !key_info)
  ------------------
  |  Branch (739:6): [True: 0, False: 3.20k]
  |  Branch (739:15): [True: 0, False: 3.20k]
  ------------------
  740|      0|		return 0;
  741|       |
  742|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  743|  3.20k|	switch (key_info->algorithm) {
  744|    112|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  869|    112|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (744:2): [True: 112, False: 3.09k]
  ------------------
  745|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 /
  746|       |		 * v3.x section 7.2.11 & 7.2.12 */
  747|    112|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  120|    112|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    112|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|    112|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  748|    112|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  142|    112|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  749|    112|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |  102|    112|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  750|       |
  751|    112|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  752|    112|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %"
  ------------------
  |  |   71|    112|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  753|    112|			SC_FORMAT_LEN_SIZE_T"u",
  754|    112|			do_num, key_info->u.rsa.modulus_len);
  755|    112|		break;
  756|  1.58k|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  870|  1.58k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (756:2): [True: 1.58k, False: 1.62k]
  ------------------
  757|       |		/* The montgomery curve (curve25519) needs to go through
  758|       |		 * different paths, otherwise we handle it as a normal EC key */
  759|  1.58k|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (759:7): [True: 1.25k, False: 322]
  ------------------
  760|  1.25k|			break;
  761|       |		/* fall through */
  762|    546|	case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  871|    546|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (762:2): [True: 224, False: 2.98k]
  ------------------
  763|       |		/* v3.0+: ECC [RFC 4880 & 6637] */
  764|       |
  765|       |		/* Allow curve to be used by both ECDH and ECDSA.
  766|       |		 * pgp_init set these flags the same way */
  767|    546|		flags = SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  182|    546|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  768|    546|		flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  183|    546|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  769|    546|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    546|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    546|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  770|    546|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    546|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  771|    546|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  210|    546|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  772|       |
  773|    546|		_sc_card_add_ec_alg(card, key_info->u.ec.key_length, flags, ext_flags,
  774|    546|			&key_info->u.ec.oid);
  775|    546|		sc_log(card->ctx, "DO %uX: Added EC algorithm (%d), mod_len = %zu" ,
  ------------------
  |  |   71|    546|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  776|    546|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  777|    546|		break;
  778|  1.28k|	case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  872|  1.28k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (778:2): [True: 1.28k, False: 1.91k]
  ------------------
  779|       |		/* EdDSA from draft-ietf-openpgp-rfc4880bis-08 */
  780|       |		/* Handle Yubikey bug, that in DO FA curve25519 has EDDSA algo */
  781|  1.28k|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (781:7): [True: 1.09k, False: 195]
  ------------------
  782|  1.09k|			break;
  783|    195|		_sc_card_add_eddsa_alg(card, key_info->u.ec.key_length,
  784|    195|				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  197|    195|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
              				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  102|    195|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  785|       |
  786|    195|		sc_log(card->ctx, "DO %uX: Added EDDSA algorithm (%d), mod_len = %zu" ,
  ------------------
  |  |   71|    195|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  787|    195|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  788|    195|		break;
  789|      0|	default:
  ------------------
  |  Branch (789:2): [True: 0, False: 3.20k]
  ------------------
  790|      0|		sc_log(card->ctx, "DO %uX: Unknown algorithm ID (%d)" ,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  791|      0|			do_num, key_info->algorithm);
  792|       |		/* return "false" if we do not understand algo */
  793|      0|		return 0;
  794|  3.20k|	}
  795|       |	/* return true */
  796|  3.20k|	return 1;
  797|  3.20k|}
sc_get_openpgp_driver:
 4211|  15.0k|{
 4212|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4213|       |
 4214|  15.0k|	iso_ops = iso_drv->ops;
 4215|       |
 4216|  15.0k|	pgp_ops = *iso_ops;
 4217|  15.0k|	pgp_ops.match_card	= pgp_match_card;
 4218|  15.0k|	pgp_ops.init		= pgp_init;
 4219|  15.0k|	pgp_ops.finish		= pgp_finish;
 4220|  15.0k|	pgp_ops.select_file	= pgp_select_file;
 4221|  15.0k|	pgp_ops.list_files	= pgp_list_files;
 4222|  15.0k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4223|  15.0k|	pgp_ops.read_binary	= pgp_read_binary;
 4224|  15.0k|	pgp_ops.write_binary	= NULL;
 4225|  15.0k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4226|  15.0k|	pgp_ops.logout		= pgp_logout;
 4227|  15.0k|	pgp_ops.get_data	= pgp_get_data;
 4228|  15.0k|	pgp_ops.put_data	= pgp_put_data;
 4229|  15.0k|	pgp_ops.set_security_env= pgp_set_security_env;
 4230|  15.0k|	pgp_ops.compute_signature= pgp_compute_signature;
 4231|  15.0k|	pgp_ops.decipher	= pgp_decipher;
 4232|  15.0k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4233|  15.0k|	pgp_ops.delete_file	= pgp_delete_file;
 4234|  15.0k|	pgp_ops.update_binary	= pgp_update_binary;
 4235|  15.0k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4236|       |
 4237|  15.0k|	return &pgp_drv;
 4238|  15.0k|}
card-openpgp.c:pgp_new_blob:
 1237|  37.6k|{
 1238|  37.6k|	pgp_blob_t *blob = NULL;
 1239|       |
 1240|  37.6k|	if (file == NULL)
  ------------------
  |  Branch (1240:6): [True: 0, False: 37.6k]
  ------------------
 1241|      0|		return NULL;
 1242|       |
 1243|  37.6k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1243:6): [True: 37.6k, False: 0]
  ------------------
 1244|  37.6k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  37.6k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1245|  37.6k|		pgp_do_info_t *info;
 1246|       |
 1247|  37.6k|		blob->file = file;
 1248|       |
 1249|  37.6k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  37.6k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1250|  37.6k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  37.6k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1251|  37.6k|		blob->file->id           = file_id;
 1252|       |
 1253|  37.6k|		blob->id     = file_id;
 1254|  37.6k|		blob->parent = parent;
 1255|       |
 1256|  37.6k|		if (parent != NULL) {
  ------------------
  |  Branch (1256:7): [True: 37.0k, False: 633]
  ------------------
 1257|  37.0k|			pgp_blob_t **p;
 1258|       |
 1259|       |			/* set file's path = parent's path + file's id */
 1260|  37.0k|			blob->file->path = parent->file->path;
 1261|  37.0k|			sc_append_file_id(&blob->file->path, file_id);
 1262|       |
 1263|       |			/* append blob to list of parent's children */
 1264|  3.47M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1264:29): [True: 3.44M, False: 37.0k]
  ------------------
 1265|  3.44M|				;
 1266|  37.0k|			*p = blob;
 1267|  37.0k|		}
 1268|    633|		else {
 1269|    633|			char path[10] = "0000";	/* long enough */
 1270|       |
 1271|       |			/* no parent: set file's path = file's id */
 1272|    633|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1272:8): [True: 0, False: 633]
  ------------------
 1273|      0|				free(blob);
 1274|      0|				return NULL;
 1275|      0|			}
 1276|       |
 1277|    633|			sc_format_path(path, &blob->file->path);
 1278|    633|		}
 1279|       |
 1280|       |		/* find matching DO info: set file type depending on it */
 1281|  1.52M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1281:34): [True: 1.52M, False: 0]
  |  Branch (1281:52): [True: 1.51M, False: 9.89k]
  ------------------
 1282|  1.51M|			if (info->id == file_id) {
  ------------------
  |  Branch (1282:8): [True: 27.7k, False: 1.48M]
  ------------------
 1283|  27.7k|				blob->info = info;
 1284|  27.7k|				blob->file->type = blob->info->type;
 1285|  27.7k|				pgp_attach_acl(card, blob->file, info);
 1286|  27.7k|				break;
 1287|  27.7k|			}
 1288|  1.51M|		}
 1289|  37.6k|	}
 1290|       |
 1291|  37.6k|	return blob;
 1292|  37.6k|}
card-openpgp.c:pgp_attach_acl:
 1169|  27.7k|{
 1170|  27.7k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  27.7k|#define SC_AC_NONE			0x00000000
  ------------------
 1171|  27.7k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  27.7k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1172|       |
 1173|       |	/* Write access */
 1174|  27.7k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1174:10): [True: 27.7k, False: 0]
  ------------------
 1175|  7.93k|	case WRITE_NEVER:
  ------------------
  |  Branch (1175:2): [True: 7.93k, False: 19.8k]
  ------------------
 1176|  7.93k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  7.93k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1177|  7.93k|		break;
 1178|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1178:2): [True: 0, False: 27.7k]
  ------------------
 1179|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1180|      0|		key_ref = 0x01;
 1181|      0|		break;
 1182|  1.26k|	case WRITE_PIN2:
  ------------------
  |  Branch (1182:2): [True: 1.26k, False: 26.5k]
  ------------------
 1183|  1.26k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.26k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1184|  1.26k|		key_ref = 0x02;
 1185|  1.26k|		break;
 1186|  18.5k|	case WRITE_PIN3:
  ------------------
  |  Branch (1186:2): [True: 18.5k, False: 9.19k]
  ------------------
 1187|  18.5k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  18.5k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1188|  18.5k|		key_ref = 0x03;
 1189|  18.5k|		break;
 1190|  27.7k|	}
 1191|       |
 1192|  27.7k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  55.5k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|      0|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1192:6): [True: 27.7k, False: 0]
  |  Branch (1192:30): [True: 0, False: 0]
  ------------------
 1193|  27.7k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  27.7k|#define SC_AC_OP_WRITE			24
  ------------------
 1194|  27.7k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  27.7k|#define SC_AC_OP_UPDATE			23
  ------------------
 1195|  27.7k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  27.7k|#define SC_AC_OP_DELETE			2
  ------------------
 1196|  27.7k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  27.7k|#define SC_AC_OP_CREATE			3
  ------------------
 1197|  27.7k|	}
 1198|      0|	else {
 1199|       |		/* When SC_AC_OP_DELETE is absent, we need to provide
 1200|       |		 * SC_AC_OP_DELETE_SELF for sc_pkcs15init_delete_by_path() */
 1201|      0|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE_SELF, method, key_ref);
  ------------------
  |  |  174|      0|#define SC_AC_OP_DELETE_SELF		8
  ------------------
 1202|      0|	}
 1203|       |
 1204|  27.7k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  27.7k|#define SC_AC_NONE			0x00000000
  ------------------
 1205|  27.7k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  27.7k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1206|       |	/* Read access */
 1207|  27.7k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1207:10): [True: 3.97k, False: 23.7k]
  ------------------
 1208|  2.70k|	case READ_NEVER:
  ------------------
  |  Branch (1208:2): [True: 2.70k, False: 25.0k]
  ------------------
 1209|  2.70k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  2.70k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1210|  2.70k|		break;
 1211|      0|	case READ_PIN1:
  ------------------
  |  Branch (1211:2): [True: 0, False: 27.7k]
  ------------------
 1212|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1213|      0|		key_ref = 0x01;
 1214|      0|		break;
 1215|    633|	case READ_PIN2:
  ------------------
  |  Branch (1215:2): [True: 633, False: 27.1k]
  ------------------
 1216|    633|		method = SC_AC_CHV;
  ------------------
  |  |  151|    633|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1217|    633|		key_ref = 0x02;
 1218|    633|		break;
 1219|    633|	case READ_PIN3:
  ------------------
  |  Branch (1219:2): [True: 633, False: 27.1k]
  ------------------
 1220|    633|		method = SC_AC_CHV;
  ------------------
  |  |  151|    633|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1221|    633|		key_ref = 0x03;
 1222|    633|		break;
 1223|  27.7k|	}
 1224|       |
 1225|  27.7k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  55.5k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  23.7k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1225:6): [True: 3.97k, False: 23.7k]
  |  Branch (1225:30): [True: 0, False: 23.7k]
  ------------------
 1226|  3.97k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  3.97k|#define SC_AC_OP_READ			22
  ------------------
 1227|  3.97k|	}
 1228|  27.7k|}
card-openpgp.c:pgp_match_card:
  326|  3.29k|{
  327|  3.29k|	int i;
  328|       |
  329|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.29k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.29k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 20, False: 3.27k]
  ------------------
  333|     20|		card->name = pgp_atrs[i].name;
  334|     20|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  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: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"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|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|     20|	}
  336|  3.27k|	else {
  337|  3.27k|		sc_path_t	partial_aid;
  338|  3.27k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.27k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.27k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.27k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.27k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.27k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.27k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 635, False: 2.63k]
  ------------------
  346|    635|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    635|			card->name = default_cardname;
  348|       |
  349|    635|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 634, False: 1]
  ------------------
  350|    634|				(void) get_full_pgp_aid(card, file);
  351|    635|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 16, False: 619]
  ------------------
  352|     16|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     16|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     16|				switch (major) {
  355|      6|					case 1:
  ------------------
  |  Branch (355:6): [True: 6, False: 10]
  ------------------
  356|      6|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      6|						card->name = default_cardname_v1;
  358|      6|						break;
  359|      3|					case 2:
  ------------------
  |  Branch (359:6): [True: 3, False: 13]
  ------------------
  360|      3|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|      3|						card->name = default_cardname_v2;
  362|      3|						break;
  363|      4|					case 3:
  ------------------
  |  Branch (363:6): [True: 4, False: 12]
  ------------------
  364|      4|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      4|						card->name = default_cardname_v3;
  366|      4|						break;
  367|      3|					default:
  ------------------
  |  Branch (367:6): [True: 3, False: 13]
  ------------------
  368|      3|						break;
  369|     16|				}
  370|     16|			}
  371|    635|			sc_file_free(file);
  372|    635|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    635|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    635|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    635|	int _ret = r; \
  |  |  |  |  155|    635|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 635]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    635|	} else { \
  |  |  |  |  159|    635|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    635|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    635|	} \
  |  |  |  |  162|    635|	return _ret; \
  |  |  |  |  163|    635|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    635|		}
  374|  3.27k|	}
  375|  2.63k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.63k|	int _ret = r; \
  |  |  |  |  155|  2.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.63k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.63k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.63k|	return _ret; \
  |  |  |  |  163|  2.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.63k|}
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: 529, False: 743]
  |  |  ------------------
  ------------------
  314|  1.27k|	}
  315|       |
  316|  1.27k|	return r;
  317|  1.27k|}
card-openpgp.c:pgp_init:
  405|    655|{
  406|    655|	struct pgp_priv_data *priv;
  407|    655|	sc_path_t	path;
  408|    655|	sc_file_t	*file = NULL;
  409|    655|	int		r, i;
  410|       |
  411|    655|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    655|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    655|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    655|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    655|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 655]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|       |
  413|    655|	priv = calloc (1, sizeof *priv);
  414|    655|	if (!priv)
  ------------------
  |  Branch (414:6): [True: 0, False: 655]
  ------------------
  415|    655|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|    655|	card->drv_data = priv;
  417|       |
  418|    655|	card->cla = 0x00;
  419|       |
  420|       |	/* select application "OpenPGP" */
  421|    655|	sc_format_path("D276:0001:2401", &path);
  422|    655|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    655|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  423|    655|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (423:6): [True: 16, False: 639]
  ------------------
  424|     16|		sc_file_free(file);
  425|     16|		pgp_finish(card);
  426|     16|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|     16|	}
  428|       |
  429|       |	/* defensive programming check */
  430|    639|	if (!file)   {
  ------------------
  |  Branch (430:6): [True: 0, False: 639]
  ------------------
  431|      0|		pgp_finish(card);
  432|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  433|      0|	}
  434|       |
  435|    639|	if (file->namelen != 16) {
  ------------------
  |  Branch (435:6): [True: 638, False: 1]
  ------------------
  436|       |		/* explicitly get the full aid */
  437|    638|		r = get_full_pgp_aid(card, file);
  438|    638|		if (r < 0) {
  ------------------
  |  Branch (438:7): [True: 6, False: 632]
  ------------------
  439|      6|			sc_file_free(file);
  440|      6|			pgp_finish(card);
  441|      6|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  442|      6|		}
  443|    638|	}
  444|       |
  445|       |	/* read information from AID */
  446|    633|	if (file->namelen == 16) {
  ------------------
  |  Branch (446:6): [True: 464, False: 169]
  ------------------
  447|    464|		static char card_name[SC_MAX_APDU_BUFFER_SIZE] = "OpenPGP card";
  448|       |
  449|       |		/* OpenPGP card spec 1.1, 2.x & 3.x, section 4.2.1 & 4.1.2.1 */
  450|    464|		priv->bcd_version = bebytes2ushort(file->name + 6);
  451|    464|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    464|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  452|    464|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    464|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  453|       |
  454|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  455|    464|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (455:7): [True: 4, False: 460]
  ------------------
  456|    460|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (456:7): [True: 1, False: 459]
  ------------------
  457|    459|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (457:7): [True: 1, False: 458]
  ------------------
  458|      6|			snprintf(card_name, sizeof(card_name),
  459|      6|				 "OpenPGP card v%u.%u (%04X %08lX)",
  460|      6|				 card->version.hw_major, card->version.hw_minor,
  461|      6|				 bebytes2ushort(file->name + 8),
  462|      6|				 bebytes2ulong(file->name + 10));
  463|      6|		}
  464|    458|		else if (card->name != NULL) {
  ------------------
  |  Branch (464:12): [True: 458, False: 0]
  ------------------
  465|       |			/* for other cards, append serial number to the card name */
  466|    458|			snprintf(card_name, sizeof(card_name),
  467|    458|				 "%s (%04X %08lX)",
  468|    458|				 card->name,
  469|    458|				 bebytes2ushort(file->name + 8),
  470|    458|				 bebytes2ulong(file->name + 10));
  471|    458|		}
  472|    464|		card->name = card_name;
  473|       |
  474|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  475|    464|		memcpy(card->serialnr.value, file->name + 8, 6);
  476|    464|		card->serialnr.len = 6;
  477|    464|	} else {
  478|       |		/* set detailed card version */
  479|    169|		switch (card->type) {
  480|      1|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (480:4): [True: 1, False: 168]
  ------------------
  481|      1|				priv->bcd_version = OPENPGP_CARD_3_0;
  482|      1|				break;
  483|      3|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (483:4): [True: 3, False: 166]
  ------------------
  484|      4|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (484:4): [True: 1, False: 168]
  ------------------
  485|      4|				priv->bcd_version = OPENPGP_CARD_2_0;
  486|      4|				break;
  487|    164|			default:
  ------------------
  |  Branch (487:4): [True: 164, False: 5]
  ------------------
  488|    164|				priv->bcd_version = OPENPGP_CARD_1_1;
  489|    164|				break;
  490|    169|		}
  491|    169|	}
  492|       |
  493|       |	/* set pointer to correct list of card objects */
  494|    633|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (494:22): [True: 196, False: 437]
  ------------------
  495|    633|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (495:8): [True: 6, False: 431]
  ------------------
  496|    437|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (496:8): [True: 18, False: 413]
  ------------------
  497|    431|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (497:8): [True: 4, False: 409]
  ------------------
  498|    413|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (498:8): [True: 4, False: 405]
  ------------------
  499|    409|			  :					     pgp34_objects;
  500|       |
  501|       |	/* With gnuk, we use different curves */
  502|    633|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (502:6): [True: 17, False: 616]
  ------------------
  503|     17|		priv->ec_curves = ec_curves_gnuk;
  504|    616|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (504:13): [True: 398, False: 218]
  ------------------
  505|    398|		priv->ec_curves = ec_curves_openpgp34;
  506|    398|	} else {
  507|    218|		priv->ec_curves = ec_curves_openpgp;
  508|    218|	}
  509|       |
  510|       |	/* change file path to MF for reuse in MF */
  511|    633|	sc_format_path("3f00", &file->path);
  512|       |
  513|       |	/* set up the root of our fake file tree */
  514|       |	/* Transfers ownership of the file to the priv->mf structure */
  515|    633|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  516|    633|	if (!priv->mf) {
  ------------------
  |  Branch (516:6): [True: 0, False: 633]
  ------------------
  517|      0|		sc_file_free(file);
  518|      0|		pgp_finish(card);
  519|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|      0|	}
  521|       |
  522|       |	/* select MF */
  523|    633|	priv->current = priv->mf;
  524|       |
  525|    633|	r = populate_blobs_to_mf(card, priv);
  526|    633|	if (r < 0) {
  ------------------
  |  Branch (526:6): [True: 0, False: 633]
  ------------------
  527|      0|		pgp_finish(card);
  528|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  529|      0|	}
  530|       |
  531|       |	/* get card_features from ATR & DOs */
  532|    633|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (532:6): [True: 90, False: 543]
  ------------------
  533|     90|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     90|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     90|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     90|	int _ret = r; \
  |  |  |  |  155|     90|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 90, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     90|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 90]
  |  |  |  |  ------------------
  |  |  |  |  157|     90|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     90|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     90|	return _ret; \
  |  |  |  |  163|     90|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|     90|	}
  535|       |
  536|       |	/* if algorithm attributes can be changed,
  537|       |	 * add supported algorithms based on specification for pkcs15-init */
  538|    543|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (538:6): [True: 30, False: 513]
  ------------------
  539|     30|		unsigned long flags_rsa, flags_ecc, ext_flags;
  540|     30|		unsigned long flags_eddsa, flags_xeddsa;
  541|       |
  542|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 / v3.x section 7.2.11 & 7.2.12 */
  543|     30|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  120|     30|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|     30|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|     30|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  544|     30|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  142|     30|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  545|     30|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     30|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  546|     30|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  183|     30|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  547|     30|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  182|     30|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  548|     30|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  184|     30|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|     30|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  549|     30|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     30|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     30|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  210|     30|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  551|       |
  552|     30|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  197|     30|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  553|     30|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     30|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|       |		/* xeddsa may allow signing at some time */
  555|     30|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  182|     30|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  556|     30|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     30|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  557|       |
  558|     30|		switch (card->type) {
  559|      0|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (559:4): [True: 0, False: 30]
  ------------------
  560|       |				/* RSA 1024 was removed for v3+ */
  561|      0|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  562|      0|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  563|       |				/* fallthrough */
  564|      0|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (564:4): [True: 0, False: 30]
  ------------------
  565|      0|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  566|      0|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (566:15): [True: 0, False: 0]
  ------------------
  567|      0|				{
  568|      0|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (568:10): [True: 0, False: 0]
  ------------------
  569|      0|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  570|      0|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  571|      0|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (571:15): [True: 0, False: 0]
  ------------------
  572|      0|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  573|      0|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  574|      0|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (574:15): [True: 0, False: 0]
  ------------------
  575|      0|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  576|      0|								flags_xeddsa, ext_flags, &priv->ec_curves[i].oid);
  577|      0|					else
  578|      0|						LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  579|      0|				}
  580|      0|				break;
  581|      0|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (581:4): [True: 0, False: 30]
  ------------------
  582|     30|			default:
  ------------------
  |  Branch (582:4): [True: 30, False: 0]
  ------------------
  583|     30|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  584|     30|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  585|     30|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  586|     30|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  587|     30|				break;
  588|     30|		}
  589|     30|	}
  590|       |
  591|    543|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    543|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    543|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    543|	int _ret = r; \
  |  |  |  |  155|    543|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 543, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    543|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 543]
  |  |  |  |  ------------------
  |  |  |  |  157|    543|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    543|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    543|	return _ret; \
  |  |  |  |  163|    543|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|    543|}
card-openpgp.c:pgp_get_blob:
 1477|  5.30k|{
 1478|  5.30k|	pgp_blob_t		*child;
 1479|  5.30k|	int			r;
 1480|       |
 1481|  5.30k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1481:6): [True: 1.15k, False: 4.14k]
  ------------------
 1482|  1.15k|		return r;
 1483|       |
 1484|  42.3k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1484:28): [True: 40.5k, False: 1.72k]
  ------------------
 1485|  40.5k|		if (child->id == id) {
  ------------------
  |  Branch (1485:7): [True: 2.41k, False: 38.1k]
  ------------------
 1486|  2.41k|			(void) pgp_read_blob(card, child);
 1487|  2.41k|			*ret = child;
 1488|  2.41k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.41k|#define SC_SUCCESS				0
  ------------------
 1489|  2.41k|		}
 1490|  40.5k|	}
 1491|       |
 1492|       |	/* This part is for "NOT FOUND" cases */
 1493|       |
 1494|       |	/* Special case:
 1495|       |	 * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
 1496|       |	 * So, if these blob was not found, we create it. */
 1497|  1.72k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  3.45k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|     78|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|     78|#define DO_LANG_PREF             0x5f2d
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  157|      0|#define DO_SEX                   0x5f35
  ------------------
  |  Branch (1497:6): [True: 39, False: 1.68k]
  |  Branch (1497:36): [True: 0, False: 39]
  |  Branch (1497:53): [True: 39, False: 0]
  |  Branch (1497:75): [True: 0, False: 0]
  ------------------
 1498|     39|		sc_log(card->ctx, "Create blob %X under %X", id, blob->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__
  |  |  ------------------
  ------------------
 1499|     39|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1500|     39|		if (child) {
  ------------------
  |  Branch (1500:7): [True: 39, False: 0]
  ------------------
 1501|     39|			pgp_set_blob(child, NULL, 0);
 1502|     39|			*ret = child;
 1503|     39|			return SC_SUCCESS;
  ------------------
  |  |   28|     39|#define SC_SUCCESS				0
  ------------------
 1504|     39|		}
 1505|      0|		else
 1506|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1507|     39|			       "Not enough memory to create blob for DO %X",
 1508|     39|			       id);
 1509|     39|	}
 1510|       |
 1511|  1.68k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.68k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1512|  1.72k|}
card-openpgp.c:pgp_enumerate_blob:
 1395|  5.70k|{
 1396|  5.70k|	const u8	*in;
 1397|  5.70k|	int		r;
 1398|  5.70k|	sc_file_t	*file = NULL;
 1399|       |
 1400|  5.70k|	if (blob->files != NULL)
  ------------------
  |  Branch (1400:6): [True: 3.84k, False: 1.86k]
  ------------------
 1401|  3.84k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.84k|#define SC_SUCCESS				0
  ------------------
 1402|       |
 1403|  1.86k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1403:6): [True: 1.12k, False: 741]
  ------------------
 1404|  1.12k|		return r;
 1405|       |
 1406|    741|	in = blob->data;
 1407|       |
 1408|  26.1k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1408:9): [True: 25.8k, False: 380]
  ------------------
 1409|  25.8k|		unsigned int	cla, tag, tmptag;
 1410|  25.8k|		size_t		len;
 1411|  25.8k|		const u8	*data = in;
 1412|  25.8k|		pgp_blob_t	*new;
 1413|       |
 1414|  25.8k|		if (!in)
  ------------------
  |  Branch (1414:7): [True: 0, False: 25.8k]
  ------------------
 1415|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1416|       |
 1417|  25.8k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1418|  25.8k|					&cla, &tag, &len);
 1419|  25.8k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  25.8k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1419:7): [True: 110, False: 25.6k]
  ------------------
 1420|    110|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   71|    110|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1421|    110|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    110|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1422|    110|		}
 1423|       |		/* Check for unknown error, or empty data */
 1424|  25.6k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    418|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1424:8): [True: 418, False: 25.2k]
  |  Branch (1424:19): [True: 0, False: 418]
  ------------------
 1425|  25.6k|		    (data == NULL)) {
  ------------------
  |  Branch (1425:7): [True: 89, False: 25.6k]
  ------------------
 1426|     89|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1427|     89|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|     89|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1428|     89|		}
 1429|       |
 1430|       |		/* undo ASN1's split of tag & class */
 1431|  25.9k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1431:22): [True: 382, False: 25.6k]
  ------------------
 1432|    382|			cla <<= 8;
 1433|    382|		}
 1434|  25.6k|		tag |= cla;
 1435|       |		/* Check for length mismatch */
 1436|  25.6k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  25.6k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1436:7): [True: 418, False: 25.1k]
  ------------------
 1437|  25.1k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1437:7): [True: 0, False: 25.1k]
  ------------------
 1438|       |			// Check if it is not known Yubikey 5 issue
 1439|    418|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1439:8): [True: 151, False: 267]
  |  Branch (1439:29): [True: 11, False: 256]
  ------------------
 1440|    162|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1441|    162|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    162|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1442|    162|			}
 1443|    418|		}
 1444|       |
 1445|       |		/* Awful hack for composite DOs that have
 1446|       |		 * a TLV with the DO's id encompassing the
 1447|       |		 * entire blob. Example: Yubikey Neo */
 1448|  25.4k|		if (tag == blob->id) {
  ------------------
  |  Branch (1448:7): [True: 511, False: 24.9k]
  ------------------
 1449|    511|			in = data;
 1450|    511|			continue;
 1451|    511|		}
 1452|       |
 1453|       |		/* create fake file system hierarchy by
 1454|       |		 * using constructed DOs as DF */
 1455|  24.9k|		file = sc_file_new();
 1456|  24.9k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1456:7): [True: 0, False: 24.9k]
  ------------------
 1457|      0|			sc_file_free(file);
 1458|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1459|      0|		}
 1460|  24.9k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  24.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1460:7): [True: 0, False: 24.9k]
  ------------------
 1461|      0|			sc_file_free(file);
 1462|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1463|      0|		}
 1464|  24.9k|		in = data + len;
 1465|  24.9k|	}
 1466|       |
 1467|    380|	return SC_SUCCESS;
  ------------------
  |  |   28|    380|#define SC_SUCCESS				0
  ------------------
 1468|    741|}
card-openpgp.c:pgp_set_blob:
 1137|  25.6k|{
 1138|  25.6k|	if (blob->data)
  ------------------
  |  Branch (1138:6): [True: 0, False: 25.6k]
  ------------------
 1139|      0|		free(blob->data);
 1140|  25.6k|	blob->data = NULL;
 1141|  25.6k|	blob->len    = 0;
 1142|  25.6k|	blob->status = 0;
 1143|       |
 1144|  25.6k|	if (len > 0) {
  ------------------
  |  Branch (1144:6): [True: 11.7k, False: 13.9k]
  ------------------
 1145|  11.7k|		void *tmp = calloc(1, len);
 1146|       |
 1147|  11.7k|		if (tmp == NULL)
  ------------------
  |  Branch (1147:7): [True: 0, False: 11.7k]
  ------------------
 1148|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1149|       |
 1150|  11.7k|		blob->data = tmp;
 1151|  11.7k|		blob->len  = (unsigned int)len;
 1152|  11.7k|		if (data != NULL)
  ------------------
  |  Branch (1152:7): [True: 11.7k, False: 0]
  ------------------
 1153|  11.7k|			memcpy(blob->data, data, len);
 1154|  11.7k|	}
 1155|       |
 1156|  25.6k|	if (blob->file)
  ------------------
  |  Branch (1156:6): [True: 25.6k, False: 0]
  ------------------
 1157|  25.6k|		blob->file->size = len;
 1158|       |
 1159|  25.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  25.6k|#define SC_SUCCESS				0
  ------------------
 1160|  25.6k|}
card-openpgp.c:pgp_read_blob:
 1345|  4.30k|{
 1346|  4.30k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  4.30k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1347|       |
 1348|  4.30k|	if (blob->data != NULL)
  ------------------
  |  Branch (1348:6): [True: 870, False: 3.43k]
  ------------------
 1349|    870|		return SC_SUCCESS;
  ------------------
  |  |   28|    870|#define SC_SUCCESS				0
  ------------------
 1350|  3.43k|	if (blob->info == NULL)
  ------------------
  |  Branch (1350:6): [True: 0, False: 3.43k]
  ------------------
 1351|      0|		return blob->status;
 1352|       |
 1353|  3.43k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1353:6): [True: 3.37k, False: 57]
  ------------------
 1354|  3.37k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1355|  3.37k|		size_t	buf_len = sizeof(buffer);
 1356|  3.37k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.37k|#define SC_SUCCESS				0
  ------------------
 1357|       |
 1358|       |		/* buffer length for certificate */
 1359|  3.37k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  6.74k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1359:7): [True: 0, False: 3.37k]
  |  Branch (1359:30): [True: 0, False: 0]
  ------------------
 1360|      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]
  |  |  ------------------
  ------------------
 1361|      0|		}
 1362|       |
 1363|       |		/* buffer length for Gnuk pubkey */
 1364|  3.37k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1364:7): [True: 87, False: 3.28k]
  ------------------
 1365|     87|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|    174|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1365:8): [True: 0, False: 87]
  ------------------
 1366|     87|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|    174|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1366:8): [True: 0, False: 87]
  ------------------
 1367|     87|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|    174|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1367:8): [True: 0, False: 87]
  ------------------
 1368|     87|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|    174|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1368:8): [True: 0, False: 87]
  ------------------
 1369|     87|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|    174|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1369:8): [True: 0, False: 87]
  ------------------
 1370|     87|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|     87|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1370:8): [True: 0, False: 87]
  ------------------
 1371|      0|			buf_len = MIN(MAXLEN_RESP_PUBKEY_GNUK, sizeof(buffer));
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, Folded]
  |  |  ------------------
  ------------------
 1372|      0|		}
 1373|       |
 1374|  3.37k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1375|       |
 1376|  3.37k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1376:7): [True: 2.71k, False: 655]
  ------------------
 1377|  2.71k|			blob->status = r;
 1378|  2.71k|			return r;
 1379|  2.71k|		}
 1380|       |
 1381|    655|		return pgp_set_blob(blob, buffer, r);
 1382|  3.37k|	}
 1383|     57|	else {		/* un-readable DO or part of a constructed DO */
 1384|     57|		return SC_SUCCESS;
  ------------------
  |  |   28|     57|#define SC_SUCCESS				0
  ------------------
 1385|     57|	}
 1386|  3.43k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  630|  9.73k|{
  631|  9.73k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  9.73k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  632|  9.73k|	struct sc_object_id oid;
  633|  9.73k|	unsigned int j, r;
  634|       |
  635|  9.73k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  9.73k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.73k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.73k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.73k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|  9.73k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (637:6): [True: 0, False: 9.73k]
  |  Branch (637:22): [True: 1.34k, False: 8.38k]
  |  Branch (637:44): [True: 0, False: 8.38k]
  ------------------
  638|  8.38k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (638:6): [True: 0, False: 8.38k]
  |  Branch (638:27): [True: 0, False: 8.38k]
  |  Branch (638:48): [True: 0, False: 8.38k]
  ------------------
  639|  1.34k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  1.34k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.34k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.34k|	int _ret = r; \
  |  |  |  |  155|  1.34k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.34k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.34k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.34k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.34k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.34k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.34k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.34k|	return _ret; \
  |  |  |  |  163|  1.34k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|  1.34k|	}
  641|       |
  642|  8.38k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  643|       |
  644|  8.38k|	switch (blob->data[0]) {
  645|    312|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  869|    312|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (645:3): [True: 312, False: 8.07k]
  ------------------
  646|    312|			if (blob->len < 5) {
  ------------------
  |  Branch (646:8): [True: 200, False: 112]
  ------------------
  647|    200|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|    200|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    200|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    200|	int _ret = r; \
  |  |  |  |  155|    200|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    200|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    200|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    200|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    200|	return _ret; \
  |  |  |  |  163|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  648|    200|			}
  649|       |
  650|    112|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  869|    112|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  651|    112|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  652|    112|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  653|       |
  654|    112|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (654:32): [True: 77, False: 35]
  ------------------
  655|    112|						  ? blob->data[5]
  656|    112|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  874|    147|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  657|    112|			break;
  658|  3.11k|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  870|  3.11k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (658:3): [True: 3.11k, False: 5.26k]
  ------------------
  659|  4.70k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  871|  4.70k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (659:3): [True: 1.58k, False: 6.80k]
  ------------------
  660|  7.13k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  872|  7.13k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (660:3): [True: 2.42k, False: 5.95k]
  ------------------
  661|       |
  662|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  663|  7.13k|			key_info->algorithm = blob->data[0];
  664|       |
  665|       |			/* last byte is set to 0xFF if pubkey import is supported */
  666|  7.13k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  880|  7.13k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (666:8): [True: 805, False: 6.32k]
  ------------------
  667|    805|				if (blob->len < 3)
  ------------------
  |  Branch (667:9): [True: 202, False: 603]
  ------------------
  668|    202|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    202|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  669|    603|				key_info->u.ec.oidv_len = blob->len - 2;
  670|    603|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  880|    603|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  671|    603|			}
  672|  6.32k|			else {
  673|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  674|       |				 * it is not part of OID */
  675|  6.32k|				if (blob->len < 2)
  ------------------
  |  Branch (675:9): [True: 562, False: 5.76k]
  ------------------
  676|    562|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    562|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  677|  5.76k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  879|  5.76k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (677:9): [True: 1.28k, False: 4.47k]
  ------------------
  678|  1.28k|					key_info->u.ec.oidv_len = blob->len - 2;
  679|  4.47k|				else
  680|  4.47k|					key_info->u.ec.oidv_len = blob->len - 1;
  681|  5.76k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  879|  5.76k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  682|  5.76k|			}
  683|       |
  684|       |			/* Create copy of oid from blob */
  685|  6.36k|			sc_init_oid(&oid);
  686|  6.36k|			r = sc_asn1_decode_object_id(&blob->data[1], key_info->u.ec.oidv_len, &oid);
  687|       |
  688|       |			/* decoding failed, return sc_asn1_decode_object_id error code */
  689|  6.36k|			if (r > 0){
  ------------------
  |  Branch (689:8): [True: 2.30k, False: 4.06k]
  ------------------
  690|  2.30k|				return r;
  691|  2.30k|			}
  692|       |			/* compare with list of supported ec_curves */
  693|  20.8k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (693:16): [True: 19.8k, False: 968]
  ------------------
  694|  19.8k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (694:9): [True: 3.09k, False: 16.7k]
  ------------------
  695|  3.09k|					sc_log(card->ctx, "Matched EC oid %s (%d)",
  ------------------
  |  |   71|  3.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  696|  3.09k|						sc_dump_oid(&oid), j);
  697|  3.09k|					key_info->u.ec.oid = priv->ec_curves[j].oid;
  698|  3.09k|					key_info->u.ec.key_length = priv->ec_curves[j].size;
  699|  3.09k|					break;
  700|  3.09k|				}
  701|  19.8k|			}
  702|       |			/* We did not match the OID */
  703|  4.06k|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (703:8): [True: 968, False: 3.09k]
  ------------------
  704|    968|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|    968|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 968, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  705|    968|			}
  706|  3.09k|			break;
  707|  3.09k|		default:
  ------------------
  |  Branch (707:3): [True: 943, False: 7.44k]
  ------------------
  708|    943|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    943|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    943|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    943|	int _ret = r; \
  |  |  |  |  155|    943|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 943, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    943|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    943|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 943, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    943|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    943|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    943|	return _ret; \
  |  |  |  |  163|    943|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  8.38k|	}
  710|       |
  711|  3.20k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.20k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.20k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.20k|	int _ret = r; \
  |  |  |  |  155|  3.20k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.20k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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: 3.20k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.20k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.20k|	return _ret; \
  |  |  |  |  163|  3.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  712|  3.20k|}
card-openpgp.c:pgp_get_card_features:
  906|    633|{
  907|    633|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    633|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  908|    633|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  909|    633|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  910|    633|	unsigned int i;
  911|    633|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  912|    633|	int handled_algos = 0;
  913|       |
  914|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  915|       |
  916|       |	/* parse card capabilities from historical bytes in ATR */
  917|    633|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (917:6): [True: 68, False: 565]
  ------------------
  918|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  919|     68|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (919:11): [True: 58, False: 10]
  ------------------
  920|     35|			case 0x00:
  ------------------
  |  Branch (920:4): [True: 35, False: 33]
  ------------------
  921|     35|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (921:9): [True: 32, False: 3]
  ------------------
  922|     32|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  923|     32|				}
  924|     35|				break;
  925|     19|			case 0x80:
  ------------------
  |  Branch (925:4): [True: 19, False: 49]
  ------------------
  926|     19|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (926:9): [True: 18, False: 1]
  ------------------
  927|     18|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  928|     18|				}
  929|     19|				break;
  930|      4|			case 0x10:
  ------------------
  |  Branch (930:4): [True: 4, False: 64]
  ------------------
  931|      4|				if (hist_bytes_len > 2) {
  ------------------
  |  Branch (931:9): [True: 3, False: 1]
  ------------------
  932|      3|					pgp_parse_hist_bytes(card, hist_bytes+2, hist_bytes_len-2);
  933|      3|				}
  934|      4|				break;
  935|     68|		}
  936|     68|	}
  937|       |
  938|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  939|    633|	priv->ext_caps &= ~EXT_CAP_LCS;
  940|       |
  941|    633|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (941:6): [True: 437, False: 196]
  ------------------
  942|       |		/* get card capabilities from "historical bytes" DO */
  943|    437|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (943:7): [True: 437, False: 0]
  ------------------
  944|    437|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (944:7): [True: 37, False: 400]
  |  Branch (944:31): [True: 33, False: 4]
  ------------------
  945|       |
  946|     33|			if (blob->len > 4) {
  ------------------
  |  Branch (946:8): [True: 31, False: 2]
  ------------------
  947|     31|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  948|     31|			}
  949|       |
  950|       |			/* get card status from historical bytes status indicator */
  951|     33|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (951:8): [True: 33, False: 0]
  |  Branch (951:35): [True: 32, False: 1]
  ------------------
  952|     32|				priv->state = blob->data[blob->len-3];
  953|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  954|     32|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (954:9): [True: 24, False: 8]
  ------------------
  955|     24|					priv->ext_caps |= EXT_CAP_LCS;
  956|     32|			}
  957|     33|		}
  958|    437|	}
  959|       |
  960|    633|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (960:6): [True: 410, False: 223]
  ------------------
  961|    410|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    410|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  962|    410|	}
  963|       |
  964|    633|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (964:6): [True: 405, False: 228]
  ------------------
  965|       |		/* Parse supported algorithms from Algorithm Information DO
  966|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  967|    405|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (967:7): [True: 405, False: 0]
  ------------------
  968|    405|			pgp_blob_t *child;
  969|    405|			pgp_enumerate_blob(card, blobfa);
  970|       |			/* There will be multiple children with the same ID, but
  971|       |			 * different algos, so we need to iterate over all of them */
  972|  18.4k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (972:32): [True: 18.0k, False: 405]
  ------------------
  973|  18.0k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (973:9): [True: 4.98k, False: 13.0k]
  |  Branch (973:33): [True: 3.37k, False: 9.72k]
  ------------------
  974|  8.36k|					continue;
  975|  9.72k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  976|  9.72k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (976:9): [True: 3.20k, False: 6.51k]
  ------------------
  977|  3.20k|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  978|  9.72k|			}
  979|    405|		}
  980|    405|	}
  981|       |
  982|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  983|    633|	priv->max_specialDO_size = 254;
  984|       |
  985|    633|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (985:6): [True: 633, False: 0]
  ------------------
  986|    633|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (986:6): [True: 95, False: 538]
  ------------------
  987|       |
  988|       |		/* get "extended capabilities" DO */
  989|     95|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (989:7): [True: 49, False: 46]
  ------------------
  990|     49|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (990:7): [True: 48, False: 1]
  |  Branch (990:31): [True: 48, False: 0]
  ------------------
  991|     48|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (991:8): [True: 36, False: 12]
  |  Branch (991:34): [True: 25, False: 11]
  ------------------
  992|     25|				priv->ext_caps |= EXT_CAP_KDF_DO;
  993|     25|			}
  994|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  995|     48|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (995:8): [True: 37, False: 11]
  ------------------
  996|     37|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (996:6): [True: 30, False: 7]
  ------------------
  997|     30|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
  998|       |			/* bit 0x08 in first byte means "support for private use DOs" */
  999|     48|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (999:8): [True: 32, False: 16]
  ------------------
 1000|     32|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1001|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1002|     48|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1002:8): [True: 29, False: 19]
  ------------------
 1003|     29|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1004|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1005|     48|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1005:8): [True: 33, False: 15]
  ------------------
 1006|     33|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1007|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1008|     48|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1008:8): [True: 34, False: 14]
  ------------------
 1009|     34|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     34|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1010|     34|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1011|     34|			}
 1012|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1013|     48|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1013:8): [True: 17, False: 31]
  ------------------
 1014|     17|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1014:6): [True: 14, False: 3]
  ------------------
 1015|     14|				priv->ext_caps |= EXT_CAP_SM;
 1016|       |
 1017|     48|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1017:8): [True: 40, False: 8]
  |  Branch (1017:51): [True: 10, False: 30]
  ------------------
 1018|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1019|     10|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1020|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1021|     10|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1022|       |
 1023|     10|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1023:9): [True: 7, False: 3]
  ------------------
 1024|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1025|      7|					priv->sm_algo = blob->data[1];
 1026|      7|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1026:10): [True: 4, False: 3]
  |  Branch (1026:45): [True: 1, False: 3]
  ------------------
 1027|      1|						priv->sm_algo = SM_ALGO_3DES;
 1028|       |
 1029|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1030|      7|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1031|      7|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1032|      7|				}
 1033|      3|				else {
 1034|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1035|      3|					priv->sm_algo = blob->data[1];
 1036|      3|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1036:10): [True: 2, False: 1]
  |  Branch (1036:45): [True: 1, False: 1]
  ------------------
 1037|      1|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1038|       |
 1039|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1040|      3|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1041|      3|				}
 1042|     10|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1042:9): [True: 3, False: 7]
  |  Branch (1042:50): [True: 3, False: 0]
  ------------------
 1043|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1044|      3|					if (blob->data[9])
  ------------------
  |  Branch (1044:10): [True: 1, False: 2]
  ------------------
 1045|      1|						priv->ext_caps |= EXT_CAP_MSE;
 1046|      3|				}
 1047|     10|			}
 1048|     48|		}
 1049|       |
 1050|       |		/* get max. PIN length from "CHV status bytes" DO */
 1051|     95|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1051:7): [True: 37, False: 58]
  ------------------
 1052|     37|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1052:4): [True: 5, False: 32]
  |  Branch (1052:28): [True: 3, False: 2]
  ------------------
 1053|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1054|      3|			card->max_pin_len = blob->data[1];
 1055|      3|		}
 1056|       |
 1057|     95|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1057:7): [True: 56, False: 39]
  ------------------
 1058|       |			/* v3.0+: get length info from "extended length information" DO */
 1059|     56|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1059:8): [True: 3, False: 53]
  ------------------
 1060|      3|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1060:5): [True: 2, False: 1]
  |  Branch (1060:29): [True: 1, False: 1]
  ------------------
 1061|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1062|      1|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1063|      1|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1064|      1|			}
 1065|     56|		}
 1066|       |
 1067|     95|#ifdef ENABLE_OPENSSL
 1068|     95|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1068:7): [True: 25, False: 70]
  ------------------
 1069|     25|			int r = pgp_decode_kdf_do(card, priv);
 1070|     25|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
  |  Branch (1070:8): [True: 24, False: 1]
  ------------------
 1071|     24|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1072|     24|			}
 1073|     25|		}
 1074|     95|#endif /* ENABLE_OPENSSL */
 1075|       |
 1076|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1077|     95|		if (handled_algos) {
  ------------------
  |  Branch (1077:7): [True: 2, False: 93]
  ------------------
 1078|      2|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1079|      2|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  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: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      2|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      2|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      2|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1080|      2|		}
 1081|       |
 1082|       |		/* get _current_ algorithms & key lengths from "algorithm attributes" DOs
 1083|       |		 *
 1084|       |		 * All available algorithms should be already provided by pgp_init. However, if another
 1085|       |		 * algorithm is found in the "algorithm attributes" DOs, it is supported by the card as
 1086|       |		 * well and therefore added
 1087|       |		 * see OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1088|    372|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1088:20): [True: 279, False: 93]
  ------------------
 1089|    279|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1090|       |
 1091|    279|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   71|    279|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1092|       |
 1093|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1094|    279|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1094:8): [True: 11, False: 268]
  ------------------
 1095|     11|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1095:8): [True: 1, False: 10]
  ------------------
 1096|      1|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1096:9): [True: 0, False: 1]
  ------------------
 1097|      1|					LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "Cannot add algorithm");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1098|      1|			}
 1099|    279|		}
 1100|       |
 1101|     93|	}
 1102|       |
 1103|    631|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    631|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    631|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    631|	int _ret = r; \
  |  |  |  |  155|    631|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 543, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  156|    543|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 543]
  |  |  |  |  ------------------
  |  |  |  |  157|    543|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    543|	} else { \
  |  |  |  |  159|     88|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     88|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     88|	} \
  |  |  |  |  162|    631|	return _ret; \
  |  |  |  |  163|    631|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|    631|}
card-openpgp.c:pgp_parse_hist_bytes:
  600|     84|{
  601|     84|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     84|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  602|     84|	const u8 *ptr;
  603|       |
  604|       |	/* IS07816-4 hist bytes: 3rd function table */
  605|     84|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (605:6): [True: 33, False: 51]
  ------------------
  606|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  607|     33|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (607:7): [True: 9, False: 24]
  ------------------
  608|      9|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|      9|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  609|      9|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  610|      9|		}
  611|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  612|     33|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (612:7): [True: 23, False: 10]
  ------------------
  613|     23|			priv->ext_caps |= EXT_CAP_CHAINING;
  614|     23|		}
  615|     33|	}
  616|       |
  617|     84|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (617:6): [True: 53, False: 31]
  ------------------
  618|     53|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (618:6): [True: 18, False: 35]
  ------------------
  619|       |		// ToDo ...
  620|     18|	}
  621|     84|}
card-openpgp.c:pgp_decode_kdf_do:
  802|     25|{
  803|     25|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  804|     25|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     25|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  805|     25|	pgp_blob_t *kdf_blob;
  806|     25|	const uint8_t *data;
  807|     25|	size_t data_len;
  808|     25|	size_t tag_len;
  809|     25|	const uint8_t *p;
  810|     25|	pgp_blob_t *blob;
  811|       |
  812|     25|	if (!pin_kdf_info) {
  ------------------
  |  Branch (812:6): [True: 0, False: 25]
  ------------------
  813|      0|		return r;
  814|      0|	}
  815|       |
  816|     25|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     25|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  817|     25|	priv->pin_kdf_info = NULL;
  818|     25|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     25|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
  |  Branch (818:6): [True: 0, False: 25]
  |  Branch (818:73): [True: 14, False: 11]
  ------------------
  819|     14|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  820|     14|		goto out;
  821|     14|	}
  822|       |
  823|     11|	data = kdf_blob->data;
  824|     11|	data_len = kdf_blob->len;
  825|     11|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  826|     11|	if (!p) {
  ------------------
  |  Branch (826:6): [True: 1, False: 10]
  ------------------
  827|      1|		sc_log(card->ctx, "KDF algorithm byte not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  828|      1|		goto out;
  829|      1|	}
  830|     10|	if (tag_len != 1) {
  ------------------
  |  Branch (830:6): [True: 1, False: 9]
  ------------------
  831|      1|		sc_log(card->ctx, "Unexpected KDF algorithm byte length, expects 1, got %" SC_FORMAT_LEN_SIZE_T "u", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  832|      1|		goto out;
  833|      1|	}
  834|       |
  835|      9|	if (*p != 0x3) {
  ------------------
  |  Branch (835:6): [True: 2, False: 7]
  ------------------
  836|      2|		if (*p == 0x0) {
  ------------------
  |  Branch (836:7): [True: 1, False: 1]
  ------------------
  837|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  838|      1|			sc_log(card->ctx, "KDF derived PIN format disabled");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  839|      1|		} else {
  840|      1|			sc_log(card->ctx, "Unknown KDF algorithm ID %x", *p);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  841|      1|		}
  842|      2|		goto out;
  843|      2|	}
  844|       |
  845|      7|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  846|      7|	if (!p) {
  ------------------
  |  Branch (846:6): [True: 1, False: 6]
  ------------------
  847|      1|		sc_log(card->ctx, "KDF hash algorithm byte not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  848|      1|		goto out;
  849|      1|	}
  850|      6|	if (tag_len != 1) {
  ------------------
  |  Branch (850:6): [True: 2, False: 4]
  ------------------
  851|      2|		sc_log(card->ctx, "Unexpected KDF hash algorithm byte length, expects 1, got %" SC_FORMAT_LEN_SIZE_T "u", tag_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__
  |  |  ------------------
  ------------------
  852|      2|		goto out;
  853|      2|	}
  854|       |
  855|      4|	switch (*p) {
  856|      1|	case 0x08:
  ------------------
  |  Branch (856:2): [True: 1, False: 3]
  ------------------
  857|      1|		pin_kdf_info->hash_algo = "SHA256";
  858|      1|		break;
  859|      2|	case 0x0A:
  ------------------
  |  Branch (859:2): [True: 2, False: 2]
  ------------------
  860|      2|		pin_kdf_info->hash_algo = "SHA512";
  861|      2|		break;
  862|      1|	default:
  ------------------
  |  Branch (862:2): [True: 1, False: 3]
  ------------------
  863|      1|		sc_log(card->ctx, "Unknown KDF hash algorithm ID %x", *p);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  864|      1|		goto out;
  865|      4|	}
  866|       |
  867|      3|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  868|      3|	if (!p) {
  ------------------
  |  Branch (868:6): [True: 2, False: 1]
  ------------------
  869|      2|		sc_log(card->ctx, "KDF iteration count not found");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  870|      2|		goto out;
  871|      2|	}
  872|      1|	if (tag_len != 4) {
  ------------------
  |  Branch (872:6): [True: 1, False: 0]
  ------------------
  873|      1|		sc_log(card->ctx, "Unexpected KDF iteration count length, expects 4, got %" SC_FORMAT_LEN_SIZE_T "u", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  874|      1|		goto out;
  875|      1|	}
  876|      0|	pin_kdf_info->iterations = (uint32_t)bebytes2ulong(p);
  877|       |
  878|      0|	r = pgp_get_blob(card, kdf_blob, 0x84, &blob);
  879|      0|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (879:6): [True: 0, False: 0]
  ------------------
  880|      0|		sc_log(card->ctx, "Failed to get salt bytes of user password");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  881|      0|		goto out;
  882|      0|	}
  883|      0|	pin_kdf_info->userpw_salt = blob;
  884|       |
  885|      0|	r = pgp_get_blob(card, kdf_blob, 0x86, &blob);
  886|      0|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (886:6): [True: 0, False: 0]
  ------------------
  887|      0|		sc_log(card->ctx, "Failed to get salt bytes of admin password");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  888|      0|		goto out;
  889|      0|	}
  890|      0|	pin_kdf_info->adminpw_salt = blob;
  891|       |
  892|      0|	sc_log(card->ctx, "KDF derived PIN format enabled");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  893|      0|	priv->pin_kdf_info = pin_kdf_info;
  894|      0|	return r;
  895|     25|out:
  896|     25|	free(pin_kdf_info);
  897|     25|	return r;
  898|      0|}
card-openpgp.c:pgp_finish:
 1112|    655|{
 1113|    655|	if (card != NULL) {
  ------------------
  |  Branch (1113:6): [True: 655, False: 0]
  ------------------
 1114|    655|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    655|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1115|       |
 1116|    655|		if (priv != NULL) {
  ------------------
  |  Branch (1116:7): [True: 655, False: 0]
  ------------------
 1117|       |			/* delete fake file hierarchy */
 1118|    655|			pgp_free_blobs(priv->mf);
 1119|       |
 1120|       |			/* delete kdf do related data if exists */
 1121|    655|			free(priv->pin_kdf_info);
 1122|       |
 1123|       |			/* delete private data */
 1124|    655|			free(priv);
 1125|    655|		}
 1126|    655|		card->drv_data = NULL;
 1127|    655|	}
 1128|    655|	return SC_SUCCESS;
  ------------------
  |  |   28|    655|#define SC_SUCCESS				0
  ------------------
 1129|    655|}
card-openpgp.c:pgp_free_blobs:
 1325|  37.6k|{
 1326|  37.6k|	if (blob) {
  ------------------
  |  Branch (1326:6): [True: 37.6k, False: 22]
  ------------------
 1327|  37.6k|		pgp_blob_t *child = blob->files;
 1328|       |
 1329|  74.6k|		while (child != NULL) {
  ------------------
  |  Branch (1329:10): [True: 37.0k, False: 37.6k]
  ------------------
 1330|  37.0k|			pgp_blob_t *next = child->next;
 1331|       |
 1332|  37.0k|			pgp_free_blobs(child);
 1333|  37.0k|			child = next;
 1334|  37.0k|		}
 1335|  37.6k|		pgp_free_blob(blob);
 1336|  37.6k|	}
 1337|  37.6k|}
card-openpgp.c:pgp_free_blob:
 1300|  37.6k|{
 1301|  37.6k|	if (blob) {
  ------------------
  |  Branch (1301:6): [True: 37.6k, False: 0]
  ------------------
 1302|  37.6k|		if (blob->parent) {
  ------------------
  |  Branch (1302:7): [True: 37.0k, False: 633]
  ------------------
 1303|  37.0k|			pgp_blob_t **p;
 1304|       |
 1305|       |			/* remove blob from list of parent's children */
 1306|  37.0k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1306:35): [True: 37.0k, False: 0]
  |  Branch (1306:49): [True: 0, False: 37.0k]
  ------------------
 1307|      0|				;
 1308|  37.0k|			if (*p == blob)
  ------------------
  |  Branch (1308:8): [True: 37.0k, False: 0]
  ------------------
 1309|  37.0k|				*p = blob->next;
 1310|  37.0k|		}
 1311|       |
 1312|  37.6k|		sc_file_free(blob->file);
 1313|  37.6k|		if (blob->data)
  ------------------
  |  Branch (1313:7): [True: 11.7k, False: 25.9k]
  ------------------
 1314|  11.7k|			free(blob->data);
 1315|  37.6k|		free(blob);
 1316|  37.6k|	}
 1317|  37.6k|}
card-openpgp.c:pgp_select_file:
 1611|  3.84k|{
 1612|  3.84k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  3.84k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1613|  3.84k|	pgp_blob_t	*blob;
 1614|  3.84k|	unsigned int	path_start = 0;
 1615|  3.84k|	unsigned int	n;
 1616|  3.84k|	sc_path_t dummy_path;
 1617|       |
 1618|  3.84k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.84k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.84k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.84k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.84k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|  3.84k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  3.84k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1620:6): [True: 1.27k, False: 2.56k]
  ------------------
 1621|  3.84k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  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: 1.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.27k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.24k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.24k, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.27k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.27k|	return _ret; \
  |  |  |  |  163|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  2.56k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1623:6): [True: 0, False: 2.56k]
  |  Branch (1623:23): [True: 0, False: 2.56k]
  ------------------
 1624|  2.56k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1625|  2.56k|				"invalid path length");
 1626|       |
 1627|  2.56k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  5.13k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1627:6): [True: 0, False: 2.56k]
  |  Branch (1627:44): [True: 0, False: 0]
  ------------------
 1628|  2.56k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1629|  2.56k|				"invalid path type");
 1630|       |
 1631|       |	/* Due to pkcs15init implementation, sometimes a file at path "11001101"
 1632|       |	 * need to be written (one use case is when importing key&cert from p12 file).
 1633|       |	 * This file does not exist in OpenPGP but pkcs15 requires that
 1634|       |	 * writing this file must be successful.
 1635|       |	 * So, we pretend that selecting & writing this file is successful.
 1636|       |	 * The "11001101"is defined in sc_pkcs15emu_get_df() function, pkcs15-sync.c file. */
 1637|  2.56k|	sc_format_path("11001101", &dummy_path);
 1638|  2.56k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1638:6): [True: 0, False: 2.56k]
  ------------------
 1639|      0|		if (ret != NULL) {
  ------------------
  |  Branch (1639:7): [True: 0, False: 0]
  ------------------
 1640|      0|			*ret = sc_file_new();
 1641|       |			/* One use case of this dummy file is after writing certificate in pkcs15init.
 1642|       |			 * So we set its size to be the same as max certificate size the card supports. */
 1643|      0|			(*ret)->size = priv->max_cert_size;
 1644|      0|		}
 1645|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1646|      0|	}
 1647|       |
 1648|       |	/* ignore explicitly mentioned MF at the path's beginning */
 1649|  2.56k|	path_start = pgp_strip_path(card, path);
 1650|       |
 1651|       |	/* starting with the MF ... */
 1652|  2.56k|	blob = priv->mf;
 1653|       |	/* ... recurse through the tree following the path */
 1654|  3.33k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1654:23): [True: 2.64k, False: 687]
  ------------------
 1655|  2.64k|		unsigned int	id = bebytes2ushort(path->value + n);
 1656|  2.64k|		int		r = pgp_get_blob(card, blob, id, &blob);
 1657|       |
 1658|       |		/* This file ID is referred when importing key&certificate via pkcs15init, like above.
 1659|       |		 * We pretend to successfully find this inexistent file. */
 1660|  2.64k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1660:7): [True: 0, False: 2.64k]
  |  Branch (1660:23): [True: 0, False: 2.64k]
  ------------------
 1661|      0|			if (ret == NULL)
  ------------------
  |  Branch (1661:8): [True: 0, False: 0]
  ------------------
 1662|       |				/* No need to return file */
 1663|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1664|       |
 1665|       |			/* Else, need to return file */
 1666|      0|			*ret = sc_file_new();
 1667|      0|			(*ret)->size = priv->max_cert_size;
 1668|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1669|      0|		}
 1670|       |
 1671|  2.64k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1671:7): [True: 1.88k, False: 762]
  ------------------
 1672|  1.88k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.88k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.88k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.88k|	int _ret = r; \
  |  |  |  |  155|  1.88k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.88k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.88k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.88k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.88k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.88k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.88k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.88k|	return _ret; \
  |  |  |  |  163|  1.88k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1673|  1.88k|		}
 1674|  2.64k|	}
 1675|       |
 1676|       |	/* success: select file = set "current" pointer to blob found */
 1677|    687|	priv->current = blob;
 1678|       |
 1679|    687|	if (ret)
  ------------------
  |  Branch (1679:6): [True: 60, False: 627]
  ------------------
 1680|     60|		sc_file_dup(ret, blob->file);
 1681|       |
 1682|    687|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    687|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    687|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    687|	int _ret = r; \
  |  |  |  |  155|    687|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 687, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    687|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 687]
  |  |  |  |  ------------------
  |  |  |  |  157|    687|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    687|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    687|	return _ret; \
  |  |  |  |  163|    687|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1683|    687|}
card-openpgp.c:pgp_strip_path:
 1592|  2.56k|{
 1593|  2.56k|	unsigned int start_point = 0;
 1594|       |	/* start_point will move through the path string */
 1595|  2.56k|	if (path->len == 0)
  ------------------
  |  Branch (1595:6): [True: 0, False: 2.56k]
  ------------------
 1596|      0|		return 0;
 1597|       |
 1598|       |	/* ignore 3F00 (MF) at the beginning */
 1599|  2.56k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1599:16): [True: 1.88k, False: 688]
  ------------------
 1600|       |	/* strip path of PKCS15-App DF (5015) */
 1601|  2.56k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1601:17): [True: 1.25k, False: 1.31k]
  ------------------
 1602|  2.56k|	return start_point;
 1603|  2.56k|}
card-openpgp.c:pgp_read_binary:
 1752|     20|{
 1753|     20|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     20|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1754|     20|	pgp_blob_t	*blob;
 1755|     20|	int		r;
 1756|       |
 1757|     20|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     20|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     20|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     20|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     20|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1758|       |
 1759|       |	/* jump to selected file */
 1760|     20|	blob = priv->current;
 1761|       |
 1762|     20|	if (blob == NULL)
  ------------------
  |  Branch (1762:6): [True: 0, False: 20]
  ------------------
 1763|     20|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1764|       |
 1765|     20|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|     20|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1765:6): [True: 0, False: 20]
  ------------------
 1766|     20|		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|     20|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1768:6): [True: 0, False: 20]
  ------------------
 1769|     20|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1770|       |
 1771|     20|	if (idx > blob->len)
  ------------------
  |  Branch (1771:6): [True: 0, False: 20]
  ------------------
 1772|     20|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1773|       |
 1774|     20|	if (idx + count > blob->len)
  ------------------
  |  Branch (1774:6): [True: 0, False: 20]
  ------------------
 1775|      0|		count = blob->len - idx;
 1776|     20|	memcpy(buf, blob->data + idx, count);
 1777|       |
 1778|     20|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  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: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"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|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|     20|}
card-openpgp.c:pgp_pin_cmd:
 2389|     12|{
 2390|     12|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     12|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2391|     12|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2392|       |
 2393|     12|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2394|       |
 2395|     12|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|     12|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2395:6): [True: 0, False: 12]
  ------------------
 2396|     12|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2397|     12|				"invalid PIN type");
 2398|       |
 2399|       |	/* In general, the PIN Reference is extracted from the key-id,
 2400|       |	 * for example, CHV0 -> Ref=0, CHV1 -> Ref=1.
 2401|       |	 * However, in the case of OpenPGP, the PIN Ref to compose APDU
 2402|       |	 * must be 81, 82, 83.
 2403|       |	 * So, if we receive Ref=1, Ref=2, we must convert to 81, 82...
 2404|       |	 * In OpenPGP v1, the PINs are named CHV1, CHV2, CHV3.
 2405|       |	 * In v2, they are named PW1, PW3 (PW1 operates in 2 modes).
 2406|       |	 *
 2407|       |	 * The PIN references (P2 in APDU) for "VERIFY" are the same in both versions:
 2408|       |	 * 81 (CHV1 or PW1), 82 (CHV2 or PW1-mode 2), 83 (CHV3 or PW3),
 2409|       |	 * On the other hand from version 2.0 "CHANGE REFERENCE DATA" and
 2410|       |	 * "RESET RETRY COUNTER" don't support PW1-mode 2 (82) and need this
 2411|       |	 * value changed to PW1 (81).
 2412|       |	 * Both of these commands also differ between card versions in that
 2413|       |	 * v1 cards can use only implicit old PIN or CHV3 test for both commands
 2414|       |	 * whereas v2 can use both implicit (for PW3) and explicit
 2415|       |	 * (for special "Resetting Code") PIN test for "RESET RETRY COUNTER"
 2416|       |	 * and only explicit test for "CHANGE REFERENCE DATA".
 2417|       |	 *
 2418|       |	 * Note that if this function is called from sc_pkcs15_verify_pin() in pkcs15-pin.c,
 2419|       |	 * the Ref is already 81, 82, 83.
 2420|       |	 */
 2421|       |
 2422|       |	/* convert the PIN Reference if needed */
 2423|     12|	data->pin_reference |= 0x80;
 2424|       |
 2425|       |	/* check version-dependent constraints */
 2426|     12|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  423|     24|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  424|     12|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2426:6): [True: 0, False: 12]
  |  Branch (2426:40): [True: 0, False: 12]
  ------------------
 2427|      0|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2427:7): [True: 0, False: 0]
  ------------------
 2428|      0|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2428:8): [True: 0, False: 0]
  ------------------
 2429|      0|				data->pin_reference = 0x81;
 2430|       |
 2431|      0|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2431:8): [True: 0, False: 0]
  ------------------
 2432|      0|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2432:9): [True: 0, False: 0]
  ------------------
 2433|      0|				    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2433:9): [True: 0, False: 0]
  ------------------
 2434|      0|					LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2435|      0|							"v2 cards don't support implicit old PIN for PIN change");
 2436|       |
 2437|      0|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2438|      0|			}
 2439|      0|		} else {
 2440|      0|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2440:8): [True: 0, False: 0]
  ------------------
 2441|      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__
  |  |  ------------------
  ------------------
 2442|      0|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2443|      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__
  |  |  ------------------
  ------------------
 2444|      0|				       "please make sure that you have verified the relevant PIN first.");
 2445|      0|				data->pin1.len = 0;
 2446|      0|			}
 2447|       |
 2448|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2449|      0|		}
 2450|      0|	}
 2451|       |
 2452|     12|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  424|     24|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2452:6): [True: 0, False: 12]
  |  Branch (2452:41): [True: 0, False: 0]
  ------------------
 2453|      0|	    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2453:6): [True: 0, False: 0]
  ------------------
 2454|     12|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2455|     12|				"new PIN must be provided for unblock operation");
 2456|       |
 2457|       |	/* ensure pin_reference is 81, 82, 83 */
 2458|     12|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2458:6): [True: 0, False: 12]
  |  Branch (2458:36): [True: 0, False: 12]
  ------------------
 2459|     12|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2460|     12|				"Invalid key ID; must be 1, 2, or 3");
 2461|       |
 2462|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2463|     12|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  425|     24|#define SC_PIN_CMD_GET_INFO	3
  ------------------
              	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  560|     12|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2463:6): [True: 12, False: 0]
  |  Branch (2463:42): [True: 7, False: 5]
  ------------------
 2464|      7|		u8 c4data[10];
 2465|      7|		int r;
 2466|       |
 2467|      7|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2468|      7|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2469|       |
 2470|      2|		if (r != 7)
  ------------------
  |  Branch (2470:7): [True: 1, False: 1]
  ------------------
 2471|      2|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2472|      1|				"CHV status bytes have unexpected length");
 2473|       |
 2474|       |		/* The definition of fields of DO C4 changed between OpenPGP
 2475|       |		 * card specification v1.1 and v2.0. There is no longer a separate
 2476|       |		 * CHV2 retry counter but only one retry counter for both PW1 mode 1
 2477|       |		 * and mode 2 at byte 5 (count from 1) of the DO.
 2478|       |		 */
 2479|      1|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2479:7): [True: 0, False: 1]
  |  Branch (2479:48): [True: 0, False: 0]
  ------------------
 2480|      0|			data->pin_reference = 0x81;
 2481|       |
 2482|      1|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2483|      1|		data->pin1.max_tries = 3;
 2484|      1|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      1|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2485|       |
 2486|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2487|      1|	}
 2488|       |
 2489|      5|#ifdef ENABLE_OPENSSL
 2490|      5|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2490:6): [True: 0, False: 5]
  ------------------
 2491|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2492|      0|	}
 2493|      5|#endif /* ENABLE_OPENSSL */
 2494|       |
 2495|      5|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data));
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2496|      5|}
card-openpgp.c:pgp_get_data:
 1991|  4.65k|{
 1992|  4.65k|	sc_apdu_t	apdu;
 1993|  4.65k|	int		r;
 1994|       |
 1995|  4.65k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  4.65k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.65k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1996|       |
 1997|  4.65k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  4.65k|#define SC_APDU_CASE_2			0x22
  ------------------
 1998|  4.65k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  554|  3.37k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (1998:13): [True: 3.37k, False: 1.27k]
  |  Branch (1998:33): [True: 3.33k, False: 42]
  ------------------
 1999|  4.65k|	apdu.resp = buf;
 2000|  4.65k|	apdu.resplen = buf_len;
 2001|       |
 2002|  4.65k|	r = sc_transmit_apdu(card, &apdu);
 2003|  4.65k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  4.65k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.65k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.65k|	int _ret = (r); \
  |  |  |  |  168|  4.65k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 35, False: 4.61k]
  |  |  |  |  ------------------
  |  |  |  |  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.65k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.61k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2004|       |
 2005|  4.61k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2006|       |
 2007|       |	/* Gnuk returns an error instead of empty data if there is no certificate or private DO.
 2008|       |	 * So, for this case, we ignore error and consider success */
 2009|  4.61k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2009:6): [True: 106, False: 4.51k]
  ------------------
 2010|    106|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|    212|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2010:7): [True: 0, False: 106]
  ------------------
 2011|    106|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|    212|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2011:7): [True: 0, False: 106]
  ------------------
 2012|    106|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|    212|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2012:7): [True: 0, False: 106]
  ------------------
 2013|    106|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|    212|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2013:7): [True: 0, False: 106]
  ------------------
 2014|    106|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|    106|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2014:7): [True: 0, False: 106]
  ------------------
 2015|      0|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2015:7): [True: 0, False: 0]
  ------------------
 2016|      0|			r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2017|      0|			apdu.resplen = 0;
 2018|      0|		}
 2019|      0|	}
 2020|  4.61k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  4.61k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.61k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.61k|	int _ret = (r); \
  |  |  |  |  168|  4.61k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.26k, False: 1.35k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.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|  3.26k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.26k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.26k|		return _ret; \
  |  |  |  |  172|  3.26k|	} \
  |  |  |  |  173|  4.61k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2021|       |
 2022|  1.35k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.35k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.35k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.35k|	int _ret = r; \
  |  |  |  |  155|  1.35k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 236, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  156|    236|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 236]
  |  |  |  |  ------------------
  |  |  |  |  157|    236|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.11k|	} else { \
  |  |  |  |  159|  1.11k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.11k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.11k|	} \
  |  |  |  |  162|  1.35k|	return _ret; \
  |  |  |  |  163|  1.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2023|  1.35k|}
card-openpgp.c:pgp_card_ctl:
 4011|     12|{
 4012|     12|	int r;
 4013|       |
 4014|     12|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4015|       |
 4016|     12|	switch(cmd) {
  ------------------
  |  Branch (4016:9): [True: 12, False: 0]
  ------------------
 4017|     12|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4017:2): [True: 12, False: 0]
  ------------------
 4018|     12|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4019|     12|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     12|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4020|      0|		break;
 4021|      0|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4021:2): [True: 0, False: 12]
  ------------------
 4022|      0|		r = pgp_select_data(card, *((u8 *) ptr));
 4023|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4024|      0|		break;
 4025|      0|#ifdef ENABLE_OPENSSL
 4026|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4026:2): [True: 0, False: 12]
  ------------------
 4027|      0|		r = pgp_gen_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4028|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4029|      0|		break;
 4030|      0|	case SC_CARDCTL_OPENPGP_STORE_KEY:
  ------------------
  |  Branch (4030:2): [True: 0, False: 12]
  ------------------
 4031|      0|		r = pgp_store_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4032|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4033|      0|		break;
 4034|      0|#endif /* ENABLE_OPENSSL */
 4035|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (4035:2): [True: 0, False: 12]
  ------------------
 4036|      0|		r = pgp_erase_card(card);
 4037|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4038|      0|		break;
 4039|     12|	}
 4040|       |
 4041|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4042|      0|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4171|  7.92k|{
 4172|  7.92k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  7.92k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4173|  7.92k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  7.92k|#define SC_SUCCESS				0
  ------------------
 4174|       |
 4175|  7.92k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.92k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.92k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.92k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.92k]
  |  |  ------------------
  ------------------
 4176|       |
 4177|  7.92k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  544|  15.8k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4177:6): [True: 0, False: 7.92k]
  ------------------
 4178|      0|			&& was_reset <= 0
  ------------------
  |  Branch (4178:7): [True: 0, False: 0]
  ------------------
 4179|      0|			&& priv != NULL && priv->mf && priv->mf->file) {
  ------------------
  |  Branch (4179:7): [True: 0, False: 0]
  |  Branch (4179:23): [True: 0, False: 0]
  |  Branch (4179:35): [True: 0, False: 0]
  ------------------
 4180|       |		/* check whether applet is still selected */
 4181|      0|		unsigned char aid[16];
 4182|       |
 4183|      0|		r = sc_get_data(card, 0x004F, aid, sizeof aid);
 4184|      0|		if ((size_t) r != priv->mf->file->namelen
  ------------------
  |  Branch (4184:7): [True: 0, False: 0]
  ------------------
 4185|      0|				|| 0 != memcmp(aid, priv->mf->file->name, r)) {
  ------------------
  |  Branch (4185:8): [True: 0, False: 0]
  ------------------
 4186|       |			/* reselect is required */
 4187|      0|			was_reset = 1;
 4188|      0|		}
 4189|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 4190|      0|	}
 4191|       |
 4192|  7.92k|	if (was_reset > 0) {
  ------------------
  |  Branch (4192:6): [True: 0, False: 7.92k]
  ------------------
 4193|      0|		sc_file_t	*file = NULL;
 4194|      0|		sc_path_t	path;
 4195|       |		/* select application "OpenPGP" */
 4196|      0|		sc_format_path("D276:0001:2401", &path);
 4197|      0|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 4198|      0|		r = iso_ops->select_file(card, &path, &file);
 4199|      0|		sc_file_free(file);
 4200|      0|	}
 4201|       |
 4202|  7.92k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4203|  7.92k|}

sc_get_piv_driver:
 6476|  15.0k|{
 6477|  15.0k|	return sc_get_driver();
 6478|  15.0k|}
card-piv.c:sc_get_driver:
 6449|  15.0k|{
 6450|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6451|       |
 6452|  15.0k|	piv_ops = *iso_drv->ops;
 6453|  15.0k|	piv_ops.match_card = piv_match_card;
 6454|  15.0k|	piv_ops.init = piv_init;
 6455|  15.0k|	piv_ops.finish = piv_finish;
 6456|       |
 6457|  15.0k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6458|  15.0k|	piv_ops.get_challenge = piv_get_challenge;
 6459|  15.0k|	piv_ops.logout = piv_logout;
 6460|  15.0k|	piv_ops.read_binary = piv_read_binary;
 6461|  15.0k|	piv_ops.write_binary = piv_write_binary;
 6462|  15.0k|	piv_ops.set_security_env = piv_set_security_env;
 6463|  15.0k|	piv_ops.restore_security_env = piv_restore_security_env;
 6464|  15.0k|	piv_ops.compute_signature = piv_compute_signature;
 6465|  15.0k|	piv_ops.decipher = piv_decipher;
 6466|  15.0k|	piv_ops.check_sw = piv_check_sw;
 6467|  15.0k|	piv_ops.card_ctl = piv_card_ctl;
 6468|  15.0k|	piv_ops.pin_cmd = piv_pin_cmd;
 6469|  15.0k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6470|       |
 6471|  15.0k|	return &piv_drv;
 6472|  15.0k|}
card-piv.c:piv_match_card:
 5413|  5.17k|{
 5414|  5.17k|	int r = 0;
 5415|       |
 5416|  5.17k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.17k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5417|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5418|       |	/* user provided card type must be one we know */
 5419|  5.17k|	switch (card->type) {
 5420|  5.17k|	case -1:
  ------------------
  |  Branch (5420:2): [True: 5.17k, False: 0]
  ------------------
 5421|  5.17k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5421:2): [True: 0, False: 5.17k]
  ------------------
 5422|  5.17k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5422:2): [True: 0, False: 5.17k]
  ------------------
 5423|  5.17k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5423:2): [True: 0, False: 5.17k]
  ------------------
 5424|  5.17k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5424:2): [True: 0, False: 5.17k]
  ------------------
 5425|  5.17k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5425:2): [True: 0, False: 5.17k]
  ------------------
 5426|  5.17k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5426:2): [True: 0, False: 5.17k]
  ------------------
 5427|  5.17k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5427:2): [True: 0, False: 5.17k]
  ------------------
 5428|  5.17k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5428:2): [True: 0, False: 5.17k]
  ------------------
 5429|  5.17k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5429:2): [True: 0, False: 5.17k]
  ------------------
 5430|  5.17k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5430:2): [True: 0, False: 5.17k]
  ------------------
 5431|  5.17k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5431:2): [True: 0, False: 5.17k]
  ------------------
 5432|  5.17k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5432:2): [True: 0, False: 5.17k]
  ------------------
 5433|  5.17k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5433:2): [True: 0, False: 5.17k]
  ------------------
 5434|  5.17k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5434:2): [True: 0, False: 5.17k]
  ------------------
 5435|  5.17k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5435:2): [True: 0, False: 5.17k]
  ------------------
 5436|  5.17k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5436:2): [True: 0, False: 5.17k]
  ------------------
 5437|  5.17k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5437:2): [True: 0, False: 5.17k]
  ------------------
 5438|  5.17k|		break;
 5439|      0|	default:
  ------------------
  |  Branch (5439:2): [True: 0, False: 5.17k]
  ------------------
 5440|      0|		return 0; /* can not handle the card */
 5441|  5.17k|	}
 5442|       |
 5443|  5.17k|	r = sc_lock(card);
 5444|  5.17k|	if (r < 0)
  ------------------
  |  Branch (5444:6): [True: 0, False: 5.17k]
  ------------------
 5445|      0|		return 0;
 5446|       |	/* its one we know, or we can test for it in piv_init */
 5447|  5.17k|	r = piv_match_card_continued(card);
 5448|  5.17k|	sc_unlock(card);
 5449|       |
 5450|  5.17k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5450:6): [True: 4.52k, False: 651]
  |  Branch (5450:15): [True: 0, False: 651]
  ------------------
 5451|       |		/* clean up what we left in card */
 5452|  4.52k|		piv_finish(card);
 5453|  4.52k|		return 0; /* match failed */
 5454|  4.52k|	}
 5455|       |
 5456|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5457|    651|	return 1; /* matched */
 5458|  5.17k|}
card-piv.c:piv_match_card_continued:
 5462|  5.17k|{
 5463|  5.17k|	int i, r = 0, r2 = 0;
 5464|  5.17k|	int type = -1;
 5465|  5.17k|	piv_private_data_t *priv = NULL;
 5466|  5.17k|	int saved_type = card->type;
 5467|  5.17k|	sc_apdu_t apdu;
 5468|  5.17k|	u8 yubico_version_buf[3] = {0};
 5469|       |
 5470|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5471|       |	/* User provided card type must be one we know */
 5472|       |
 5473|  5.17k|	switch (card->type) {
 5474|  5.17k|	case -1:
  ------------------
  |  Branch (5474:2): [True: 5.17k, False: 0]
  ------------------
 5475|  5.17k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5475:2): [True: 0, False: 5.17k]
  ------------------
 5476|  5.17k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5476:2): [True: 0, False: 5.17k]
  ------------------
 5477|  5.17k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5477:2): [True: 0, False: 5.17k]
  ------------------
 5478|  5.17k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5478:2): [True: 0, False: 5.17k]
  ------------------
 5479|  5.17k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5479:2): [True: 0, False: 5.17k]
  ------------------
 5480|  5.17k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5480:2): [True: 0, False: 5.17k]
  ------------------
 5481|  5.17k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5481:2): [True: 0, False: 5.17k]
  ------------------
 5482|  5.17k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5482:2): [True: 0, False: 5.17k]
  ------------------
 5483|  5.17k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5483:2): [True: 0, False: 5.17k]
  ------------------
 5484|  5.17k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5484:2): [True: 0, False: 5.17k]
  ------------------
 5485|  5.17k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5485:2): [True: 0, False: 5.17k]
  ------------------
 5486|  5.17k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5486:2): [True: 0, False: 5.17k]
  ------------------
 5487|  5.17k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5487:2): [True: 0, False: 5.17k]
  ------------------
 5488|  5.17k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5488:2): [True: 0, False: 5.17k]
  ------------------
 5489|  5.17k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5489:2): [True: 0, False: 5.17k]
  ------------------
 5490|  5.17k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5490:2): [True: 0, False: 5.17k]
  ------------------
 5491|  5.17k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5491:2): [True: 0, False: 5.17k]
  ------------------
 5492|  5.17k|		type = card->type;
 5493|  5.17k|		break;
 5494|      0|	default:
  ------------------
  |  Branch (5494:2): [True: 0, False: 5.17k]
  ------------------
 5495|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5496|  5.17k|	}
 5497|  5.17k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.17k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5498|  5.17k|	if (type == -1) {
  ------------------
  |  Branch (5498:6): [True: 5.17k, False: 0]
  ------------------
 5499|       |		/*
 5500|       |		 * Try to identify card by ATR or historical data in ATR
 5501|       |		 * currently all PIV card will respond to piv_find_aid
 5502|       |		 * the same. But in future may need to know card type first,
 5503|       |		 * so do it here.
 5504|       |		 */
 5505|       |
 5506|  5.17k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5506:7): [True: 1.61k, False: 3.56k]
  ------------------
 5507|  1.61k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5507:8): [True: 357, False: 1.26k]
  ------------------
 5508|    357|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5508:6): [True: 35, False: 322]
  ------------------
 5509|     35|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5510|  1.58k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5510:15): [True: 1.13k, False: 445]
  ------------------
 5511|  1.13k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5511:6): [True: 156, False: 981]
  ------------------
 5512|    156|				type = SC_CARD_TYPE_PIV_II_NEO;
 5513|  1.42k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5513:15): [True: 998, False: 428]
  ------------------
 5514|    998|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5514:6): [True: 34, False: 964]
  ------------------
 5515|     34|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5516|  1.39k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5516:15): [True: 964, False: 428]
  ------------------
 5517|    964|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5517:6): [True: 13, False: 951]
  ------------------
 5518|     13|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5519|     13|			}
 5520|       |			/* look for TLV historic data */
 5521|  1.37k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5521:13): [True: 1.36k, False: 18]
  ------------------
 5522|  1.36k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5522:6): [True: 332, False: 1.02k]
  ------------------
 5523|    332|				size_t datalen;
 5524|    332|				const u8 *data;
 5525|       |
 5526|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5527|    332|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5527:9): [True: 63, False: 269]
  ------------------
 5528|    332|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5529|     63|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5529:10): [True: 38, False: 25]
  |  Branch (5529:26): [True: 25, False: 13]
  ------------------
 5530|     25|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5531|     38|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5531:17): [True: 14, False: 24]
  |  Branch (5531:33): [True: 1, False: 13]
  ------------------
 5532|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5533|      1|					}
 5534|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5535|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5536|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5537|       |					 * will look at only 6 bytes that do match
 5538|       |					 */
 5539|     37|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5539:15): [True: 13, False: 24]
  |  Branch (5539:31): [True: 2, False: 11]
  ------------------
 5540|      2|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5541|      2|					}
 5542|    269|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5542:16): [True: 64, False: 205]
  ------------------
 5543|    269|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5544|     64|					int k;
 5545|       |
 5546|    182|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5546:18): [True: 124, False: 58]
  ------------------
 5547|    124|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5547:11): [True: 106, False: 18]
  ------------------
 5548|    106|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5548:9): [True: 6, False: 100]
  ------------------
 5549|      6|							type = SC_CARD_TYPE_PIV_II_HIST;
 5550|      6|							break;
 5551|      6|						}
 5552|    124|					}
 5553|     64|				}
 5554|    332|			}
 5555|  1.61k|		}
 5556|       |
 5557|  5.17k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.17k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5558|       |
 5559|  5.17k|		if (type == -1) {
  ------------------
  |  Branch (5559:7): [True: 4.90k, False: 272]
  ------------------
 5560|       |			/* use known ATRs  which changes the type */
 5561|  4.90k|			i = _sc_match_atr(card, piv_atrs, &type);
 5562|  4.90k|			if (i < 0)
  ------------------
  |  Branch (5562:8): [True: 4.87k, False: 31]
  ------------------
 5563|  4.87k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5564|  4.90k|		}
 5565|  5.17k|	}
 5566|       |
 5567|  5.17k|	card->type = type;
 5568|       |
 5569|       |	/* we either found via ATR historic bytes or ATR directly */
 5570|  5.17k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.17k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5571|       |
 5572|       |	/* allocate and init basic fields */
 5573|  5.17k|	priv = calloc(1, sizeof(piv_private_data_t));
 5574|       |
 5575|  5.17k|	if (!priv)
  ------------------
  |  Branch (5575:6): [True: 0, False: 5.17k]
  ------------------
 5576|  5.17k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5577|       |
 5578|  5.17k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5579|       |	/*
 5580|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5581|       |	 * If for some reason future cards have larger objects, this value needs to
 5582|       |	 * be increased here.
 5583|       |	 */
 5584|  5.17k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  229|  5.17k|#define MAX_FILE_SIZE 65535
  ------------------
 5585|  5.17k|	priv->selected_obj = -1;
 5586|  5.17k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5587|  5.17k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|  5.17k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5588|  5.17k|	priv->pstate = PIV_STATE_MATCH;
 5589|       |
 5590|       |#ifdef ENABLE_PIV_SM
 5591|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5592|       |	card->sm_ctx.ops.open = piv_sm_open;
 5593|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5594|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5595|       |	card->sm_ctx.ops.close = piv_sm_close;
 5596|       |#endif /* ENABLE_PIV_SM */
 5597|       |
 5598|       |	/* See if contactless  or run as virtual card */
 5599|       |	/* PivApplet in .github/test_piv.sh for example */
 5600|  5.17k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5600:6): [True: 1.90k, False: 3.27k]
  ------------------
 5601|  1.90k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5601:4): [True: 1.67k, False: 233]
  ------------------
 5602|  1.67k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5602:4): [True: 343, False: 1.32k]
  ------------------
 5603|    343|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5603:4): [True: 310, False: 33]
  ------------------
 5604|    310|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5604:4): [True: 290, False: 20]
  ------------------
 5605|    290|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  382|    290|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5606|    290|	}
 5607|       |
 5608|   315k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5608:14): [True: 310k, False: 5.17k]
  ------------------
 5609|   310k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  638|   310k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5609:7): [True: 103k, False: 207k]
  ------------------
 5610|   103k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|   108k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5611|       |	/*
 5612|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5613|       |	 * and PIV must be the default application.
 5614|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5615|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5616|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5617|       |	 *
 5618|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5619|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5620|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5621|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5622|       |	 */
 5623|       |
 5624|       |	/*
 5625|       |	 * if ATR matched or user forced card type
 5626|       |	 * test if PIV is active applet without using AID If fails try AID
 5627|       |	 */
 5628|       |
 5629|  5.17k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5629:6): [True: 303, False: 4.87k]
  ------------------
 5630|    303|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  382|    303|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5630:4): [True: 301, False: 2]
  ------------------
 5631|    301|		r = piv_find_discovery(card);
 5632|    301|		if (r < 0) {
  ------------------
  |  Branch (5632:7): [True: 268, False: 33]
  ------------------
 5633|    268|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5634|    268|			r = piv_find_aid(card);
 5635|    268|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    268|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    268|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    268|	int _ret = (r); \
  |  |  |  |  178|    268|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 107, False: 161]
  |  |  |  |  ------------------
  |  |  |  |  179|    107|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    107|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    107|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    107|		goto err; \
  |  |  |  |  182|    107|	} \
  |  |  |  |  183|    268|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 161]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5636|    268|		}
 5637|  4.87k|	} else {
 5638|       |		/* piv_find_aid saves al_label from response */
 5639|  4.87k|		r = piv_find_aid(card);
 5640|  4.87k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  4.87k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.87k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.87k|	int _ret = (r); \
  |  |  |  |  178|  4.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.42k, False: 457]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.42k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.42k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.42k|		goto err; \
  |  |  |  |  182|  4.42k|	} \
  |  |  |  |  183|  4.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 457]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5641|  4.87k|	}
 5642|       |
 5643|       |	/* Know to be PIV card but not the type */
 5644|       |
 5645|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5646|    651|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5646:6): [True: 7, False: 644]
  |  Branch (5646:24): [True: 6, False: 1]
  ------------------
 5647|      6|		switch (card->type) {
  ------------------
  |  Branch (5647:11): [True: 5, False: 1]
  ------------------
 5648|      5|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5648:3): [True: 5, False: 1]
  ------------------
 5649|      5|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5649:3): [True: 0, False: 6]
  ------------------
 5650|      9|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5650:16): [True: 5, False: 4]
  ------------------
 5651|      5|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5651:9): [True: 4, False: 1]
  ------------------
 5652|      4|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5652:7): [True: 1, False: 3]
  ------------------
 5653|      1|					sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "AL match i:%d type:%d", i, al_map[i].al_type);
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5654|      1|					card->type = al_map[i].al_type;
 5655|      1|					break;
 5656|      1|				}
 5657|      5|			}
 5658|      5|			break;
 5659|      6|		}
 5660|      6|	}
 5661|       |
 5662|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5663|    651|			card->type, priv->card_issues, r, priv->alg_ids);
 5664|       |
 5665|       |	/*
 5666|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5667|       |	 * via ATR, ATR Historic bytes or Application Label
 5668|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5669|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5670|       |	 */
 5671|    651|	switch (card->type) {
  ------------------
  |  Branch (5671:10): [True: 620, False: 31]
  ------------------
 5672|    106|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5672:2): [True: 106, False: 545]
  ------------------
 5673|    137|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5673:2): [True: 31, False: 620]
  ------------------
 5674|    160|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5674:2): [True: 23, False: 628]
  ------------------
 5675|    163|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5675:2): [True: 3, False: 648]
  ------------------
 5676|    164|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5676:2): [True: 1, False: 650]
  ------------------
 5677|    164|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5677:2): [True: 0, False: 651]
  ------------------
 5678|    620|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5678:2): [True: 456, False: 195]
  ------------------
 5679|    620|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    620|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5680|    620|		apdu.lc = 0;
 5681|    620|		apdu.data = NULL;
 5682|    620|		apdu.datalen = 0;
 5683|    620|		apdu.resp = yubico_version_buf;
 5684|    620|		apdu.resplen = sizeof(yubico_version_buf);
 5685|    620|		apdu.le = apdu.resplen;
 5686|    620|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5687|    620|		if (apdu.resplen == 3) {
  ------------------
  |  Branch (5687:7): [True: 291, False: 329]
  ------------------
 5688|    291|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5689|    291|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5690|    291|		}
 5691|    620|		break;
 5692|    651|	}
 5693|       |
 5694|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5695|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5696|       |
 5697|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5698|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5699|    651|	switch (card->type) {
  ------------------
  |  Branch (5699:10): [True: 461, False: 190]
  ------------------
 5700|       |	/*
 5701|       |	 * For cards that may also be CAC, try and read the CCC
 5702|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5703|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5704|       |	 */
 5705|    456|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5705:2): [True: 456, False: 195]
  ------------------
 5706|    456|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5706:2): [True: 0, False: 651]
  ------------------
 5707|    460|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5707:2): [True: 4, False: 647]
  ------------------
 5708|    460|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5708:2): [True: 0, False: 651]
  ------------------
 5709|    460|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5709:2): [True: 0, False: 651]
  ------------------
 5710|    461|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5710:2): [True: 1, False: 650]
  ------------------
 5711|    461|		r2 = piv_process_ccc(card);
 5712|    461|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    461|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5713|    461|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5714|       |		/* Ignore any error. */
 5715|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5716|    461|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  171|    461|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5716:7): [True: 5, False: 456]
  ------------------
 5717|      5|			switch (card->type) {
  ------------------
  |  Branch (5717:12): [True: 5, False: 0]
  ------------------
 5718|      5|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5718:4): [True: 5, False: 0]
  ------------------
 5719|      5|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5719:4): [True: 0, False: 5]
  ------------------
 5720|      5|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5720:4): [True: 0, False: 5]
  ------------------
 5721|      5|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5721:4): [True: 0, False: 5]
  ------------------
 5722|      5|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5723|      5|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      5|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5724|      5|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      5|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5725|      5|				break;
 5726|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5726:4): [True: 0, False: 5]
  ------------------
 5727|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5728|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5729|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5730|      0|				break;
 5731|      0|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5731:4): [True: 0, False: 5]
  ------------------
 5732|      0|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5733|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5734|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5735|      0|				break;
 5736|      5|			}
 5737|      5|		}
 5738|    461|		break;
 5739|       |
 5740|    461|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5740:2): [True: 0, False: 651]
  ------------------
 5741|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5741:2): [True: 0, False: 651]
  ------------------
 5742|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5742:2): [True: 0, False: 651]
  ------------------
 5743|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5744|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5745|      0|		break;
 5746|    651|	}
 5747|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5748|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5749|       |
 5750|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5751|    651|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  377|    651|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  382|     33|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5751:6): [True: 33, False: 618]
  |  Branch (5751:51): [True: 0, False: 33]
  ------------------
 5752|      0|		r2 = piv_find_aid(card);
 5753|      0|	}
 5754|       |
 5755|       |	/* Read AID if needed for these cards types */
 5756|    651|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  377|    651|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5756:6): [True: 33, False: 618]
  ------------------
 5757|     33|		switch (card->type) {
  ------------------
  |  Branch (5757:11): [True: 4, False: 29]
  ------------------
 5758|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5758:3): [True: 0, False: 33]
  ------------------
 5759|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5759:3): [True: 0, False: 33]
  ------------------
 5760|      1|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5760:3): [True: 1, False: 32]
  ------------------
 5761|      1|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5761:3): [True: 0, False: 33]
  ------------------
 5762|      4|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5762:3): [True: 3, False: 30]
  ------------------
 5763|      4|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5763:3): [True: 0, False: 33]
  ------------------
 5764|      4|			r2 = piv_find_aid(card);
 5765|     33|		}
 5766|     33|	}
 5767|       |
 5768|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5769|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5770|       |
 5771|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5772|    651|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  601|    651|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  592|    651|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  593|    651|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  594|    651|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  596|    651|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  597|    651|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5772:6): [True: 650, False: 1]
  ------------------
 5773|    650|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  601|    650|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  592|    650|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  593|    650|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  594|    650|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  596|    650|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  597|    650|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 5774|    650|	}
 5775|       |
 5776|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 5777|    651|	switch (card->type) {
  ------------------
  |  Branch (5777:10): [True: 451, False: 200]
  ------------------
 5778|    451|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5778:2): [True: 451, False: 200]
  ------------------
 5779|    451|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5779:2): [True: 0, False: 651]
  ------------------
 5780|    451|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  378|    451|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (5780:7): [True: 0, False: 451]
  ------------------
 5781|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5782|      0|		}
 5783|       |
 5784|       |#ifdef ENABLE_PIV_SM
 5785|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 5786|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 5787|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5788|       |		}
 5789|       |#endif
 5790|    451|		break;
 5791|    651|	}
 5792|       |
 5793|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5794|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5795|       |
 5796|       |	/*
 5797|       |	 * Set card_issues flags based card->type and version numbers if available.
 5798|       |	 *
 5799|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 5800|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 5801|       |	 * access to all the different devices or versions of the devices.
 5802|       |	 * Vendor and user input is welcome on any compliance issues.
 5803|       |	 *
 5804|       |	 * For the Yubico devices The assumption is also made that if a bug is
 5805|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 5806|       |	 *
 5807|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 5808|       |	 * may be set earlier or later then in the following code.
 5809|       |	 */
 5810|       |
 5811|    651|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    651|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5812|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5813|    651|	switch (card->type) {
 5814|    106|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5814:2): [True: 106, False: 545]
  ------------------
 5815|    106|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  588|    106|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 5816|    106|				     CI_VERIFY_630X |
  ------------------
  |  |  576|    106|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 5817|    106|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  585|    106|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5818|    106|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  581|    106|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5819|    106|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  586|    106|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 5820|    106|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5820:7): [True: 24, False: 82]
  ------------------
 5821|     24|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  577|     24|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5822|    106|		break;
 5823|       |
 5824|     31|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5824:2): [True: 31, False: 620]
  ------------------
 5825|     32|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5825:2): [True: 1, False: 650]
  ------------------
 5826|     35|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5826:2): [True: 3, False: 648]
  ------------------
 5827|     35|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  585|     35|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5828|     35|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  581|     35|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5829|     35|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5829:7): [True: 17, False: 18]
  ------------------
 5830|     17|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  577|     17|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5831|     35|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (5831:7): [True: 13, False: 22]
  ------------------
 5832|     13|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  595|     13|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  598|     13|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  599|     13|#define AI_X25519			    0x00200000U
  ------------------
 5833|     35|		break;
 5834|       |
 5835|     23|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5835:2): [True: 23, False: 628]
  ------------------
 5836|     23|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|     23|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5837|     23|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (5837:7): [True: 16, False: 7]
  ------------------
 5838|     16|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  595|     16|#define AI_RSA_4096			    0x00000008U
  ------------------
 5839|     23|		break;
 5840|       |
 5841|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5841:2): [True: 0, False: 651]
  ------------------
 5842|      1|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5842:2): [True: 1, False: 650]
  ------------------
 5843|      1|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5843:2): [True: 0, False: 651]
  ------------------
 5844|      1|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5844:2): [True: 0, False: 651]
  ------------------
 5845|      1|		priv->card_issues |= 0; /* could add others here */
 5846|      1|		break;
 5847|       |
 5848|    451|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5848:2): [True: 451, False: 200]
  ------------------
 5849|    455|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5849:2): [True: 4, False: 647]
  ------------------
 5850|    456|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5850:2): [True: 1, False: 650]
  ------------------
 5851|    456|		priv->card_issues |= 0; /* could add others here */
 5852|    456|		break;
 5853|       |
 5854|      5|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5854:2): [True: 5, False: 646]
  ------------------
 5855|      5|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5855:2): [True: 0, False: 651]
  ------------------
 5856|      5|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5856:2): [True: 0, False: 651]
  ------------------
 5857|      5|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|      5|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5858|      5|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  583|      5|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5859|      5|				     CI_NO_RANDOM |
  ------------------
  |  |  579|      5|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5860|      5|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|      5|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5861|      5|		break;
 5862|       |
 5863|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5863:2): [True: 0, False: 651]
  ------------------
 5864|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5865|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5866|      0|		break;
 5867|       |
 5868|     25|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5868:2): [True: 25, False: 626]
  ------------------
 5869|     25|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|     25|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5870|     25|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  583|     25|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5871|     25|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  579|     25|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5872|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 5873|     25|		break;
 5874|       |
 5875|      0|	default:
  ------------------
  |  Branch (5875:2): [True: 0, False: 651]
  ------------------
 5876|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5877|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5878|       |		/* opensc.conf may have it wrong, continue anyway */
 5879|      0|		sc_log(card->ctx, "Unknown PIV card->type %d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5880|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 5881|    651|	}
 5882|    651|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    651|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5883|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5884|       |
 5885|    651|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  582|    651|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
              	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  379|    646|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (5885:6): [True: 646, False: 5]
  |  Branch (5885:53): [True: 613, False: 33]
  ------------------
 5886|       |		/*
 5887|       |		 * We now know PIV AID is active, test DISCOVERY object again
 5888|       |		 * Some PIV don't support DISCOVERY and return
 5889|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 5890|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 5891|       |		 * to test for active AID.
 5892|       |		 */
 5893|    613|		r2 = piv_find_discovery(card);
 5894|       |
 5895|    613|		if (r2 < 0) {
  ------------------
  |  Branch (5895:7): [True: 601, False: 12]
  ------------------
 5896|    601|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|    601|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5897|    601|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  150|    601|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5898|    601|		}
 5899|    613|	}
 5900|       |
 5901|    651|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    651|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5902|    651|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5903|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 5904|    651|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    651|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    651|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    651|	int _ret = r; \
  |  |  |  |  155|    651|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 651, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    651|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 651]
  |  |  |  |  ------------------
  |  |  |  |  157|    651|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    651|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    651|	return _ret; \
  |  |  |  |  163|    651|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5905|       |
 5906|  4.52k|err:
 5907|  4.52k|	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.52k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5908|  4.52k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5909|       |	/* don't match. Does not have a PIV applet. */
 5910|  4.52k|	piv_finish(card);
 5911|  4.52k|	card->type = saved_type;
 5912|  4.52k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5913|  4.52k|}
card-piv.c:piv_find_discovery:
 5062|    959|{
 5063|    959|	int r = 0;
 5064|    959|	size_t rbuflen;
 5065|    959|	u8 *rbuf = NULL;
 5066|    959|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    959|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5067|       |
 5068|    959|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    959|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    959|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    959|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 959]
  |  |  ------------------
  ------------------
 5069|       |
 5070|       |	/*
 5071|       |	 * During piv_card_reader_lock_obtained,
 5072|       |	 * we use the discovery object to test if card present, and
 5073|       |	 * if PIV AID is active.
 5074|       |	 */
 5075|    959|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  150|    959|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5075:6): [True: 0, False: 959]
  ------------------
 5076|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5077|      0|		goto end;
 5078|      0|	}
 5079|       |
 5080|       |	/* If not valid: read, test,  cache */
 5081|    959|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  148|    959|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5081:6): [True: 914, False: 45]
  ------------------
 5082|    914|		r = piv_process_discovery(card);
 5083|    914|	} else {
 5084|       |		/* if already in cache,force read */
 5085|     45|		rbuflen = 1;
 5086|     45|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5087|       |		/* if same response as last, no need to parse */
 5088|     45|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5088:7): [True: 0, False: 45]
  |  Branch (5088:17): [True: 0, False: 0]
  ------------------
 5089|      0|			goto end;
 5090|       |
 5091|     45|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5091:7): [True: 22, False: 23]
  |  Branch (5091:17): [True: 15, False: 7]
  ------------------
 5092|     15|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5092:5): [True: 15, False: 0]
  ------------------
 5093|     15|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5093:5): [True: 12, False: 3]
  ------------------
 5094|     12|			goto end;
 5095|     12|		}
 5096|       |		/* This should not happen  bad card */
 5097|     33|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|     33|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5098|     33|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     33|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5099|     33|		goto end;
 5100|     45|	}
 5101|       |
 5102|    959|end:
 5103|    959|	free(rbuf);
 5104|    959|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    959|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    959|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    959|	int _ret = r; \
  |  |  |  |  155|    959|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 947, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  156|    947|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    902|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 902, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  157|    947|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    947|	} else { \
  |  |  |  |  159|     12|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     12|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     12|	} \
  |  |  |  |  162|    959|	return _ret; \
  |  |  |  |  163|    959|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5105|    959|}
card-piv.c:piv_process_discovery:
 4955|    914|{
 4956|    914|	int r;
 4957|    914|	u8 *rbuf = NULL;
 4958|    914|	size_t rbuflen = 0;
 4959|       |
 4960|    914|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 4961|       |	/* Note rbuf and rbuflen are now pointers into cache */
 4962|    914|	if (r < 0)
  ------------------
  |  Branch (4962:6): [True: 813, False: 101]
  ------------------
 4963|    813|		goto err;
 4964|       |
 4965|       |	/* the object is now cached, see what we have */
 4966|    101|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 4967|       |
 4968|    914|err:
 4969|    914|	LOG_FUNC_RETURN(card->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|    869|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 869, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4970|    914|}
card-piv.c:piv_get_cached_data:
 3194|  7.63k|{
 3195|       |
 3196|  7.63k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  7.63k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3197|  7.63k|	int r;
 3198|  7.63k|	u8 *rbuf = NULL;
 3199|  7.63k|	size_t rbuflen;
 3200|       |
 3201|  7.63k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.63k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.63k]
  |  |  ------------------
  ------------------
 3202|       |
 3203|  7.63k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3203:6): [True: 0, False: 7.63k]
  |  Branch (3203:21): [True: 0, False: 7.63k]
  ------------------
 3204|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3205|       |
 3206|  7.63k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  7.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3207|       |
 3208|       |	/* see if we have it cached */
 3209|  7.63k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  148|  7.63k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3209:6): [True: 635, False: 7.00k]
  ------------------
 3210|       |
 3211|    635|		sc_log(card->ctx,
  ------------------
  |  |   71|    635|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3212|    635|				"found #%d %p:%" SC_FORMAT_LEN_SIZE_T "u %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3213|    635|				enumtag,
 3214|    635|				priv->obj_cache[enumtag].obj_data,
 3215|    635|				priv->obj_cache[enumtag].obj_len,
 3216|    635|				priv->obj_cache[enumtag].internal_obj_data,
 3217|    635|				priv->obj_cache[enumtag].internal_obj_len);
 3218|       |
 3219|    635|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3219:7): [True: 0, False: 635]
  ------------------
 3220|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3221|      0|			sc_log(card->ctx, "#%d found but len=0", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3222|      0|			goto err;
 3223|      0|		}
 3224|    635|		*buf = priv->obj_cache[enumtag].obj_data;
 3225|    635|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3226|    635|		r = (int)*buf_len;
 3227|    635|		goto ok;
 3228|    635|	}
 3229|       |
 3230|       |	/*
 3231|       |	 * If we know it can not be on the card  i.e. History object
 3232|       |	 * has been read, and we know what other certs may or
 3233|       |	 * may not be on the card. We can avoid extra overhead
 3234|       |	 * Also used if object on card was not parsable
 3235|       |	 */
 3236|       |
 3237|  7.00k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  150|  7.00k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3237:6): [True: 0, False: 7.00k]
  ------------------
 3238|      0|		sc_log(card->ctx, "no_obj #%d", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3239|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3240|      0|		goto err;
 3241|      0|	}
 3242|       |
 3243|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3244|  7.00k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
 3245|  7.00k|	rbuflen = 1;
 3246|  7.00k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3247|  7.00k|	if (r > 0) {
  ------------------
  |  Branch (3247:6): [True: 1.10k, False: 5.89k]
  ------------------
 3248|  1.10k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|  1.10k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3249|  1.10k|		priv->obj_cache[enumtag].obj_len = r;
 3250|  1.10k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3251|  1.10k|		*buf = rbuf;
 3252|  1.10k|		*buf_len = r;
 3253|       |
 3254|  1.10k|		sc_log(card->ctx,
  ------------------
  |  |   71|  1.10k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3255|  1.10k|				"added #%d  %p:%" SC_FORMAT_LEN_SIZE_T "u %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3256|  1.10k|				enumtag,
 3257|  1.10k|				priv->obj_cache[enumtag].obj_data,
 3258|  1.10k|				priv->obj_cache[enumtag].obj_len,
 3259|  1.10k|				priv->obj_cache[enumtag].internal_obj_data,
 3260|  1.10k|				priv->obj_cache[enumtag].internal_obj_len);
 3261|       |
 3262|  5.89k|	} else {
 3263|  5.89k|		free(rbuf);
 3264|  5.89k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  5.89k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3264:7): [True: 0, False: 5.89k]
  |  Branch (3264:17): [True: 569, False: 5.32k]
  ------------------
 3265|    569|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    569|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3266|    569|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|    569|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3267|    569|			priv->obj_cache[enumtag].obj_len = 0;
 3268|  5.32k|		} else {
 3269|  5.32k|			goto err;
 3270|  5.32k|		}
 3271|  5.89k|	}
 3272|  2.31k|ok:
 3273|       |
 3274|  7.63k|err:
 3275|  7.63k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.63k|	int _ret = r; \
  |  |  |  |  155|  7.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.89k, False: 1.74k]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.89k|	} else { \
  |  |  |  |  159|  1.74k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.74k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.74k|	} \
  |  |  |  |  162|  7.63k|	return _ret; \
  |  |  |  |  163|  7.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3276|  7.63k|}
card-piv.c:piv_parse_discovery:
 4898|    101|{
 4899|    101|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    101|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4900|    101|	int r = 0;
 4901|    101|	const u8 *body;
 4902|    101|	size_t bodylen;
 4903|    101|	const u8 *aid;
 4904|    101|	size_t aidlen;
 4905|    101|	const u8 *pinp;
 4906|    101|	size_t pinplen;
 4907|    101|	unsigned int cla_out, tag_out;
 4908|       |
 4909|    101|	if (rbuflen != 0) {
  ------------------
  |  Branch (4909:6): [True: 101, False: 0]
  ------------------
 4910|    101|		body = rbuf;
 4911|    101|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    202|#define SC_SUCCESS				0
  ------------------
  |  Branch (4911:7): [True: 0, False: 101]
  ------------------
 4912|    101|				body == NULL ||
  ------------------
  |  Branch (4912:5): [True: 0, False: 101]
  ------------------
 4913|    101|				bodylen == 0 ||
  ------------------
  |  Branch (4913:5): [True: 1, False: 100]
  ------------------
 4914|    100|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (4914:5): [True: 0, False: 100]
  ------------------
 4915|      1|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4916|      1|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 4917|      1|			goto err;
 4918|      1|		}
 4919|       |
 4920|    100|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4921|    100|				"Discovery 0x%2.2x 0x%2.2x %p:%" SC_FORMAT_LEN_SIZE_T "u",
 4922|    100|				cla_out, tag_out, body, bodylen);
 4923|    100|		aidlen = 0;
 4924|    100|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 4925|    100|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (4925:7): [True: 11, False: 89]
  |  Branch (4925:22): [True: 4, False: 85]
  ------------------
 4926|     85|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (4926:5): [True: 40, False: 45]
  ------------------
 4927|     55|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   71|     55|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4928|     55|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     55|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4929|     55|			goto err;
 4930|     55|		}
 4931|     45|		if (aid_only == 0) {
  ------------------
  |  Branch (4931:7): [True: 45, False: 0]
  ------------------
 4932|     45|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 4933|     45|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (4933:8): [True: 29, False: 16]
  |  Branch (4933:16): [True: 28, False: 1]
  ------------------
 4934|     28|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  380|     28|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 4935|     28|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 4936|     28|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4937|     28|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  368|     28|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  369|     28|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  368|     28|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  369|     28|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (4937:9): [True: 2, False: 26]
  ------------------
 4938|      2|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  374|      2|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (4938:7): [True: 1, False: 1]
  ------------------
 4939|      1|					sc_log(card->ctx, "Pin Preference - Global");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4940|      1|					priv->pin_preference = 0x00;
 4941|      1|				}
 4942|     28|			}
 4943|     45|		}
 4944|     45|		r = SC_SUCCESS;
  ------------------
  |  |   28|     45|#define SC_SUCCESS				0
  ------------------
 4945|     45|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  379|     45|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 4946|     45|	}
 4947|       |
 4948|    101|err:
 4949|    101|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|     56|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 56, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4950|    101|}
card-piv.c:piv_get_data:
 3082|  7.04k|{
 3083|  7.04k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  7.04k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3084|  7.04k|	u8 *p;
 3085|  7.04k|	u8 *tbuf;
 3086|  7.04k|	int r = 0;
 3087|  7.04k|	u8 tagbuf[8];
 3088|  7.04k|	size_t tag_len;
 3089|  7.04k|	int alloc_buf = 0;
 3090|       |
 3091|  7.04k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.04k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.04k]
  |  |  ------------------
  ------------------
 3092|       |
 3093|  7.04k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
 3094|       |
 3095|  7.04k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3096|  7.04k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  7.04k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3096:6): [True: 0, False: 7.04k]
  ------------------
 3097|      0|		sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3098|      0|		return r;
 3099|      0|	}
 3100|       |
 3101|  7.04k|	tag_len = piv_objects[enumtag].tag_len;
 3102|       |
 3103|  7.04k|	p = tagbuf;
 3104|  7.04k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3105|  7.04k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  7.04k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3105:6): [True: 0, False: 7.04k]
  ------------------
 3106|      0|		sc_log(card->ctx, "Failed to encode ASN1 tag");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3107|      0|		goto err;
 3108|      0|	}
 3109|       |
 3110|  7.04k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3110:6): [True: 7.04k, False: 0]
  |  Branch (3110:23): [True: 7.04k, False: 0]
  ------------------
 3111|  7.04k|		*buf_len = priv->max_object_size; /* will allocate below */
 3112|  7.04k|		alloc_buf = 1;
 3113|  7.04k|	}
 3114|       |
 3115|  7.04k|	sc_log(card->ctx,
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
 3116|  7.04k|			"buffer for #%d *buf=0x%p len=%" SC_FORMAT_LEN_SIZE_T "u",
 3117|  7.04k|			enumtag, *buf, *buf_len);
 3118|  7.04k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3118:6): [True: 7.04k, False: 0]
  |  Branch (3118:22): [True: 7.04k, False: 0]
  ------------------
 3119|  7.04k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  7.04k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3119:7): [True: 0, False: 7.04k]
  ------------------
 3120|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3121|      0|			goto err;
 3122|      0|		}
 3123|  7.04k|		*buf = malloc(*buf_len);
 3124|  7.04k|		if (*buf == NULL) {
  ------------------
  |  Branch (3124:7): [True: 0, False: 7.04k]
  ------------------
 3125|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3126|      0|			goto err;
 3127|      0|		}
 3128|  7.04k|	}
 3129|       |
 3130|       |#ifdef ENABLE_PIV_SM
 3131|       |	/*
 3132|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3133|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3134|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3135|       |	 * i.e. no interference from other applications
 3136|       |	 */
 3137|       |	sc_log(card->ctx, "enumtag:%d sm_ctx.sm_mode:%d piv_objects[enumtag].flags:0x%8.8x sm_flags:0x%8.8lx it_flags:0x%8.8x",
 3138|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3139|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3140|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3141|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3142|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3143|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3144|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3145|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3146|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3147|       |	}
 3148|       |
 3149|       |#endif /* ENABLE_PIV_SM */
 3150|  7.04k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3151|  7.04k|	if (r > 0) {
  ------------------
  |  Branch (3151:6): [True: 1.56k, False: 5.47k]
  ------------------
 3152|  1.56k|		int r_tag;
 3153|  1.56k|		unsigned int cla_out, tag_out;
 3154|  1.56k|		size_t bodylen = 0;
 3155|  1.56k|		const u8 *body = *buf;
 3156|  1.56k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3157|  1.56k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  3.13k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3157:7): [True: 141, False: 1.42k]
  |  Branch (3157:30): [True: 50, False: 1.37k]
  ------------------
 3158|  1.37k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3158:5): [True: 244, False: 1.13k]
  ------------------
 3159|    435|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3160|    435|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    435|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3161|    435|			goto err;
 3162|    435|		}
 3163|  1.13k|		*buf_len = (body - *buf) + bodylen;
 3164|  5.47k|	} else if (r == 0) {
  ------------------
  |  Branch (3164:13): [True: 91, False: 5.38k]
  ------------------
 3165|     91|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     91|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3166|     91|		goto err;
 3167|  5.38k|	} else {
 3168|  5.38k|		goto err;
 3169|  5.38k|	}
 3170|       |
 3171|  1.13k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3171:6): [True: 1.13k, False: 0]
  |  Branch (3171:19): [True: 1.13k, False: 0]
  ------------------
 3172|  1.13k|		tbuf = malloc(r);
 3173|  1.13k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3173:7): [True: 0, False: 1.13k]
  ------------------
 3174|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3175|      0|			goto err;
 3176|      0|		}
 3177|  1.13k|		memcpy(tbuf, *buf, r);
 3178|  1.13k|		free(*buf);
 3179|  1.13k|		alloc_buf = 0;
 3180|  1.13k|		*buf = tbuf;
 3181|  1.13k|	}
 3182|       |
 3183|  7.04k|err:
 3184|  7.04k|	if (alloc_buf) {
  ------------------
  |  Branch (3184:6): [True: 5.91k, False: 1.13k]
  ------------------
 3185|  5.91k|		free(*buf);
 3186|  5.91k|		*buf = NULL;
 3187|  5.91k|	}
 3188|  7.04k|	sc_unlock(card);
 3189|  7.04k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.04k|	int _ret = r; \
  |  |  |  |  155|  7.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.91k, False: 1.13k]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  5.91k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.91k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.91k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.91k|	} else { \
  |  |  |  |  159|  1.13k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.13k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.13k|	} \
  |  |  |  |  162|  7.04k|	return _ret; \
  |  |  |  |  163|  7.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3190|  7.04k|}
card-piv.c:piv_general_io:
 1786|  7.04k|{
 1787|  7.04k|	int r;
 1788|  7.04k|	sc_apdu_t apdu;
 1789|       |
 1790|  7.04k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.04k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.04k]
  |  |  ------------------
  ------------------
 1791|       |
 1792|  7.04k|	r = sc_lock(card);
 1793|  7.04k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  7.04k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1793:6): [True: 0, False: 7.04k]
  ------------------
 1794|  7.04k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1795|       |
 1796|  7.04k|	sc_format_apdu(card, &apdu,
 1797|  7.04k|			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  294|  7.04k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1797:4): [True: 7.04k, False: 0]
  ------------------
 1798|  7.04k|			ins, p1, p2);
 1799|  7.04k|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  7.04k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1800|       |#ifdef ENABLE_PIV_SM
 1801|       |	if (card->sm_ctx.sm_mode != SM_MODE_NONE && sendbuflen > 255) {
 1802|       |		/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1803|       |		apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1804|       |	}
 1805|       |#endif
 1806|  7.04k|	apdu.lc = sendbuflen;
 1807|  7.04k|	apdu.datalen = sendbuflen;
 1808|  7.04k|	apdu.data = sendbuf;
 1809|       |
 1810|  7.04k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1810:6): [True: 7.04k, False: 0]
  |  Branch (1810:17): [True: 7.04k, False: 0]
  ------------------
 1811|  7.04k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1811:13): [True: 7.04k, False: 0]
  ------------------
 1812|  7.04k|		apdu.resplen = recvbuflen;
 1813|  7.04k|	} else {
 1814|      0|		apdu.le = 0;
 1815|      0|		apdu.resplen = 0;
 1816|      0|	}
 1817|  7.04k|	apdu.resp = recvbuf;
 1818|       |
 1819|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1820|  7.04k|	r = sc_transmit_apdu(card, &apdu);
 1821|       |
 1822|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1823|  7.04k|	if (r < 0) {
  ------------------
  |  Branch (1823:6): [True: 100, False: 6.94k]
  ------------------
 1824|    100|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1825|    100|		goto err;
 1826|    100|	}
 1827|       |
 1828|  6.94k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1828:6): [True: 57, False: 6.88k]
  |  Branch (1828:26): [True: 14, False: 43]
  ------------------
 1829|     14|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     14|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1830|  6.93k|	else
 1831|  6.93k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1832|       |
 1833|  6.94k|	if (r < 0) {
  ------------------
  |  Branch (1833:6): [True: 5.28k, False: 1.65k]
  ------------------
 1834|  5.28k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1835|  5.28k|		goto err;
 1836|  5.28k|	}
 1837|       |
 1838|  1.65k|	r = (int)apdu.resplen;
 1839|       |
 1840|  7.04k|err:
 1841|  7.04k|	sc_unlock(card);
 1842|  7.04k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.04k|	int _ret = r; \
  |  |  |  |  155|  7.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.47k, False: 1.56k]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  5.38k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.38k, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.47k|	} else { \
  |  |  |  |  159|  1.56k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.56k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.56k|	} \
  |  |  |  |  162|  7.04k|	return _ret; \
  |  |  |  |  163|  7.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1843|  7.04k|}
card-piv.c:piv_obj_cache_free_entry:
 5360|   311k|{
 5361|   311k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|   311k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5362|       |
 5363|   311k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5363:6): [True: 1.10k, False: 310k]
  ------------------
 5364|  1.10k|		free(priv->obj_cache[enumtag].obj_data);
 5365|   311k|	priv->obj_cache[enumtag].obj_data = NULL;
 5366|   311k|	priv->obj_cache[enumtag].obj_len = 0;
 5367|       |
 5368|   311k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5368:6): [True: 635, False: 310k]
  ------------------
 5369|    635|		free(priv->obj_cache[enumtag].internal_obj_data);
 5370|   311k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5371|   311k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5372|   311k|	priv->obj_cache[enumtag].flags = flags;
 5373|       |
 5374|   311k|	return SC_SUCCESS;
  ------------------
  |  |   28|   311k|#define SC_SUCCESS				0
  ------------------
 5375|   311k|}
card-piv.c:piv_find_aid:
 2894|  5.15k|{
 2895|  5.15k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  5.15k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2896|  5.15k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2897|  5.15k|	int r, i, j;
 2898|  5.15k|	const u8 *tag;
 2899|  5.15k|	size_t taglen;
 2900|  5.15k|	const u8 *nextac;
 2901|  5.15k|	const u8 *next80;
 2902|  5.15k|	const u8 *pix;
 2903|  5.15k|	size_t pixlen;
 2904|  5.15k|	const u8 *al_label;
 2905|  5.15k|	size_t al_labellen;
 2906|  5.15k|	const u8 *actag; /* Cipher Suite */
 2907|  5.15k|	size_t actaglen;
 2908|  5.15k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2909|  5.15k|	size_t csailen;
 2910|  5.15k|	size_t resplen = sizeof(rbuf);
 2911|       |#ifdef ENABLE_PIV_SM
 2912|       |	int found_csai = 0;
 2913|       |#endif
 2914|       |
 2915|  5.15k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.15k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.15k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.15k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.15k]
  |  |  ------------------
  ------------------
 2916|       |
 2917|       |	/* first  see if the default application will return a template
 2918|       |	 * that we know about.
 2919|       |	 */
 2920|       |
 2921|  5.15k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2922|  5.15k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2922:6): [True: 0, False: 5.15k]
  |  Branch (2922:15): [True: 0, False: 0]
  |  Branch (2922:38): [True: 0, False: 0]
  |  Branch (2922:70): [True: 0, False: 0]
  ------------------
 2923|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2924|       |		/* no need to parse again, same as last time */
 2925|      0|	}
 2926|  5.15k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2926:6): [True: 804, False: 4.34k]
  |  Branch (2926:16): [True: 730, False: 74]
  ------------------
 2927|    730|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2928|    730|		if (tag != NULL) {
  ------------------
  |  Branch (2928:7): [True: 685, False: 45]
  ------------------
 2929|    685|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  377|    685|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2930|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2931|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2932|       |			 * where xx is the SM csID either 27 or 2E.
 2933|       |			 * Some vendors may include entries for supported Algorithms even when
 2934|       |			 * not required. We will use these if possible
 2935|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2936|       |			 */
 2937|    685|			nextac = tag;
 2938|    852|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2938:11): [True: 167, False: 685]
  ------------------
 2939|    852|						0xAC, &actaglen)) != NULL) {
 2940|    167|				nextac = actag + actaglen;
 2941|       |
 2942|    167|				next80 = actag;
 2943|    311|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2943:12): [True: 144, False: 167]
  ------------------
 2944|    311|							0x80, &csailen)) != NULL) {
 2945|    144|					next80 = csai + csailen;
 2946|    144|					if (csailen == 1) {
  ------------------
  |  Branch (2946:10): [True: 80, False: 64]
  ------------------
 2947|     80|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2948|     80|						j = piv_ai_map_find_by_id(card, *csai);
 2949|     80|						if (j >= 0) {
  ------------------
  |  Branch (2949:11): [True: 40, False: 40]
  ------------------
 2950|     40|							priv->alg_ids |= ai_map[j].ai_flag;
 2951|     40|							continue;
 2952|     40|						}
 2953|       |#ifdef ENABLE_PIV_SM
 2954|       |						/* check if id is NIST SM */
 2955|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2956|       |							if (*csai != css[i].id)
 2957|       |								continue;
 2958|       |							if (found_csai) {
 2959|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2960|       |							} else {
 2961|       |								priv->cs = &css[i];
 2962|       |								priv->csID = *csai;
 2963|       |								found_csai++;
 2964|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2965|       |							}
 2966|       |						}
 2967|       |#endif /* ENABLE_PIV_SM */
 2968|     80|					}
 2969|    144|				}
 2970|    167|			}
 2971|       |
 2972|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2973|    685|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2974|    685|			if (al_label != NULL) {
  ------------------
  |  Branch (2974:8): [True: 7, False: 678]
  ------------------
 2975|      7|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  129|      7|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      7|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2976|      7|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2976:9): [True: 0, False: 7]
  ------------------
 2977|      0|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2978|      0|				}
 2979|      7|				memcpy(priv->al_label, al_label, al_labellen);
 2980|      7|				priv->al_labellen = (int)al_labellen;
 2981|      7|			}
 2982|       |
 2983|    685|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 2984|    685|			if (pix != NULL) {
  ------------------
  |  Branch (2984:8): [True: 645, False: 40]
  ------------------
 2985|    645|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    645|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2986|       |
 2987|       |				/* early cards returned full AID, rather then just the pix */
 2988|    707|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (2988:17): [True: 680, False: 27]
  ------------------
 2989|    680|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (2989:11): [True: 676, False: 4]
  ------------------
 2990|    676|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (2990:12): [True: 613, False: 63]
  ------------------
 2991|     67|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (2991:10): [True: 52, False: 15]
  |  Branch (2991:45): [True: 5, False: 47]
  ------------------
 2992|    618|													     piv_aids[i].len_short) == 0))) {
 2993|    618|						free(priv->aid_der.value); /* free previous value if any */
 2994|    618|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (2994:11): [True: 0, False: 618]
  ------------------
 2995|      0|							LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2996|      0|						}
 2997|    618|						memcpy(priv->aid_der.value, rbuf, resplen);
 2998|    618|						priv->aid_der.len = resplen;
 2999|    618|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    618|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    618|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    618|	int _ret = r; \
  |  |  |  |  155|    618|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 610, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  156|    610|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 610]
  |  |  |  |  ------------------
  |  |  |  |  157|    610|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    610|	} else { \
  |  |  |  |  159|      8|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      8|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      8|	} \
  |  |  |  |  162|    618|	return _ret; \
  |  |  |  |  163|    618|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3000|    618|					}
 3001|    680|				}
 3002|    645|			}
 3003|    685|		}
 3004|    730|	}
 3005|       |
 3006|  4.53k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  4.53k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.53k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.53k|	int _ret = r; \
  |  |  |  |  155|  4.53k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.53k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  4.53k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.53k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.53k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.53k|	return _ret; \
  |  |  |  |  163|  4.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3007|  4.53k|}
card-piv.c:piv_ai_map_find_by_id:
 2877|     80|{
 2878|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2879|     80|	int i;
 2880|       |
 2881|    526|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2881:14): [True: 486, False: 40]
  ------------------
 2882|    486|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2882:7): [True: 40, False: 446]
  ------------------
 2883|     40|			return i;
 2884|    486|	}
 2885|     40|	return -1;
 2886|     80|}
card-piv.c:piv_process_ccc:
 5043|    461|{
 5044|    461|	int r = 0;
 5045|    461|	u8 *rbuf = NULL;
 5046|    461|	size_t rbuflen = 0;
 5047|       |
 5048|    461|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    461|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    461|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    461|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 461]
  |  |  ------------------
  ------------------
 5049|    461|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5050|       |
 5051|    461|	if (r < 0)
  ------------------
  |  Branch (5051:6): [True: 415, False: 46]
  ------------------
 5052|    415|		goto err;
 5053|       |
 5054|       |	/* the object is now cached, see what we have */
 5055|     46|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5056|    461|err:
 5057|    461|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    461|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    461|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    461|	int _ret = r; \
  |  |  |  |  155|    461|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 461, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    461|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    454|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 454, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|    461|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    461|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    461|	return _ret; \
  |  |  |  |  163|    461|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5058|    461|}
card-piv.c:piv_parse_ccc:
 4979|     46|{
 4980|     46|	int r = 0;
 4981|     46|	const u8 *body;
 4982|     46|	size_t bodylen;
 4983|     46|	unsigned int cla_out, tag_out;
 4984|       |
 4985|     46|	u8 tag;
 4986|     46|	const u8 *end;
 4987|     46|	size_t len;
 4988|       |
 4989|     46|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|     46|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4990|       |
 4991|     46|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 4992|       |
 4993|     46|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (4993:6): [True: 0, False: 46]
  |  Branch (4993:22): [True: 0, False: 46]
  ------------------
 4994|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 4995|      0|		goto err;
 4996|      0|	}
 4997|       |
 4998|       |	/* Outer layer is a DER tlv */
 4999|     46|	body = rbuf;
 5000|     46|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|     92|#define SC_SUCCESS				0
  ------------------
  |  Branch (5000:6): [True: 0, False: 46]
  ------------------
 5001|     46|			body == NULL ||
  ------------------
  |  Branch (5001:4): [True: 0, False: 46]
  ------------------
 5002|     46|			bodylen == 0 ||
  ------------------
  |  Branch (5002:4): [True: 1, False: 45]
  ------------------
 5003|     45|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5003:4): [True: 0, False: 45]
  ------------------
 5004|      1|		sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5005|      1|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5006|      1|		goto err;
 5007|      1|	}
 5008|       |
 5009|     45|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  167|     45|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5010|       |
 5011|       |	/* CCC  entries are simple tlv */
 5012|     45|	end = body + bodylen;
 5013|    406|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5013:9): [True: 399, False: 7]
  ------------------
 5014|    399|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5015|    399|		if (r < 0)
  ------------------
  |  Branch (5015:7): [True: 38, False: 361]
  ------------------
 5016|     38|			goto err;
 5017|    361|		switch (tag) {
  ------------------
  |  Branch (5017:11): [True: 100, False: 261]
  ------------------
 5018|     62|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  173|     62|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5018:3): [True: 62, False: 299]
  ------------------
 5019|     62|			if (len == 0x15) {
  ------------------
  |  Branch (5019:8): [True: 43, False: 19]
  ------------------
 5020|     43|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5020:9): [True: 10, False: 33]
  ------------------
 5021|     10|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  168|     10|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5022|     33|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5022:14): [True: 10, False: 23]
  ------------------
 5023|     10|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  169|     10|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5024|     43|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5024:9): [True: 13, False: 30]
  ------------------
 5025|     13|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  170|     13|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5026|     43|			}
 5027|     62|			break;
 5028|     38|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  174|     38|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5028:3): [True: 38, False: 323]
  ------------------
 5029|     38|			if (len == 0x10) {
  ------------------
  |  Branch (5029:8): [True: 27, False: 11]
  ------------------
 5030|     27|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5030:9): [True: 11, False: 16]
  ------------------
 5031|     11|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  171|     11|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5032|     27|			}
 5033|     38|			break;
 5034|    361|		}
 5035|    361|	}
 5036|       |
 5037|     46|err:
 5038|     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|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 39, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5039|     46|}
card-piv.c:piv_init:
 5917|    651|{
 5918|    651|	int r = 0;
 5919|    651|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    651|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5920|    651|	unsigned long flags;
 5921|    651|	unsigned long flags_eddsa;
 5922|    651|	unsigned long flags_xeddsa;
 5923|    651|	unsigned long ext_flags;
 5924|       |
 5925|    651|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    651|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    651|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    651|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 651]
  |  |  ------------------
  ------------------
 5926|       |
 5927|    651|	r = sc_lock(card); /* hold until match or init is complete */
 5928|    651|	LOG_TEST_RET(card->ctx, r, "sc_lock 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: 0, False: 651]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    651|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 651]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5929|       |
 5930|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 5931|    651|	if (priv == NULL) {
  ------------------
  |  Branch (5931:6): [True: 0, False: 651]
  ------------------
 5932|      0|		r = piv_match_card_continued(card);
 5933|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  432|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5934|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (5934:7): [True: 0, False: 0]
  |  Branch (5934:16): [True: 0, False: 0]
  ------------------
 5935|      0|			sc_log(card->ctx, "piv_match_card_continued failed card->type:%d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5936|      0|			sc_unlock(card);
 5937|      0|			piv_finish(card);
 5938|       |			/* tell sc_connect_card to try other driver */
 5939|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5940|      0|		}
 5941|      0|	}
 5942|       |
 5943|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 5944|    651|	piv_load_options(card);
 5945|       |
 5946|    651|	priv->pstate = PIV_STATE_INIT;
 5947|       |
 5948|    651|	sc_log(card->ctx,
  ------------------
  |  |   71|    651|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5949|    651|			"Max send = %" SC_FORMAT_LEN_SIZE_T "u recv = %" SC_FORMAT_LEN_SIZE_T "u card->type:%d, CI:%08x AI:%08x",
 5950|    651|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 5951|    651|	card->cla = 0x00;
 5952|    651|	if (card->name == NULL)
  ------------------
  |  Branch (5952:6): [True: 651, False: 0]
  ------------------
 5953|    651|		card->name = card->driver->name;
 5954|       |
 5955|    651|	priv->enumtag = piv_aids[0].enumtag;
 5956|       |
 5957|       |	/* PKCS#11 may try to generate session keys, and get confused
 5958|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 5959|       |	 * piv-tool can still do this, just don't tell PKCS#11
 5960|       |	 */
 5961|       |
 5962|    651|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|    651|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 5963|       |
 5964|    651|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (5964:6): [True: 0, False: 651]
  ------------------
 5965|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 5966|      0|	}
 5967|       |
 5968|    651|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  592|    651|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (5968:6): [True: 650, False: 1]
  ------------------
 5969|    650|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 5970|       |
 5971|    651|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  593|    651|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (5971:6): [True: 650, False: 1]
  ------------------
 5972|    650|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 5973|       |
 5974|    651|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  594|    651|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (5974:6): [True: 650, False: 1]
  ------------------
 5975|    650|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 5976|       |
 5977|    651|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  595|    651|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (5977:6): [True: 29, False: 622]
  ------------------
 5978|     29|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 5979|       |
 5980|    651|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  589|    651|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (5980:6): [True: 651, False: 0]
  ------------------
 5981|    651|		int i;
 5982|    651|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  183|    651|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  182|    651|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    651|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    651|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 5983|    651|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    651|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    651|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 5984|    651|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  197|    651|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 5985|    651|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  198|    651|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  182|    651|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 5986|       |
 5987|  3.25k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (5987:15): [True: 2.60k, False: 651]
  ------------------
 5988|  2.60k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|  2.60k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (5988:8): [True: 1.30k, False: 1.30k]
  ------------------
 5989|  1.30k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  588|  2.60k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (5989:11): [True: 212, False: 1.09k]
  |  Branch (5989:46): [True: 106, False: 106]
  ------------------
 5990|  1.19k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 5991|  1.30k|			}
 5992|       |
 5993|  1.30k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  598|  2.60k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|     28|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (5993:13): [True: 28, False: 1.27k]
  |  Branch (5993:41): [True: 14, False: 14]
  ------------------
 5994|     14|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 5995|       |
 5996|  1.28k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  599|  2.57k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|     15|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (5996:13): [True: 15, False: 1.27k]
  |  Branch (5996:42): [True: 14, False: 1]
  ------------------
 5997|     14|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 5998|  2.60k|		}
 5999|    651|	}
 6000|       |
 6001|    651|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  579|    651|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6001:6): [True: 621, False: 30]
  ------------------
 6002|    621|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    621|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6003|       |
 6004|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6005|    651|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    651|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6006|       |
 6007|       |	/*
 6008|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6009|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6010|       |	 */
 6011|       |
 6012|       |#ifdef ENABLE_PIV_SM
 6013|       |	/*
 6014|       |	 * 800-73-4
 6015|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6016|       |	 */
 6017|       |	if (priv->csID && priv->cs != NULL) {
 6018|       |		/*
 6019|       |		 * Main point in SM and VCI is to allow contactless access
 6020|       |		 */
 6021|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6022|       |
 6023|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6024|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6025|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6026|       |			r = SC_SUCCESS; /* Users choice */
 6027|       |
 6028|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6029|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6030|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6031|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6032|       |
 6033|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6034|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6035|       |				(priv->pairing_code[0] == 0x00)) {
 6036|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6037|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6038|       |
 6039|       |		} else {
 6040|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6041|       |			r = piv_sm_open(card);
 6042|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6043|       |		}
 6044|       |
 6045|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6046|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6047|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6048|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6049|       |		}
 6050|       |
 6051|       |		/* user has wrong or no required pairing code */
 6052|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6053|       |			LOG_FUNC_RETURN(card->ctx, r);
 6054|       |
 6055|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6056|       |	}
 6057|       |#endif /* ENABLE_PIV_SM */
 6058|       |
 6059|       |	/*
 6060|       |	 * 800-73-3 cards may have a history object
 6061|       |	 * We want to process it now as this has information on what
 6062|       |	 * keys and certs. "piv like" cards may or may not have history
 6063|       |	 */
 6064|    651|	piv_process_history(card);
 6065|       |
 6066|    651|	priv->pstate = PIV_STATE_NORMAL;
 6067|    651|	sc_unlock(card);
 6068|    651|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    651|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    651|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    651|	int _ret = r; \
  |  |  |  |  155|    651|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 651, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    651|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 651]
  |  |  |  |  ------------------
  |  |  |  |  157|    651|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    651|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    651|	return _ret; \
  |  |  |  |  163|    651|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6069|    651|}
card-piv.c:piv_load_options:
 1678|    651|{
 1679|    651|	int r;
 1680|    651|	size_t i, j;
 1681|    651|	scconf_block **found_blocks, *block;
 1682|       |
 1683|       |#ifdef ENABLE_PIV_SM
 1684|       |	piv_private_data_t *priv = PIV_DATA(card);
 1685|       |	const char *option = NULL;
 1686|       |	int piv_pairing_code_found = 0;
 1687|       |	int piv_use_sm_found = 0;
 1688|       |
 1689|       |	/* pairing code is 8 decimal digits and is card specific */
 1690|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1691|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1692|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1693|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1694|       |			piv_pairing_code_found = 1;
 1695|       |		}
 1696|       |	}
 1697|       |
 1698|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1699|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1700|       |		if (!strcmp(option, "never")) {
 1701|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1702|       |			piv_use_sm_found = 1;
 1703|       |		} else if (!strcmp(option, "always")) {
 1704|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1705|       |			piv_use_sm_found = 1;
 1706|       |		} else {
 1707|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1708|       |		}
 1709|       |	}
 1710|       |#endif
 1711|       |
 1712|  1.30k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1712:14): [True: 651, False: 651]
  ------------------
 1713|    651|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1714|    651|				"card_driver", "PIV-II");
 1715|    651|		if (!found_blocks)
  ------------------
  |  Branch (1715:7): [True: 0, False: 651]
  ------------------
 1716|      0|			continue;
 1717|       |
 1718|    651|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1718:40): [True: 0, False: 651]
  ------------------
 1719|       |
 1720|       |#ifdef ENABLE_PIV_SM
 1721|       |			/*
 1722|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1723|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1724|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1725|       |			 * this security risk
 1726|       |			 * always - Use even for contact interface.
 1727|       |			 * PINS, crypto and reading of object will not show up in logs
 1728|       |			 * or over network.
 1729|       |			 */
 1730|       |
 1731|       |			if (piv_use_sm_found == 0) {
 1732|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1733|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1734|       |				if (!strcmp(option, "default")) {
 1735|       |					/* no new flags */
 1736|       |				} else if (!strcmp(option, "never")) {
 1737|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1738|       |				} else if (!strcmp(option, "always")) {
 1739|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1740|       |				} else {
 1741|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1742|       |				}
 1743|       |			}
 1744|       |
 1745|       |			/* This is really a card specific value and should not be in the conf file */
 1746|       |			if (piv_pairing_code_found == 0) {
 1747|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1748|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1749|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1750|       |				}
 1751|       |			}
 1752|       |#endif
 1753|      0|		}
 1754|    651|		free(found_blocks);
 1755|    651|	}
 1756|    651|	r = SC_SUCCESS;
  ------------------
  |  |   28|    651|#define SC_SUCCESS				0
  ------------------
 1757|    651|	return r;
 1758|    651|}
card-piv.c:piv_process_history:
 5115|    651|{
 5116|    651|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    651|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5117|    651|	int r;
 5118|    651|	int i, tmplen, tmplen2, tmplen3;
 5119|    651|	int enumtag;
 5120|    651|	u8 *rbuf = NULL;
 5121|    651|	size_t rbuflen = 0;
 5122|    651|	const u8 *body;
 5123|    651|	size_t bodylen;
 5124|    651|	const u8 *num;
 5125|    651|	size_t numlen;
 5126|    651|	const u8 *url = NULL;
 5127|    651|	size_t urllen;
 5128|    651|	u8 *ocfhfbuf = NULL;
 5129|    651|	unsigned int cla_out, tag_out;
 5130|    651|	size_t ocfhflen;
 5131|    651|	const u8 *seq;
 5132|    651|	const u8 *seqtag;
 5133|    651|	size_t seqlen;
 5134|    651|	const u8 *keyref;
 5135|    651|	size_t keyreflen;
 5136|    651|	const u8 *cert;
 5137|    651|	size_t certlen;
 5138|    651|	size_t certobjlen, i2;
 5139|    651|	u8 *certobj;
 5140|    651|	u8 *cp;
 5141|       |
 5142|    651|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    651|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    651|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    651|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 651]
  |  |  ------------------
  ------------------
 5143|       |
 5144|    651|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5145|    651|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    651|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5145:6): [True: 86, False: 565]
  ------------------
 5146|     86|		r = 0; /* OK if not found */
 5147|    651|	if (r <= 0) {
  ------------------
  |  Branch (5147:6): [True: 483, False: 168]
  ------------------
 5148|    483|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|    483|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5149|    483|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5150|    483|	}
 5151|       |
 5152|       |	/* the object is now cached, see what we have */
 5153|    168|	if (rbuflen != 0) {
  ------------------
  |  Branch (5153:6): [True: 168, False: 0]
  ------------------
 5154|    168|		body = rbuf;
 5155|    168|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    336|#define SC_SUCCESS				0
  ------------------
  |  Branch (5155:7): [True: 0, False: 168]
  ------------------
 5156|    168|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5156:5): [True: 0, False: 168]
  ------------------
 5157|      0|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5158|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5159|      0|			goto err;
 5160|      0|		}
 5161|       |
 5162|    168|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5162:7): [True: 168, False: 0]
  |  Branch (5162:23): [True: 166, False: 2]
  ------------------
 5163|    166|			numlen = 0;
 5164|    166|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5165|    166|			if (num) {
  ------------------
  |  Branch (5165:8): [True: 66, False: 100]
  ------------------
 5166|     66|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5166:9): [True: 1, False: 65]
  |  Branch (5166:24): [True: 1, False: 64]
  ------------------
 5167|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5168|      2|					goto err;
 5169|      2|				}
 5170|       |
 5171|     64|				priv->keysWithOnCardCerts = *num;
 5172|     64|			}
 5173|       |
 5174|    164|			numlen = 0;
 5175|    164|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5176|    164|			if (num) {
  ------------------
  |  Branch (5176:8): [True: 6, False: 158]
  ------------------
 5177|      6|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5177:9): [True: 1, False: 5]
  |  Branch (5177:24): [True: 1, False: 4]
  ------------------
 5178|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5179|      2|					goto err;
 5180|      2|				}
 5181|       |
 5182|      4|				priv->keysWithOffCardCerts = *num;
 5183|      4|			}
 5184|       |
 5185|    162|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5186|    162|			if (url) {
  ------------------
  |  Branch (5186:8): [True: 85, False: 77]
  ------------------
 5187|     85|				if (urllen > 118) {
  ------------------
  |  Branch (5187:9): [True: 1, False: 84]
  ------------------
 5188|      1|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5189|      1|					goto err;
 5190|      1|				}
 5191|     84|				priv->offCardCertURL = calloc(1, urllen + 1);
 5192|     84|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5192:9): [True: 0, False: 84]
  ------------------
 5193|     84|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5194|     84|				memcpy(priv->offCardCertURL, url, urllen);
 5195|     84|			}
 5196|    162|		} else {
 5197|      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__
  |  |  ------------------
  ------------------
 5198|      2|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 5199|      2|			goto err;
 5200|      2|		}
 5201|    168|	}
 5202|    161|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   71|    322|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 84, False: 77]
  |  |  ------------------
  ------------------
 5203|    161|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5204|    161|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5205|       |
 5206|       |	/* now mark what objects are on the card */
 5207|  1.22k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5207:14): [True: 1.06k, False: 161]
  ------------------
 5208|  1.06k|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|  1.22k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5209|       |
 5210|       |	/*
 5211|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5212|       |	 * we will read in and add the certs to the cache as listed on
 5213|       |	 * the card. some of the certs may be on the card as well.
 5214|       |	 *
 5215|       |	 * Get file name from url. verify that the filename is valid
 5216|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5217|       |	 * in the directory used for the  PKCS15 cache
 5218|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5219|       |	 */
 5220|       |
 5221|    161|	r = 0;
 5222|    161|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5222:6): [True: 84, False: 77]
  ------------------
 5223|     84|		char *fp;
 5224|     84|		char filename[PATH_MAX];
 5225|       |
 5226|     84|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5226:7): [True: 67, False: 17]
  ------------------
 5227|     67|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     67|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5228|     67|			goto err;
 5229|     67|		}
 5230|       |		/* find the last /  so we have the filename part */
 5231|     17|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5232|     17|		if (fp == NULL) {
  ------------------
  |  Branch (5232:7): [True: 3, False: 14]
  ------------------
 5233|      3|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5234|      3|			goto err;
 5235|      3|		}
 5236|     14|		fp++;
 5237|     14|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5237:7): [True: 7, False: 7]
  ------------------
 5238|      7|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      7|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5239|      7|			goto err;
 5240|      7|		}
 5241|    116|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5241:15): [True: 115, False: 1]
  ------------------
 5242|    115|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5242:8): [True: 6, False: 109]
  ------------------
 5243|      6|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5244|      6|				goto err;
 5245|      6|			}
 5246|    115|		}
 5247|       |
 5248|       |		/* Use the same directory as used for other OpenSC cached items */
 5249|      1|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5250|      1|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (5250:7): [True: 0, False: 1]
  ------------------
 5251|      0|			goto err;
 5252|       |#ifdef _WIN32
 5253|       |		strlcat(filename, "\\", PATH_MAX);
 5254|       |#else
 5255|      1|		strlcat(filename, "/", PATH_MAX);
 5256|      1|#endif
 5257|      1|		strlcat(filename, fp, PATH_MAX);
 5258|       |
 5259|      1|		r = piv_read_obj_from_file(card, filename,
 5260|      1|				&ocfhfbuf, &ocfhflen);
 5261|      1|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5261:7): [True: 1, False: 0]
  ------------------
 5262|      1|			r = 0;
 5263|      1|			goto err;
 5264|      1|		}
 5265|       |
 5266|       |		/*
 5267|       |		 * Its a seq of seq of a key ref and cert
 5268|       |		 */
 5269|       |
 5270|      0|		body = ocfhfbuf;
 5271|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5271:7): [True: 0, False: 0]
  ------------------
 5272|      0|				body == NULL ||
  ------------------
  |  Branch (5272:5): [True: 0, False: 0]
  ------------------
 5273|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5273:5): [True: 0, False: 0]
  ------------------
 5274|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5274:5): [True: 0, False: 0]
  ------------------
 5275|      0|			sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5276|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5277|      0|			goto err;
 5278|      0|		}
 5279|      0|		seq = body;
 5280|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5280:10): [True: 0, False: 0]
  ------------------
 5281|      0|			seqtag = seq;
 5282|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5282:8): [True: 0, False: 0]
  ------------------
 5283|      0|					seq == 0 ||
  ------------------
  |  Branch (5283:6): [True: 0, False: 0]
  ------------------
 5284|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5284:6): [True: 0, False: 0]
  ------------------
 5285|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5285:6): [True: 0, False: 0]
  ------------------
 5286|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5287|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5288|      0|				goto err;
 5289|      0|			}
 5290|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5291|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5291:8): [True: 0, False: 0]
  |  Branch (5291:19): [True: 0, False: 0]
  ------------------
 5292|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5292:7): [True: 0, False: 0]
  |  Branch (5292:25): [True: 0, False: 0]
  ------------------
 5293|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5294|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5295|      0|				goto err;
 5296|      0|			}
 5297|      0|			cert = keyref + keyreflen;
 5298|      0|			certlen = seqlen - (cert - seq);
 5299|       |
 5300|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5301|       |			/* now add the cert like another object */
 5302|       |
 5303|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5303:8): [True: 0, False: 0]
  ------------------
 5304|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5304:6): [True: 0, False: 0]
  ------------------
 5305|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5305:6): [True: 0, False: 0]
  ------------------
 5306|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5307|      0|				goto err;
 5308|      0|			}
 5309|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5310|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5311|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5311:8): [True: 0, False: 0]
  ------------------
 5312|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5313|      0|				goto err;
 5314|      0|			}
 5315|       |
 5316|      0|			certobjlen = tmplen;
 5317|      0|			certobj = malloc(certobjlen);
 5318|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5318:8): [True: 0, False: 0]
  ------------------
 5319|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5320|      0|				goto err;
 5321|      0|			}
 5322|      0|			cp = certobj;
 5323|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5323:8): [True: 0, False: 0]
  ------------------
 5324|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5324:6): [True: 0, False: 0]
  ------------------
 5325|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5325:6): [True: 0, False: 0]
  ------------------
 5326|      0|				goto err;
 5327|      0|			}
 5328|      0|			*cp++ = 0x00;
 5329|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5330|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5330:8): [True: 0, False: 0]
  ------------------
 5331|      0|				goto err;
 5332|      0|			}
 5333|       |
 5334|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5335|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5336|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5337|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5338|       |
 5339|      0|			r = piv_cache_internal_data(card, enumtag);
 5340|      0|			sc_log(card->ctx, "got internal r=%d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5341|       |
 5342|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5343|      0|					"Added from off card file #%d %p:%" SC_FORMAT_LEN_SIZE_T "u 0x%02X",
 5344|      0|					enumtag,
 5345|      0|					priv->obj_cache[enumtag].obj_data,
 5346|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5347|       |
 5348|      0|			bodylen -= (seqlen + seq - seqtag);
 5349|      0|			seq += seqlen;
 5350|      0|		}
 5351|      0|	}
 5352|    651|err:
 5353|    651|	if (ocfhfbuf)
  ------------------
  |  Branch (5353:6): [True: 0, False: 651]
  ------------------
 5354|      0|		free(ocfhfbuf);
 5355|    651|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    651|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    651|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    651|	int _ret = r; \
  |  |  |  |  155|    651|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 651, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    651|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    485|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 485, False: 166]
  |  |  |  |  ------------------
  |  |  |  |  157|    651|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    651|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    651|	return _ret; \
  |  |  |  |  163|    651|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5356|    651|}
card-piv.c:piv_read_obj_from_file:
 3018|      1|{
 3019|      1|	int r;
 3020|      1|	int r_tag;
 3021|      1|	int f = -1;
 3022|      1|	size_t len;
 3023|      1|	u8 tagbuf[16];
 3024|      1|	size_t rbuflen;
 3025|      1|	const u8 *body;
 3026|      1|	unsigned int cla_out, tag_out;
 3027|      1|	size_t bodylen;
 3028|       |
 3029|      1|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      1|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      1|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      1|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1]
  |  |  ------------------
  ------------------
 3030|       |
 3031|      1|	*buf = NULL;
 3032|      1|	*buf_len = 0;
 3033|      1|	f = open(filename, O_RDONLY);
 3034|      1|	if (f < 0) {
  ------------------
  |  Branch (3034:6): [True: 1, False: 0]
  ------------------
 3035|      1|		sc_log(card->ctx, "Unable to load PIV off card file: \"%s\"", filename);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3036|      1|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3037|      1|		goto err;
 3038|      1|	}
 3039|      0|	len = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
 3040|      0|	if (len < 2 || len > sizeof(tagbuf)) {
  ------------------
  |  Branch (3040:6): [True: 0, False: 0]
  |  Branch (3040:17): [True: 0, False: 0]
  ------------------
 3041|      0|		sc_log(card->ctx, "Problem with \"%s\"", filename);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3042|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 3043|      0|		goto err;
 3044|      0|	}
 3045|      0|	body = tagbuf;
 3046|       |	/* accept any tag for now, just get length */
 3047|      0|	r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 3048|      0|	if ((r_tag != SC_SUCCESS && r_tag != SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              	if ((r_tag != SC_SUCCESS && r_tag != SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|      0|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (3048:7): [True: 0, False: 0]
  |  Branch (3048:30): [True: 0, False: 0]
  ------------------
 3049|      0|			body == NULL) {
  ------------------
  |  Branch (3049:4): [True: 0, False: 0]
  ------------------
 3050|      0|		sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3051|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3052|      0|		goto err;
 3053|      0|	}
 3054|      0|	rbuflen = body - tagbuf + bodylen;
 3055|      0|	*buf = malloc(rbuflen);
 3056|      0|	if (!*buf) {
  ------------------
  |  Branch (3056:6): [True: 0, False: 0]
  ------------------
 3057|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3058|      0|		goto err;
 3059|      0|	}
 3060|      0|	memcpy(*buf, tagbuf, MIN(len, rbuflen)); /* copy first or only part */
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 3061|       |	/* read rest of file */
 3062|      0|	if (rbuflen > len + sizeof(tagbuf)) {
  ------------------
  |  Branch (3062:6): [True: 0, False: 0]
  ------------------
 3063|      0|		len = read(f, *buf + sizeof(tagbuf), rbuflen - sizeof(tagbuf)); /* read rest */
 3064|      0|		if (len != rbuflen - sizeof(tagbuf)) {
  ------------------
  |  Branch (3064:7): [True: 0, False: 0]
  ------------------
 3065|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 3066|      0|			free(*buf);
 3067|      0|			*buf = NULL;
 3068|      0|			goto err;
 3069|      0|		}
 3070|      0|	}
 3071|      0|	r = (int)rbuflen;
 3072|      0|	*buf_len = rbuflen;
 3073|      1|err:
 3074|      1|	if (f >= 0)
  ------------------
  |  Branch (3074:6): [True: 0, False: 1]
  ------------------
 3075|      0|		close(f);
 3076|      1|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3077|      1|}
card-piv.c:piv_cache_internal_data:
 3280|  1.35k|{
 3281|  1.35k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  1.35k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3282|  1.35k|	const u8 *tag;
 3283|  1.35k|	const u8 *body;
 3284|  1.35k|	size_t taglen;
 3285|  1.35k|	size_t bodylen;
 3286|  1.35k|	int compressed = 0;
 3287|  1.35k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.35k|#define SC_SUCCESS				0
  ------------------
 3288|       |#ifdef ENABLE_PIV_SM
 3289|       |	u8 *cvc_start = NULL;
 3290|       |	size_t cvc_len = 0;
 3291|       |#endif
 3292|       |
 3293|       |	/* if already cached */
 3294|  1.35k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3294:6): [True: 635, False: 719]
  |  Branch (3294:52): [True: 635, False: 0]
  ------------------
 3295|    635|		sc_log(card->ctx,
  ------------------
  |  |   71|    635|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3296|    635|				"#%d found internal %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3297|    635|				enumtag,
 3298|    635|				priv->obj_cache[enumtag].internal_obj_data,
 3299|    635|				priv->obj_cache[enumtag].internal_obj_len);
 3300|    635|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    635|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    635|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    635|	int _ret = r; \
  |  |  |  |  155|    635|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 635, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    635|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 635]
  |  |  |  |  ------------------
  |  |  |  |  157|    635|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    635|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    635|	return _ret; \
  |  |  |  |  163|    635|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3301|    635|	}
 3302|       |
 3303|    719|	body = sc_asn1_find_tag(card->ctx,
 3304|    719|			priv->obj_cache[enumtag].obj_data,
 3305|    719|			priv->obj_cache[enumtag].obj_len,
 3306|    719|			0x53, &bodylen);
 3307|       |
 3308|    719|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3308:6): [True: 0, False: 719]
  |  Branch (3308:22): [True: 0, False: 719]
  ------------------
 3309|    719|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3310|       |
 3311|       |	/* get the certificate out */
 3312|    719|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  636|    719|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3312:6): [True: 719, False: 0]
  ------------------
 3313|       |
 3314|    719|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3315|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3316|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3317|    719|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3317:7): [True: 415, False: 304]
  |  Branch (3317:14): [True: 401, False: 14]
  |  Branch (3317:29): [True: 16, False: 385]
  |  Branch (3317:48): [True: 21, False: 364]
  ------------------
 3318|     37|			compressed = 1;
 3319|       |
 3320|       |#ifdef ENABLE_PIV_SM
 3321|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3322|       |#endif
 3323|       |
 3324|    719|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3325|    719|		if (tag == NULL)
  ------------------
  |  Branch (3325:7): [True: 73, False: 646]
  ------------------
 3326|    719|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  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|     73|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 73, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3327|       |
 3328|    646|		if (taglen == 0)
  ------------------
  |  Branch (3328:7): [True: 11, False: 635]
  ------------------
 3329|    646|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3330|       |
 3331|    635|		if (compressed) {
  ------------------
  |  Branch (3331:7): [True: 35, False: 600]
  ------------------
 3332|     35|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  149|     35|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3333|     35|		}
 3334|       |		/* internal certificate remains compressed */
 3335|    635|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3335:7): [True: 0, False: 635]
  ------------------
 3336|    635|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3337|       |
 3338|    635|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3339|    635|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3340|       |
 3341|       |#ifdef ENABLE_PIV_SM
 3342|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3343|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3344|       |			/* cvc if present should be at cvc_start.
 3345|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3346|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3347|       |			 * as the size of (L) depends on the length of value
 3348|       |			 */
 3349|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3350|       |					cvc_start &&
 3351|       |					cvc_start < tag &&
 3352|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3353|       |				cvc_len = tag - cvc_start + taglen;
 3354|       |				/* decode the intermediate CVC */
 3355|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3356|       |				if (r < 0) {
 3357|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3358|       |				}
 3359|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3360|       |			}
 3361|       |		}
 3362|       |#endif /* ENABLE_PIV_SM */
 3363|       |
 3364|       |		/* convert pub key to internal */
 3365|    635|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3365:13): [True: 0, False: 0]
  ------------------
 3366|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3367|      0|		if (tag == NULL)
  ------------------
  |  Branch (3367:7): [True: 0, False: 0]
  ------------------
 3368|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3369|       |
 3370|      0|		if (taglen == 0)
  ------------------
  |  Branch (3370:7): [True: 0, False: 0]
  ------------------
 3371|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3372|       |
 3373|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3373:7): [True: 0, False: 0]
  ------------------
 3374|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3375|       |
 3376|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3377|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3378|      0|	} else {
 3379|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3380|      0|	}
 3381|       |
 3382|    635|	sc_log(card->ctx, "added #%d internal %p:%" SC_FORMAT_LEN_SIZE_T "u",
  ------------------
  |  |   71|    635|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3383|    635|			enumtag,
 3384|    635|			priv->obj_cache[enumtag].internal_obj_data,
 3385|    635|			priv->obj_cache[enumtag].internal_obj_len);
 3386|       |
 3387|    635|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    635|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    635|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    635|	int _ret = r; \
  |  |  |  |  155|    635|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 635, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    635|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 635]
  |  |  |  |  ------------------
  |  |  |  |  157|    635|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    635|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    635|	return _ret; \
  |  |  |  |  163|    635|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3388|    635|}
card-piv.c:piv_finish:
 5379|  9.70k|{
 5380|  9.70k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  9.70k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5381|  9.70k|	int i;
 5382|       |
 5383|  9.70k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.70k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.70k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.70k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.70k]
  |  |  ------------------
  ------------------
 5384|  9.70k|	if (priv) {
  ------------------
  |  Branch (5384:6): [True: 5.17k, False: 4.52k]
  ------------------
 5385|  5.17k|		if (priv->context_specific) {
  ------------------
  |  Branch (5385:7): [True: 0, False: 5.17k]
  ------------------
 5386|      0|			sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5387|      0|			priv->context_specific = 0;
 5388|      0|			sc_unlock(card);
 5389|      0|		}
 5390|  5.17k|		free(priv->aid_der.value);
 5391|  5.17k|		free(priv->al_label);
 5392|  5.17k|		if (priv->w_buf)
  ------------------
  |  Branch (5392:7): [True: 0, False: 5.17k]
  ------------------
 5393|      0|			free(priv->w_buf);
 5394|  5.17k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5394:7): [True: 84, False: 5.09k]
  ------------------
 5395|     84|			free(priv->offCardCertURL);
 5396|   315k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5396:15): [True: 310k, False: 5.17k]
  ------------------
 5397|   310k|			piv_obj_cache_free_entry(card, i, 0);
 5398|   310k|		}
 5399|       |#ifdef ENABLE_PIV_SM
 5400|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5401|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5402|       |		piv_clear_sm_session(&priv->sm_session);
 5403|       |#endif /* ENABLE_PIV_SM */
 5404|       |
 5405|  5.17k|		free(priv);
 5406|       |		card->drv_data = NULL; /* priv */
 5407|  5.17k|	}
 5408|  9.70k|	return 0;
 5409|  9.70k|}
card-piv.c:piv_select_file:
 4811|  5.88k|{
 4812|  5.88k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  5.88k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4813|  5.88k|	int r;
 4814|  5.88k|	int i;
 4815|  5.88k|	const u8 *path;
 4816|  5.88k|	size_t pathlen;
 4817|  5.88k|	sc_file_t *file = NULL;
 4818|  5.88k|	u8 *rbuf = NULL;
 4819|  5.88k|	size_t rbuflen = 0;
 4820|       |
 4821|  5.88k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.88k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.88k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.88k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.88k]
  |  |  ------------------
  ------------------
 4822|       |
 4823|  5.88k|	path = in_path->value;
 4824|  5.88k|	pathlen = in_path->len;
 4825|       |
 4826|       |	/* only support single EF in current application */
 4827|       |	/*
 4828|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 4829|       |	 * select_file and read_binary. The emulation adds path emulated structures
 4830|       |	 * so piv_select_file will find it.
 4831|       |	 * there is no dir. Only direct access to emulated files
 4832|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 4833|       |	 */
 4834|       |
 4835|  5.88k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (4835:6): [True: 1.53k, False: 4.34k]
  ------------------
 4836|  1.53k|		if (pathlen > 2) {
  ------------------
  |  Branch (4836:7): [True: 1.53k, False: 0]
  ------------------
 4837|  1.53k|			path += 2;
 4838|  1.53k|			pathlen -= 2;
 4839|  1.53k|		}
 4840|  1.53k|	}
 4841|       |
 4842|  5.88k|	i = piv_find_obj_by_containerid(card, path);
 4843|       |
 4844|  5.88k|	if (i < 0)
  ------------------
  |  Branch (4844:6): [True: 1.55k, False: 4.32k]
  ------------------
 4845|  5.88k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4846|       |
 4847|       |	/*
 4848|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 4849|       |	 * with cece added to path to request only the cert from the cert obj
 4850|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 4851|       |	 */
 4852|  4.32k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (4852:28): [True: 4.32k, False: 0]
  |  Branch (4852:44): [True: 4.32k, False: 0]
  |  Branch (4852:63): [True: 4.32k, False: 0]
  ------------------
 4853|       |
 4854|  4.32k|	priv->selected_obj = i;
 4855|  4.32k|	priv->rwb_state = -1;
 4856|       |
 4857|       |	/* make it look like the file was found. */
 4858|       |	/* We don't want to read it now  unless we need the length */
 4859|       |
 4860|  4.32k|	if (file_out) {
  ------------------
  |  Branch (4860:6): [True: 4.32k, False: 0]
  ------------------
 4861|       |		/* we need to read it now, to get length into cache */
 4862|  4.32k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 4863|       |
 4864|  4.32k|		if (r < 0)
  ------------------
  |  Branch (4864:7): [True: 3.60k, False: 719]
  ------------------
 4865|  4.32k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  3.60k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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.60k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.60k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4866|       |
 4867|       |		/* get the cert or the pub key out and into the cache too */
 4868|    719|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (4868:7): [True: 719, False: 0]
  |  Branch (4868:33): [True: 0, False: 0]
  ------------------
 4869|    719|			r = piv_cache_internal_data(card, i);
 4870|    719|			if (r < 0)
  ------------------
  |  Branch (4870:8): [True: 84, False: 635]
  ------------------
 4871|    719|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     84|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     84|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     84|	int _ret = r; \
  |  |  |  |  155|     84|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 84, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     84|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     84|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 84, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     84|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     84|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     84|	return _ret; \
  |  |  |  |  163|     84|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4872|    719|		}
 4873|       |
 4874|    635|		file = sc_file_new();
 4875|    635|		if (file == NULL)
  ------------------
  |  Branch (4875:7): [True: 0, False: 635]
  ------------------
 4876|    635|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4877|       |
 4878|    635|		file->path = *in_path;
 4879|       |		/* this could be like the FCI */
 4880|    635|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    635|#define SC_FILE_TYPE_DF			0x04
  ------------------
 4881|    635|		file->shareable = 0;
 4882|    635|		file->ef_structure = 0;
 4883|    635|		if (priv->return_only_cert)
  ------------------
  |  Branch (4883:7): [True: 635, False: 0]
  ------------------
 4884|    635|			file->size = priv->obj_cache[i].internal_obj_len;
 4885|      0|		else
 4886|      0|			file->size = priv->obj_cache[i].obj_len;
 4887|       |
 4888|    635|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 4889|       |
 4890|    635|		*file_out = file;
 4891|    635|	}
 4892|       |
 4893|    635|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    635|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    635|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    635|	int _ret = r; \
  |  |  |  |  155|    635|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 635, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    635|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 635]
  |  |  |  |  ------------------
  |  |  |  |  157|    635|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    635|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    635|	return _ret; \
  |  |  |  |  163|    635|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4894|    635|}
card-piv.c:piv_find_obj_by_containerid:
 1762|  46.2k|{
 1763|  46.2k|	int i;
 1764|       |
 1765|  46.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  46.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  46.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  46.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  46.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 46.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1766|  46.2k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1767|       |
 1768|   967k|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1768:14): [True: 965k, False: 2.20k]
  ------------------
 1769|   965k|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1769:7): [True: 397k, False: 568k]
  |  Branch (1769:50): [True: 44.0k, False: 353k]
  ------------------
 1770|   965k|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  44.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  44.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  44.0k|	int _ret = r; \
  |  |  |  |  155|  44.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 651, False: 43.3k]
  |  |  |  |  ------------------
  |  |  |  |  156|    651|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 651]
  |  |  |  |  ------------------
  |  |  |  |  157|    651|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  43.3k|	} else { \
  |  |  |  |  159|  43.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  43.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  43.3k|	} \
  |  |  |  |  162|  44.0k|	return _ret; \
  |  |  |  |  163|  44.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1771|   965k|	}
 1772|       |
 1773|  2.20k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  2.20k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.20k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.20k|	int _ret = r; \
  |  |  |  |  155|  2.20k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.20k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.20k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.20k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.20k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.20k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.20k|	return _ret; \
  |  |  |  |  163|  2.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1774|  2.20k|}
card-piv.c:piv_read_binary:
 3397|    839|{
 3398|    839|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    839|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3399|    839|	int enumtag;
 3400|    839|	int r;
 3401|    839|	u8 *rbuf = NULL;
 3402|    839|	size_t rbuflen = 0;
 3403|    839|	const u8 *body;
 3404|    839|	size_t bodylen;
 3405|       |
 3406|    839|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    839|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    839|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    839|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 839]
  |  |  ------------------
  ------------------
 3407|    839|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3407:6): [True: 0, False: 839]
  ------------------
 3408|    839|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3409|    839|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3410|       |
 3411|    839|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3411:6): [True: 635, False: 204]
  ------------------
 3412|    635|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3413|       |
 3414|    635|		if (r >= 0) {
  ------------------
  |  Branch (3414:7): [True: 635, False: 0]
  ------------------
 3415|       |			/* an object with no data will be considered not found */
 3416|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3417|    635|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3417:8): [True: 0, False: 635]
  |  Branch (3417:17): [True: 0, False: 635]
  |  Branch (3417:37): [True: 635, False: 0]
  |  Branch (3417:65): [True: 0, False: 635]
  ------------------
 3418|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3419|      0|				goto err;
 3420|      0|			}
 3421|       |
 3422|    635|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3423|    635|			if (body == NULL) {
  ------------------
  |  Branch (3423:8): [True: 0, False: 635]
  ------------------
 3424|       |				/* if missing, assume its the body */
 3425|       |				/* DEE bug in the beta card */
 3426|      0|				sc_log(card->ctx, " ***** tag 0x53 MISSING");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3427|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3428|      0|				goto err;
 3429|      0|			}
 3430|    635|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3430:8): [True: 0, False: 635]
  ------------------
 3431|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3432|      0|						" ***** tag length > then data: %" SC_FORMAT_LEN_SIZE_T "u>%" SC_FORMAT_LEN_PTRDIFF_T "u+%" SC_FORMAT_LEN_SIZE_T "u",
 3433|      0|						bodylen, body - rbuf, rbuflen);
 3434|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3435|      0|				goto err;
 3436|      0|			}
 3437|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3438|    635|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3438:8): [True: 635, False: 0]
  |  Branch (3438:34): [True: 0, False: 0]
  ------------------
 3439|    635|				r = piv_cache_internal_data(card, enumtag);
 3440|    635|				if (r < 0)
  ------------------
  |  Branch (3440:9): [True: 0, False: 635]
  ------------------
 3441|      0|					goto err;
 3442|    635|			}
 3443|    635|		}
 3444|    635|		priv->rwb_state = 0;
 3445|    635|	}
 3446|       |
 3447|    839|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3447:6): [True: 839, False: 0]
  |  Branch (3447:32): [True: 0, False: 0]
  ------------------
 3448|    839|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3449|    839|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3450|    839|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  149|    839|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3450:7): [True: 35, False: 804]
  |  Branch (3450:70): [True: 35, False: 0]
  ------------------
 3451|     35|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     35|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3452|     35|		}
 3453|    839|	} else {
 3454|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3455|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3456|      0|	}
 3457|       |	/* rbuf rbuflen has pointer and length to cached data */
 3458|       |
 3459|    839|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3459:6): [True: 0, False: 839]
  ------------------
 3460|      0|		count = rbuflen - idx;
 3461|    839|	if (count <= 0) {
  ------------------
  |  Branch (3461:6): [True: 0, False: 839]
  ------------------
 3462|      0|		r = 0;
 3463|      0|		priv->rwb_state = 1;
 3464|    839|	} else {
 3465|    839|		memcpy(buf, rbuf + idx, count);
 3466|    839|		r = (int)count;
 3467|    839|	}
 3468|       |
 3469|    839|err:
 3470|    839|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    839|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    839|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    839|	int _ret = r; \
  |  |  |  |  155|    839|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 839]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    839|	} else { \
  |  |  |  |  159|    839|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    839|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    839|	} \
  |  |  |  |  162|    839|	return _ret; \
  |  |  |  |  163|    839|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3471|    839|}
card-piv.c:piv_check_sw:
 6073|  12.7k|{
 6074|  12.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6075|       |
 6076|  12.7k|	int r;
 6077|       |#ifdef ENABLE_PIV_SM
 6078|       |	int i;
 6079|       |#endif
 6080|  12.7k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  12.7k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6081|       |
 6082|  12.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  12.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  12.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  12.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12.7k]
  |  |  ------------------
  ------------------
 6083|       |
 6084|       |	/* may be called before piv_init has allocated priv */
 6085|  12.7k|	if (priv) {
  ------------------
  |  Branch (6085:6): [True: 12.7k, False: 0]
  ------------------
 6086|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6087|       |
 6088|  12.7k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6088:7): [True: 0, False: 12.7k]
  ------------------
 6089|      0|			priv->pin_cmd_verify_sw1 = sw1;
 6090|      0|			priv->pin_cmd_verify_sw2 = sw2;
 6091|  12.7k|		} else {
 6092|       |			/* a command has completed and it is not verify
 6093|       |			 * If we are in a context_specific sequence, unlock
 6094|       |			 * This just decrements the extra lock count
 6095|       |			 */
 6096|  12.7k|			if (priv->context_specific) {
  ------------------
  |  Branch (6096:8): [True: 0, False: 12.7k]
  ------------------
 6097|      0|				sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6098|      0|				priv->context_specific = 0;
 6099|      0|				sc_unlock(card);
 6100|      0|			}
 6101|  12.7k|		}
 6102|       |
 6103|  12.7k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  576|  12.7k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6103:7): [True: 1.48k, False: 11.2k]
  ------------------
 6104|       |
 6105|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6106|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6107|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6108|       |			 */
 6109|  1.48k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6109:8): [True: 0, False: 1.48k]
  |  Branch (6109:32): [True: 0, False: 0]
  ------------------
 6110|      0|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6111|      0|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6111:9): [True: 0, False: 0]
  ------------------
 6112|      0|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (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__
  |  |  ------------------
  ------------------
 6113|      0|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6114|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6115|      0|				}
 6116|      0|			}
 6117|  1.48k|		}
 6118|  12.7k|	}
 6119|       |#ifdef ENABLE_PIV_SM
 6120|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6121|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6122|       |	/* we stashed the sw1 and sw2 above for verify */
 6123|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6124|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6125|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6126|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6127|       |			return piv_sm_errors[i].errorno;
 6128|       |		}
 6129|       |	}
 6130|       |#endif
 6131|  12.7k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6132|  12.7k|	return r;
 6133|  12.7k|}
card-piv.c:piv_card_ctl:
 4487|  41.6k|{
 4488|  41.6k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  41.6k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4489|  41.6k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4490|       |
 4491|  41.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  41.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  41.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  41.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  41.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 41.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4492|       |
 4493|  41.6k|	if (priv == NULL) {
  ------------------
  |  Branch (4493:6): [True: 0, False: 41.6k]
  ------------------
 4494|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4495|      0|	}
 4496|  41.6k|	switch (cmd) {
  ------------------
  |  Branch (4496:10): [True: 41.6k, False: 0]
  ------------------
 4497|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4497:2): [True: 0, False: 41.6k]
  ------------------
 4498|      0|		opts = (u8 *)ptr;
 4499|      0|		switch (*opts) {
  ------------------
  |  Branch (4499:11): [True: 0, False: 0]
  ------------------
 4500|      0|		case 'A':
  ------------------
  |  Branch (4500:3): [True: 0, False: 0]
  ------------------
 4501|      0|			return piv_general_external_authenticate(card,
 4502|      0|					*(opts + 1), *(opts + 2));
 4503|      0|			break;
 4504|      0|		case 'M':
  ------------------
  |  Branch (4504:3): [True: 0, False: 0]
  ------------------
 4505|      0|			return piv_general_mutual_authenticate(card,
 4506|      0|					*(opts + 1), *(opts + 2));
 4507|      0|			break;
 4508|      0|		}
 4509|      0|		break;
 4510|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4510:2): [True: 0, False: 41.6k]
  ------------------
 4511|      0|		return piv_generate_key(card,
 4512|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4513|      0|		break;
 4514|    651|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4514:2): [True: 651, False: 41.0k]
  ------------------
 4515|    651|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4516|      0|		break;
 4517|    651|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4517:2): [True: 651, False: 41.0k]
  ------------------
 4518|    651|		return piv_get_pin_preference(card, ptr);
 4519|      0|		break;
 4520|  40.3k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4520:2): [True: 40.3k, False: 1.30k]
  ------------------
 4521|  40.3k|		return piv_is_object_present(card, ptr);
 4522|      0|		break;
 4523|  41.6k|	}
 4524|       |
 4525|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4526|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4366|    651|{
 4367|    651|	int r;
 4368|    651|	int i;
 4369|    651|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4370|    651|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4371|    651|	u8 *rbuf = NULL;
 4372|    651|	const u8 *body;
 4373|    651|	const u8 *fascn;
 4374|    651|	const u8 *guid;
 4375|    651|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4376|       |
 4377|    651|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    651|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    651|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    651|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 651]
  |  |  ------------------
  ------------------
 4378|    651|	if (card->serialnr.len) {
  ------------------
  |  Branch (4378:6): [True: 0, False: 651]
  ------------------
 4379|      0|		*serial = card->serialnr;
 4380|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4381|      0|	}
 4382|       |
 4383|       |	/*
 4384|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4385|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4386|       |	 * based on RFC 4122. If GUID present and not zero
 4387|       |	 * we will use the GUID as the serial number.
 4388|       |	 */
 4389|       |
 4390|    651|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4391|    651|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  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: 576, False: 75]
  |  |  |  |  ------------------
  |  |  |  |  169|    576|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    576|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    576|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    576|		return _ret; \
  |  |  |  |  172|    576|	} \
  |  |  |  |  173|    651|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 75]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4392|       |
 4393|     75|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     75|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4394|     75|	if (rbuflen != 0) {
  ------------------
  |  Branch (4394:6): [True: 75, False: 0]
  ------------------
 4395|     75|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4396|     75|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4396:7): [True: 75, False: 0]
  |  Branch (4396:23): [True: 65, False: 10]
  |  Branch (4396:39): [True: 65, False: 0]
  ------------------
 4397|     65|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4398|       |
 4399|     65|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4399:8): [True: 40, False: 25]
  |  Branch (4399:17): [True: 31, False: 9]
  ------------------
 4400|    806|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4400:17): [True: 775, False: 31]
  ------------------
 4401|    775|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4401:14): [True: 614, False: 161]
  |  Branch (4401:23): [True: 30, False: 131]
  ------------------
 4402|    775|				}
 4403|     31|			}
 4404|       |
 4405|     65|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4406|       |
 4407|     65|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4407:8): [True: 15, False: 50]
  |  Branch (4407:16): [True: 12, False: 3]
  ------------------
 4408|    204|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4408:17): [True: 192, False: 12]
  ------------------
 4409|    192|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4410|    192|				}
 4411|     12|			}
 4412|     65|			sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4413|     65|					"fascn=%p,fascnlen=%" SC_FORMAT_LEN_SIZE_T "u,guid=%p,guidlen=%" SC_FORMAT_LEN_SIZE_T "u,gbits=%2.2x",
 4414|     65|					fascn, fascnlen, guid, guidlen, gbits);
 4415|       |
 4416|     65|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4416:8): [True: 40, False: 25]
  |  Branch (4416:17): [True: 31, False: 9]
  |  Branch (4416:35): [True: 30, False: 1]
  ------------------
 4417|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4418|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4419|     30|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4419:11): [True: 11, False: 19]
  |  Branch (4419:20): [True: 4, False: 7]
  |  Branch (4419:40): [True: 3, False: 1]
  ------------------
 4420|     29|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4420:11): [True: 2, False: 1]
  |  Branch (4420:31): [True: 1, False: 1]
  ------------------
 4421|       |					/* fascnlen is 25 */
 4422|     29|					serial->len = fascnlen;
 4423|     29|					memcpy(serial->value, fascn, serial->len);
 4424|     29|					r = SC_SUCCESS;
  ------------------
  |  |   28|     29|#define SC_SUCCESS				0
  ------------------
 4425|     29|					gbits = 0; /* set to skip using guid below */
 4426|     29|				}
 4427|     30|			}
 4428|     65|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4428:8): [True: 15, False: 50]
  |  Branch (4428:16): [True: 12, False: 3]
  |  Branch (4428:33): [True: 2, False: 10]
  ------------------
 4429|      2|				serial->len = guidlen;
 4430|      2|				memcpy(serial->value, guid, serial->len);
 4431|      2|				r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 4432|      2|			}
 4433|     65|		}
 4434|     75|	}
 4435|       |
 4436|     75|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4436:6): [True: 45, False: 30]
  |  Branch (4436:20): [True: 44, False: 1]
  ------------------
 4437|     44|		serial->len = 16;
 4438|     44|		memset(serial->value, 0x00, serial->len);
 4439|     44|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     44|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4440|     44|	}
 4441|       |
 4442|     75|	card->serialnr = *serial;
 4443|     75|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     75|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     75|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     75|	int _ret = r; \
  |  |  |  |  155|     75|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 75, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     75|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     44|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 44, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4444|     75|}
card-piv.c:piv_get_pin_preference:
 4478|    651|{
 4479|    651|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    651|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4480|       |
 4481|    651|	*pin_ref = priv->pin_preference;
 4482|    651|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    651|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    651|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    651|	int _ret = r; \
  |  |  |  |  155|    651|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 651, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    651|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 651]
  |  |  |  |  ------------------
  |  |  |  |  157|    651|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    651|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    651|	return _ret; \
  |  |  |  |  163|    651|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4483|    651|}
card-piv.c:piv_is_object_present:
 4459|  40.3k|{
 4460|  40.3k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  40.3k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4461|  40.3k|	int r = 0;
 4462|  40.3k|	int enumtag;
 4463|       |
 4464|  40.3k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4465|  40.3k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  150|  39.7k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4465:6): [True: 39.7k, False: 651]
  |  Branch (4465:22): [True: 24.9k, False: 14.7k]
  ------------------
 4466|  24.9k|		r = 1;
 4467|       |
 4468|  40.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  40.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  40.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  40.3k|	int _ret = r; \
  |  |  |  |  155|  40.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.3k, False: 24.9k]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 15.3k]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  24.9k|	} else { \
  |  |  |  |  159|  24.9k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  24.9k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  24.9k|	} \
  |  |  |  |  162|  40.3k|	return _ret; \
  |  |  |  |  163|  40.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4469|  40.3k|}
card-piv.c:piv_card_reader_lock_obtained:
 6380|  6.48k|{
 6381|  6.48k|	int r = 0;
 6382|  6.48k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6383|  6.48k|	size_t templen = sizeof(temp);
 6384|  6.48k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  432|  6.48k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6385|       |
 6386|  6.48k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.48k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.48k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.48k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.48k]
  |  |  ------------------
  ------------------
 6387|       |
 6388|       |	/* We have a PCSC transaction and sc_lock */
 6389|  6.48k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6389:6): [True: 5.17k, False: 1.30k]
  |  Branch (6389:22): [True: 651, False: 651]
  ------------------
 6390|  5.83k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  11.6k|#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: 651, False: 5.17k]
  |  |  ------------------
  ------------------
 6391|  5.83k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6392|  5.83k|		r = 0; /* do nothing, piv_match will take care of it */
 6393|  5.83k|		goto err;
 6394|  5.83k|	}
 6395|       |
 6396|    651|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  381|    651|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6397|       |
 6398|       |	/* make sure our application is active */
 6399|       |
 6400|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6401|       |	/* If not try selecting AID */
 6402|       |
 6403|       |	/* but if card does not support DISCOVERY object we can not use it */
 6404|    651|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  582|    651|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6404:6): [True: 606, False: 45]
  ------------------
 6405|    606|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    606|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6406|    606|	} else {
 6407|     45|		r = piv_find_discovery(card);
 6408|       |#ifdef ENABLE_PIV_SM
 6409|       |		/*
 6410|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6411|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6412|       |		 * Discovery object can be read with contact or contactless
 6413|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6414|       |		 * sm.c will close the SM connectrion, and set defer
 6415|       |		 */
 6416|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6417|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6418|       |			piv_sm_open(card);
 6419|       |			r = piv_find_discovery(card);
 6420|       |		}
 6421|       |#endif /* ENABLE_PIV_SM */
 6422|     45|	}
 6423|       |
 6424|    651|	if (r < 0) {
  ------------------
  |  Branch (6424:6): [True: 639, False: 12]
  ------------------
 6425|    639|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  583|    639|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6425:7): [True: 0, False: 639]
  |  Branch (6425:24): [True: 609, False: 30]
  ------------------
 6426|    609|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6427|    609|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    609|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6428|    609|		} else {
 6429|     30|			r = 0; /* can't do anything with this card, hope there was no interference */
 6430|     30|		}
 6431|    639|	}
 6432|       |
 6433|    651|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6433:6): [True: 502, False: 149]
  ------------------
 6434|    502|		goto err;
 6435|       |
 6436|    149|	if (was_reset > 0)
  ------------------
  |  Branch (6436:6): [True: 0, False: 149]
  ------------------
 6437|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6438|       |
 6439|    149|	r = 0;
 6440|       |
 6441|  6.48k|err:
 6442|  6.48k|	if (priv)
  ------------------
  |  Branch (6442:6): [True: 1.30k, False: 5.17k]
  ------------------
 6443|  1.30k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  381|  1.30k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6444|  6.48k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.48k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.48k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.48k|	int _ret = r; \
  |  |  |  |  155|  6.48k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.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|    502|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 502, False: 5.97k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.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|  6.48k|	return _ret; \
  |  |  |  |  163|  6.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6445|  6.48k|}

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

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

sc_get_sc_hsm_driver:
 1976|  15.0k|{
 1977|  15.0k|	return sc_get_driver();
 1978|  15.0k|}
card-sc-hsm.c:sc_get_driver:
 1940|  15.0k|{
 1941|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1942|       |
 1943|  15.0k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1943:6): [True: 1, False: 15.0k]
  ------------------
 1944|      1|		iso_ops = iso_drv->ops;
 1945|       |
 1946|  15.0k|	sc_hsm_ops                   = *iso_drv->ops;
 1947|  15.0k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1948|  15.0k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1949|  15.0k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1950|  15.0k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1951|  15.0k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1952|  15.0k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1953|  15.0k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1954|  15.0k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1955|  15.0k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 1956|  15.0k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 1957|  15.0k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 1958|  15.0k|	sc_hsm_ops.init              = sc_hsm_init;
 1959|  15.0k|	sc_hsm_ops.finish            = sc_hsm_finish;
 1960|  15.0k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 1961|  15.0k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 1962|  15.0k|	sc_hsm_ops.logout            = sc_hsm_logout;
 1963|       |
 1964|       |	/* no record oriented file services */
 1965|  15.0k|	sc_hsm_ops.read_record       = NULL;
 1966|  15.0k|	sc_hsm_ops.write_record      = NULL;
 1967|  15.0k|	sc_hsm_ops.append_record     = NULL;
 1968|  15.0k|	sc_hsm_ops.update_record     = NULL;
 1969|       |
 1970|  15.0k|	return &sc_hsm_drv;
 1971|  15.0k|}
card-sc-hsm.c:sc_hsm_match_card:
  266|  5.51k|{
  267|  5.51k|	sc_path_t path;
  268|  5.51k|	int i, r, type = 0;
  269|  5.51k|	sc_file_t *file = NULL;
  270|       |
  271|  5.51k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  272|  5.51k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (272:6): [True: 137, False: 5.37k]
  |  Branch (272:16): [True: 136, False: 1]
  ------------------
  273|    136|		card->type = type;
  274|    136|		return 1;
  275|    136|	}
  276|       |
  277|  5.37k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  5.37k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  278|  5.37k|	r = sc_hsm_select_file(card, &path, &file);
  279|  5.37k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  5.37k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.37k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.37k|	int _ret = (r); \
  |  |  |  |  168|  5.37k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.07k, False: 302]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.07k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.07k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.07k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.07k|		return _ret; \
  |  |  |  |  172|  5.07k|	} \
  |  |  |  |  173|  5.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 302]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|       |
  281|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  282|    302|	if (file != NULL) {
  ------------------
  |  Branch (282:6): [True: 302, False: 0]
  ------------------
  283|    302|		size_t sz = file->prop_attr_len;
  284|    302|		sc_file_free(file);
  285|    302|		if (sz < 2) {
  ------------------
  |  Branch (285:7): [True: 298, False: 4]
  ------------------
  286|    298|			return 0;
  287|    298|		}
  288|    302|	}
  289|       |
  290|      4|	if (type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (290:6): [True: 0, False: 4]
  ------------------
  291|      0|		card->type = SC_CARD_TYPE_SC_HSM_SOC;
  292|      4|	} else {
  293|      4|		card->type = SC_CARD_TYPE_SC_HSM;
  294|      4|	}
  295|       |
  296|      4|	return 1;
  297|    302|}
card-sc-hsm.c:sc_hsm_select_file:
  246|  6.29k|{
  247|  6.29k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  248|  6.29k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  148|  6.87k|{
  149|  6.87k|	int rv;
  150|  6.87k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  151|  6.87k|	sc_file_t *file = NULL;
  152|  6.87k|	sc_path_t cpath;
  153|  6.87k|	size_t card_max_recv_size = card->max_recv_size;
  154|  6.87k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  155|       |
  156|  6.87k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (156:6): [True: 444, False: 6.43k]
  ------------------
  157|    444|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  158|    444|		sc_file_free(file);
  159|    444|		return rv;
  160|    444|	}
  161|       |
  162|  6.43k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  6.43k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (162:6): [True: 65, False: 6.36k]
  |  Branch (162:49): [True: 0, False: 65]
  ------------------
  163|       |		// Split applet selection and file selection into two separate calls
  164|      0|		cpath = *in_path;
  165|      0|		cpath.len = 0;
  166|      0|		cpath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  167|      0|		rv = sc_hsm_select_file_ex(card, &cpath, forceselect, NULL);
  168|      0|		LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  169|       |
  170|      0|		if (in_path->len) {
  ------------------
  |  Branch (170:7): [True: 0, False: 0]
  ------------------
  171|      0|			cpath = *in_path;
  172|      0|			cpath.aid.len = 0;
  173|      0|			rv = sc_hsm_select_file_ex(card, &cpath, forceselect, file_out);
  174|      0|		}
  175|      0|		return rv;
  176|      0|	}
  177|       |
  178|       |	// Prevent selection of applet unless this is the first time, selection is forced or the device is not authenticated
  179|  6.43k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  12.8k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (179:6): [True: 5.87k, False: 553]
  ------------------
  180|    553|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  1.10k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (180:8): [True: 488, False: 65]
  ------------------
  181|    488|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (181:8): [True: 0, False: 488]
  ------------------
  182|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (182:8): [True: 0, False: 0]
  ------------------
  183|    553|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  1.10k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (183:8): [True: 488, False: 65]
  ------------------
  184|    488|				&& in_path->len == 0
  ------------------
  |  Branch (184:8): [True: 1, False: 487]
  ------------------
  185|      1|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (185:8): [True: 0, False: 1]
  ------------------
  186|  5.87k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  5.87k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (187:7): [True: 5.37k, False: 502]
  |  Branch (187:16): [True: 403, False: 99]
  |  Branch (187:41): [True: 0, False: 99]
  ------------------
  188|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  189|  5.78k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  391|  5.78k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  190|  5.78k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  191|  5.78k|			card->max_recv_size = card_max_recv_size;
  192|  5.78k|			card->reader->max_recv_size = reader_max_recv_size;
  193|  5.78k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  5.78k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.78k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.78k|	int _ret = (r); \
  |  |  |  |  168|  5.78k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.39k, False: 386]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.39k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.39k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.39k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.39k|		return _ret; \
  |  |  |  |  172|  5.39k|	} \
  |  |  |  |  173|  5.78k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 386]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|       |
  195|    386|			if (priv) {
  ------------------
  |  Branch (195:8): [True: 84, False: 302]
  ------------------
  196|     84|				sc_file_free(priv->dffcp);
  197|       |				// Cache the FCP returned when selecting the applet
  198|     84|				sc_file_dup(&priv->dffcp, *file_out);
  199|     84|			}
  200|    386|		} else {
  201|     99|			sc_file_dup(file_out, priv->dffcp);
  202|     99|			rv = SC_SUCCESS;
  ------------------
  |  |   28|     99|#define SC_SUCCESS				0
  ------------------
  203|     99|		}
  204|    485|		return rv;
  205|  5.87k|	}
  206|       |
  207|    553|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (207:6): [True: 552, False: 1]
  |  Branch (207:29): [True: 385, False: 167]
  |  Branch (207:60): [True: 379, False: 6]
  ------------------
  208|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  209|    379|		if (in_path->len == 2) {
  ------------------
  |  Branch (209:7): [True: 0, False: 379]
  ------------------
  210|      0|			file = sc_file_new();
  211|      0|			if (file == NULL)
  ------------------
  |  Branch (211:8): [True: 0, False: 0]
  ------------------
  212|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|      0|			file->path = *in_path;
  214|      0|			file->id = 0x3F00;
  215|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  216|      0|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  217|       |
  218|      0|			*file_out = file;
  219|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  220|    379|		} else {
  221|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  222|    379|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  391|    379|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  223|    379|			sc_path_t truncated;
  224|    379|			memcpy(&truncated, in_path, sizeof truncated);
  225|    379|			truncated.len = in_path->len - 2;
  226|    379|			memcpy(truncated.value, in_path->value+2, truncated.len);
  227|    379|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  228|    379|			card->max_recv_size = card_max_recv_size;
  229|    379|			card->reader->max_recv_size = reader_max_recv_size;
  230|    379|			return rv;
  231|    379|		}
  232|    379|	}
  233|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  234|    174|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  391|    174|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  235|    174|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  236|    174|	card->max_recv_size = card_max_recv_size;
  237|    174|	card->reader->max_recv_size = reader_max_recv_size;
  238|    174|	return rv;
  239|    553|}
card-sc-hsm.c:sc_hsm_read_binary:
  795|    371|{
  796|    371|	sc_context_t *ctx = card->ctx;
  797|    371|	sc_apdu_t apdu;
  798|    371|	u8 cmdbuff[4];
  799|    371|	int r;
  800|       |
  801|    371|	if (idx > 0xffff) {
  ------------------
  |  Branch (801:6): [True: 0, False: 371]
  ------------------
  802|      0|		sc_log(ctx,  "invalid EF offset: 0x%X > 0xFFFF", idx);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  803|      0|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  804|      0|	}
  805|       |
  806|    371|	cmdbuff[0] = 0x54;
  807|    371|	cmdbuff[1] = 0x02;
  808|    371|	cmdbuff[2] = (idx >> 8) & 0xFF;
  809|    371|	cmdbuff[3] = idx & 0xFF;
  810|       |
  811|    371|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (811:6): [True: 0, False: 371]
  ------------------
  812|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  813|    371|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    371|#define SC_APDU_CASE_4			0x24
  ------------------
  814|    371|	apdu.data = cmdbuff;
  815|    371|	apdu.datalen = 4;
  816|    371|	apdu.lc = 4;
  817|    371|	apdu.le = count;
  818|    371|	apdu.resplen = count;
  819|    371|	apdu.resp = buf;
  820|       |
  821|    371|	r = sc_transmit_apdu(card, &apdu);
  822|    371|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    371|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    371|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    371|	int _ret = (r); \
  |  |  |  |  168|    371|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 361]
  |  |  |  |  ------------------
  |  |  |  |  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|    371|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 361]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  823|       |
  824|    361|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  825|    361|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    361|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (825:6): [True: 325, False: 36]
  ------------------
  826|    325|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|    325|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    325|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    325|	int _ret = (r); \
  |  |  |  |  168|    325|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 71, False: 254]
  |  |  |  |  ------------------
  |  |  |  |  169|     71|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     71|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     71|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     71|		return _ret; \
  |  |  |  |  172|     71|	} \
  |  |  |  |  173|    325|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 254]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|    325|	}
  828|       |
  829|    290|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    290|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    290|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    290|	int _ret = r; \
  |  |  |  |  155|    290|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 277]
  |  |  |  |  ------------------
  |  |  |  |  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|    277|	} else { \
  |  |  |  |  159|    277|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    277|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    277|	} \
  |  |  |  |  162|    290|	return _ret; \
  |  |  |  |  163|    290|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|    290|}
card-sc-hsm.c:sc_hsm_init:
 1775|    140|{
 1776|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1777|       |	char expanded_val[PATH_MAX];
 1778|       |	size_t expanded_len = PATH_MAX;
 1779|       |#endif
 1780|    140|	int flags,ext_flags;
 1781|    140|	sc_file_t *file = NULL;
 1782|    140|	sc_path_t path;
 1783|    140|	sc_hsm_private_data_t *priv = NULL;
 1784|       |
 1785|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1786|       |
 1787|    140|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  111|    140|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  116|    140|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    140|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1788|    140|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  143|    140|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  147|    140|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  148|    140|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  149|    140|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1789|    140|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  155|    140|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  156|    140|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  157|    140|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1790|       |
 1791|    140|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1792|    140|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1793|    140|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1794|    140|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1795|    140|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1796|       |
 1797|    140|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  183|    140|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1798|    140|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  182|    140|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1799|    140|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  184|    140|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    140|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1800|    140|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  185|    140|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  143|    140|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1801|    140|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  186|    140|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  150|    140|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1802|    140|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  187|    140|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  147|    140|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1803|    140|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  188|    140|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  148|    140|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1804|    140|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  189|    140|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  149|    140|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1805|    140|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    140|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1806|       |
 1807|    140|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  207|    140|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1808|    140|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  209|    140|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1809|    140|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  210|    140|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1810|    140|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  211|    140|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1811|    140|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    140|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1812|    140|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1813|    140|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1814|    140|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1815|    140|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1816|    140|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1817|    140|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1818|    140|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1819|       |
 1820|    140|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  557|    140|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  554|    140|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    140|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1821|       |
 1822|       |	// APDU Size limits
 1823|       |	//   JCOP 2.4.1r3           1462
 1824|       |	//   JCOP 2.4.2r3           1454
 1825|       |	//   JCOP 3                 1232
 1826|       |	//   JCOP 4                 1454
 1827|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1828|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1829|       |	//
 1830|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1831|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1832|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1833|       |	// class 3 APDU
 1834|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1835|       |
 1836|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1837|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1838|    140|	card->max_send_size = 1232 - 9;
 1839|       |	// Assume that card supports sending with extended length APDU and without limit
 1840|    140|	card->max_recv_size = 0;
 1841|       |
 1842|    140|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1842:6): [True: 0, False: 140]
  ------------------
 1843|    140|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1843:7): [True: 136, False: 4]
  ------------------
 1844|    136|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1845|    136|	} else {
 1846|       |		// Adjust to the limits set by the reader
 1847|      4|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1847:7): [True: 4, False: 0]
  ------------------
 1848|      4|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1848:8): [True: 4, False: 0]
  ------------------
 1849|      4|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1850|       |
 1851|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1852|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1853|      0|		}
 1854|       |
 1855|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1855:7): [True: 0, False: 0]
  ------------------
 1856|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1856:8): [True: 0, False: 0]
  ------------------
 1857|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1858|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1859|      0|		}
 1860|      0|	}
 1861|       |
 1862|    136|	priv = card->drv_data;
 1863|    136|	if (!priv) {
  ------------------
  |  Branch (1863:6): [True: 136, False: 0]
  ------------------
 1864|    136|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1865|    136|		if (!priv)
  ------------------
  |  Branch (1865:7): [True: 0, False: 136]
  ------------------
 1866|    136|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1867|    136|		card->drv_data = priv;
 1868|    136|	}
 1869|       |
 1870|    136|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    136|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1871|    136|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    272|#define SC_SUCCESS				0
  ------------------
  |  Branch (1871:6): [True: 12, False: 124]
  ------------------
 1872|     12|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1872:7): [True: 12, False: 0]
  |  Branch (1872:15): [True: 5, False: 7]
  |  Branch (1872:34): [True: 4, False: 1]
  ------------------
 1873|      4|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1874|      4|		u8 type = 0xFF;
 1875|      4|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1876|      4|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1877|      4|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1878|      4|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1879|      4|		char *p = "SmartCard-HSM";
 1880|      4|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1880:7): [True: 2, False: 2]
  ------------------
 1881|      2|			type = file->prop_attr[file->prop_attr_len - 3];
 1882|      2|		}
 1883|      4|		switch (type) {
 1884|      1|			case 0x00:
  ------------------
  |  Branch (1884:4): [True: 1, False: 3]
  ------------------
 1885|      1|				p = p00;
 1886|      1|				break;
 1887|      1|			case 0x01:
  ------------------
  |  Branch (1887:4): [True: 1, False: 3]
  ------------------
 1888|      1|				p = p01;
 1889|      1|				break;
 1890|      2|			default:
  ------------------
  |  Branch (1890:4): [True: 2, False: 2]
  ------------------
 1891|      2|				break;
 1892|      4|		}
 1893|      4|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1894|      4|		card->name = card_name;
 1895|       |
 1896|      4|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1896:7): [True: 1, False: 3]
  ------------------
 1897|      1|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  570|      1|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1898|      1|		}
 1899|      4|	}
 1900|    136|	sc_file_free(file);
 1901|       |
 1902|    136|	priv->EF_C_DevAut = NULL;
 1903|    136|	priv->EF_C_DevAut_len = 0;
 1904|       |
 1905|    136|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1906|    136|	EAC_init();
 1907|       |#ifdef _WIN32
 1908|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1909|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1910|       |		EAC_set_cvc_default_dir(expanded_val);
 1911|       |#else
 1912|    136|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    136|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1913|    136|#endif
 1914|    136|#endif
 1915|       |
 1916|    136|	return 0;
 1917|    136|}
card-sc-hsm.c:sc_hsm_finish:
 1922|    136|{
 1923|    136|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1924|    136|#ifdef ENABLE_SM
 1925|    136|	sc_sm_stop(card);
 1926|    136|#endif
 1927|    136|	if (priv) {
  ------------------
  |  Branch (1927:6): [True: 136, False: 0]
  ------------------
 1928|    136|		free(priv->serialno);
 1929|    136|		sc_file_free(priv->dffcp);
 1930|    136|		free(priv->EF_C_DevAut);
 1931|    136|	}
 1932|    136|	free(priv);
 1933|       |
 1934|    136|	return SC_SUCCESS;
  ------------------
  |  |   28|    136|#define SC_SUCCESS				0
  ------------------
 1935|    136|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1746|     19|{
 1747|     19|	switch (cmd) {
  ------------------
  |  Branch (1747:10): [True: 19, False: 0]
  ------------------
 1748|     19|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1748:2): [True: 19, False: 0]
  ------------------
 1749|     19|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1750|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1750:2): [True: 0, False: 19]
  ------------------
 1751|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1752|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1752:2): [True: 0, False: 19]
  ------------------
 1753|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1754|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1754:2): [True: 0, False: 19]
  ------------------
 1755|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1756|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1756:2): [True: 0, False: 19]
  ------------------
 1757|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1758|      0|	case SC_CARDCTL_SC_HSM_IMPORT_DKEK_SHARE:
  ------------------
  |  Branch (1758:2): [True: 0, False: 19]
  ------------------
 1759|      0|		return sc_hsm_import_dkek_share(card, (sc_cardctl_sc_hsm_dkek_t *)ptr);
 1760|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1760:2): [True: 0, False: 19]
  ------------------
 1761|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1762|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1762:2): [True: 0, False: 19]
  ------------------
 1763|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1764|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1764:2): [True: 0, False: 19]
  ------------------
 1765|      0|		return sc_hsm_register_public_key(card, ptr);
 1766|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1766:2): [True: 0, False: 19]
  ------------------
 1767|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1768|     19|	}
 1769|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1770|     19|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1193|     19|{
 1194|     19|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1195|       |
 1196|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1197|       |
 1198|     19|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1198:6): [True: 19, False: 0]
  |  Branch (1198:25): [True: 0, False: 19]
  ------------------
 1199|       |		/* sc-hsm initializes the serial number via its PKCS#15 layer.
 1200|       |		 * Create and destroy a dummy card to get this initialized.  Only do
 1201|       |		 * this for `opensc-tool --serial` to avoid unnecessary card commands
 1202|       |		 * in all other cases. */
 1203|      0|		sc_pkcs15_card_t *p15card = NULL;
 1204|      0|		(void)sc_pkcs15_bind(card, NULL, &p15card);
 1205|      0|		sc_pkcs15_unbind(p15card);
 1206|      0|	}
 1207|       |
 1208|     19|	if (!priv->serialno) {
  ------------------
  |  Branch (1208:6): [True: 19, False: 0]
  ------------------
 1209|     19|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|     19|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1210|     19|	}
 1211|       |
 1212|      0|	serial->len = strlen(priv->serialno);
 1213|      0|	if (serial->len > sizeof(serial->value))
  ------------------
  |  Branch (1213:6): [True: 0, False: 0]
  ------------------
 1214|      0|		serial->len = sizeof(serial->value);
 1215|       |
 1216|      0|	memcpy(serial->value, priv->serialno, serial->len);
 1217|       |
 1218|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1219|      0|}
card-sc-hsm.c:sc_hsm_pin_cmd:
  616|     19|{
  617|     19|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  618|     19|	sc_apdu_t apdu;
  619|     19|	u8 cmdbuff[16];
  620|     19|#ifdef ENABLE_SM
  621|     19|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  622|     19|#endif
  623|     19|	int r;
  624|     19|	int cmd = data->cmd;
  625|     19|	size_t pin2_len = data->pin2.len;
  626|       |
  627|     19|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  426|     19|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (627:6): [True: 0, False: 19]
  ------------------
  628|       |		/* First, perform a standard VERIFY */
  629|      0|		data->cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  630|       |		/* we assign pin2.len to 0 early on so that in case of an error we are
  631|       |		 * not exiting with an undefined session PIN */
  632|      0|		data->pin2.len = 0;
  633|      0|	}
  634|       |
  635|     19|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|     19|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (635:6): [True: 0, False: 19]
  ------------------
  636|      0|		   	&& (data->cmd == SC_PIN_CMD_CHANGE)
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (636:10): [True: 0, False: 0]
  ------------------
  637|      0|		   	&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (637:10): [True: 0, False: 0]
  ------------------
  638|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (638:8): [True: 0, False: 0]
  |  Branch (638:28): [True: 0, False: 0]
  ------------------
  639|      0|		return sc_hsm_soc_change(card, data);
  640|     19|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|     19|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (640:13): [True: 0, False: 19]
  ------------------
  641|      0|		   	&& (data->cmd == SC_PIN_CMD_UNBLOCK)
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (641:10): [True: 0, False: 0]
  ------------------
  642|      0|		   	&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (642:10): [True: 0, False: 0]
  ------------------
  643|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (643:8): [True: 0, False: 0]
  |  Branch (643:28): [True: 0, False: 0]
  ------------------
  644|      0|		return sc_hsm_soc_unblock(card, data);
  645|      0|	}
  646|       |
  647|     19|#ifdef ENABLE_SM
  648|       |	/* For contactless cards always establish a secure channel before PIN
  649|       |	 * verification. Also, Session PIN generation requires SM. */
  650|     19|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (650:7): [True: 0, False: 19]
  ------------------
  651|     19|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (651:8): [True: 19, False: 0]
  ------------------
  652|      0|				|| card->reader->uid.len || cmd == SC_PIN_CMD_GET_SESSION_PIN)
  ------------------
  |  |  426|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (652:8): [True: 0, False: 0]
  |  Branch (652:33): [True: 0, False: 0]
  ------------------
  653|     19|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  425|     19|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (653:7): [True: 0, False: 19]
  ------------------
  654|      0|		struct sc_pin_cmd_data check_sm_pin_data;
  655|      0|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  656|      0|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  425|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  657|      0|		check_sm_pin_data.pin_type = data->pin_type;
  658|      0|		check_sm_pin_data.pin_reference = data->pin_reference;
  659|       |
  660|      0|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|      0|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  661|      0|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (661:7): [True: 0, False: 0]
  ------------------
  662|       |			/* check if the existing SM channel is still valid */
  663|      0|			r = sc_pin_cmd(card, &check_sm_pin_data);
  664|      0|		}
  665|      0|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|      0|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|      0|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (665:7): [True: 0, False: 0]
  |  Branch (665:46): [True: 0, False: 0]
  ------------------
  666|       |			/* need to establish a new SM channel */
  667|      0|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  668|      0|					sc_hsm_perform_chip_authentication(card),
  669|      0|					"Could not perform chip authentication");
  670|      0|		}
  671|      0|	}
  672|     19|#endif
  673|       |
  674|     19|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|     19|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (674:6): [True: 0, False: 19]
  ------------------
  675|      0|			&& (data->cmd == SC_PIN_CMD_VERIFY)
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (675:7): [True: 0, False: 0]
  ------------------
  676|      0|			&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (676:7): [True: 0, False: 0]
  ------------------
  677|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (677:8): [True: 0, False: 0]
  |  Branch (677:28): [True: 0, False: 0]
  ------------------
  678|      0|		r = sc_hsm_soc_biomatch(card, data);
  679|     19|	} else {
  680|     19|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  422|     19|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (680:7): [True: 0, False: 19]
  |  Branch (680:43): [True: 0, False: 0]
  ------------------
  681|      0|			if (data->pin1.len != 16)
  ------------------
  |  Branch (681:8): [True: 0, False: 0]
  ------------------
  682|      0|				return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  683|       |
  684|       |			// Save SO PIN for later use in sc_hsm_init_pin()
  685|      0|			r = sc_hsm_encode_sopin(data->pin1.data, priv->sopin);
  686|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|       |
  688|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  689|      0|		}
  690|       |
  691|     19|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  423|     19|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (691:7): [True: 0, False: 19]
  |  Branch (691:43): [True: 0, False: 0]
  ------------------
  692|      0|			if ((data->pin1.len != 16) || (data->pin2.len != 16))
  ------------------
  |  Branch (692:8): [True: 0, False: 0]
  |  Branch (692:34): [True: 0, False: 0]
  ------------------
  693|      0|				return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  694|       |
  695|      0|			r = sc_hsm_encode_sopin(data->pin1.data, cmdbuff);
  696|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  697|       |
  698|      0|			r = sc_hsm_encode_sopin(data->pin2.data, cmdbuff + 8);
  699|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  700|       |
  701|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, 0x00, data->pin_reference);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  702|      0|			apdu.data = cmdbuff;
  703|      0|			apdu.datalen = sizeof(cmdbuff);
  704|      0|			apdu.lc = 16;
  705|      0|			apdu.resplen = 0;
  706|      0|			data->apdu = &apdu;
  707|      0|		}
  708|       |
  709|     19|#ifdef ENABLE_SM
  710|     19|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|     19|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (710:7): [True: 19, False: 0]
  ------------------
  711|     19|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|     19|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (711:8): [True: 0, False: 19]
  ------------------
  712|       |			/* JCOP's SM accelerator is incapable of using case 1 APDU in SM */
  713|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x20, 0x00, data->pin_reference);
  ------------------
  |  |  301|      0|#define SC_APDU_CASE_2			0x22
  ------------------
  714|      0|			apdu.resp = rbuf;
  715|      0|			apdu.resplen = sizeof rbuf;
  716|      0|			data->apdu = &apdu;
  717|      0|		}
  718|     19|#endif
  719|       |
  720|     19|		data->pin1.offset = 5;
  721|     19|		data->pin2.offset = 5;
  722|       |
  723|     19|		r = (*iso_ops->pin_cmd)(card, data);
  724|     19|		data->apdu = NULL;
  725|     19|	}
  726|     19|	LOG_TEST_RET(card->ctx, r, "Verification 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: 8, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|       |
  728|     11|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  426|     11|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (728:6): [True: 0, False: 11]
  ------------------
  729|       |		/* reset data->cmd to its original value */
  730|      0|		data->cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  426|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  731|      0|		if (data->pin_reference == 0x81) {
  ------------------
  |  Branch (731:7): [True: 0, False: 0]
  ------------------
  732|      0|			u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  733|      0|#ifdef ENABLE_SM
  734|      0|			if (card->sm_ctx.sm_mode != SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (734:8): [True: 0, False: 0]
  ------------------
  735|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  736|      0|						"Session PIN generation only supported in SM");
  737|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  738|      0|			}
  739|       |#else
  740|       |			sc_log(card->ctx,
  741|       |					"Session PIN generation only supported in SM");
  742|       |			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  743|       |#endif
  744|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x5A, 0x01, data->pin_reference);
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  745|      0|			apdu.cla = 0x80;
  746|      0|			apdu.resp = recvbuf;
  747|      0|			apdu.resplen = sizeof recvbuf;
  748|      0|			apdu.le = 0;
  749|      0|			if (sc_transmit_apdu(card, &apdu) != SC_SUCCESS
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (749:8): [True: 0, False: 0]
  ------------------
  750|      0|					|| sc_check_sw(card, apdu.sw1, apdu.sw2) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (750:9): [True: 0, False: 0]
  ------------------
  751|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  752|      0|						"Generating session PIN failed");
  753|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  754|      0|			}
  755|      0|			if (data->pin2.data && pin2_len > 0) {
  ------------------
  |  Branch (755:8): [True: 0, False: 0]
  |  Branch (755:27): [True: 0, False: 0]
  ------------------
  756|      0|				if (pin2_len >= apdu.resplen) {
  ------------------
  |  Branch (756:9): [True: 0, False: 0]
  ------------------
  757|      0|					memcpy((unsigned char *) data->pin2.data, apdu.resp,
  758|      0|							apdu.resplen);
  759|      0|					data->pin2.len = apdu.resplen;
  760|      0|				} else {
  761|      0|					sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  762|      0|							"Buffer too small for session PIN");
  763|      0|				}
  764|      0|			}
  765|      0|		} else {
  766|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  767|      0|					"Session PIN not supported for this PIN (0x%02X)",
  768|      0|					data->pin_reference);
  769|      0|		}
  770|      0|	}
  771|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|     11|}

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

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

sc_get_srbeid_driver:
  305|  15.0k|{
  306|       |	/* Save ISO ops for delegation, then override what we handle. */
  307|  15.0k|	iso_ops = sc_get_iso7816_driver()->ops;
  308|  15.0k|	srbeid_ops = *iso_ops;
  309|  15.0k|	srbeid_ops.match_card = srbeid_match_card;
  310|  15.0k|	srbeid_ops.init = srbeid_init;
  311|  15.0k|	srbeid_ops.select_file = srbeid_select_file;
  312|  15.0k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  313|  15.0k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  314|  15.0k|	srbeid_ops.decipher = srbeid_decipher;
  315|       |
  316|  15.0k|	return &srbeid_drv;
  317|  15.0k|}
card-srbeid.c:srbeid_match_card:
   72|  7.06k|{
   73|  7.06k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   74|  7.06k|	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   30|    477|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   28|    477|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 477, False: 6.58k]
  |  Branch (74:16): [True: 350, False: 127]
  ------------------
   75|    350|		card->name = srbeid_atrs[i].name;
   76|    350|		return 1;
   77|    350|	}
   78|  6.71k|	return 0;
   79|  7.06k|}
card-srbeid.c:srbeid_init:
   83|    350|{
   84|    350|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    350|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    350|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    350|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    350|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 350]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|       |
   86|    350|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    350|#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|    350|	_sc_card_add_rsa_alg(card, 2048,
   91|    350|			SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_RAW |
  ------------------
  |  |  118|    350|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              			SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_RAW |
  ------------------
  |  |  111|    350|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   92|    350|					SC_ALGORITHM_RSA_HASH_NONE,
  ------------------
  |  |  142|    350|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   93|    350|			0);
   94|       |
   95|    350|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    350|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    350|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    350|	int _ret = r; \
  |  |  |  |  155|    350|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 350, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    350|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 350]
  |  |  |  |  ------------------
  |  |  |  |  157|    350|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    350|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    350|	return _ret; \
  |  |  |  |  163|    350|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   96|    350|}
card-srbeid.c:srbeid_select_file:
  112|  2.65k|{
  113|  2.65k|	sc_apdu_t apdu;
  114|  2.65k|	u8 fci[16];
  115|  2.65k|	sc_file_t *file;
  116|  2.65k|	int r;
  117|       |
  118|  2.65k|	if (in_path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  2.65k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (118:6): [True: 440, False: 2.21k]
  ------------------
  119|    440|		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|  2.21k|	if (in_path->len == 0 && in_path->aid.len > 0)
  ------------------
  |  Branch (123:6): [True: 0, False: 2.21k]
  |  Branch (123:27): [True: 0, False: 0]
  ------------------
  124|      0|		return iso7816_select_aid(card, in_path->aid.value,
  125|      0|				in_path->aid.len, NULL, NULL);
  126|       |
  127|  2.21k|	if (in_path->len != 2)
  ------------------
  |  Branch (127:6): [True: 1.05k, False: 1.16k]
  ------------------
  128|  2.21k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|  1.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.05k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.05k|	int _ret = r; \
  |  |  |  |  155|  1.05k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.05k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.05k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.05k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.05k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.05k|	return _ret; \
  |  |  |  |  163|  1.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  129|       |
  130|  1.16k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.16k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  131|  1.16k|	apdu.data = in_path->value;
  132|  1.16k|	apdu.datalen = 2;
  133|  1.16k|	apdu.lc = 2;
  134|  1.16k|	apdu.resp = fci;
  135|  1.16k|	apdu.resplen = sizeof(fci);
  136|  1.16k|	apdu.le = 10;
  137|       |
  138|  1.16k|	r = sc_transmit_apdu(card, &apdu);
  139|  1.16k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.16k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.16k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.16k|	int _ret = (r); \
  |  |  |  |  168|  1.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 1.13k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.13k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  140|  1.13k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  141|  1.13k|	LOG_TEST_RET(card->ctx, r, "SELECT FILE failed");
  ------------------
  |  |  174|  1.13k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.13k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.13k|	int _ret = (r); \
  |  |  |  |  168|  1.13k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 304, False: 833]
  |  |  |  |  ------------------
  |  |  |  |  169|    304|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    304|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    304|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    304|		return _ret; \
  |  |  |  |  172|    304|	} \
  |  |  |  |  173|  1.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 833]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  142|       |
  143|    833|	if (apdu.resplen < 4)
  ------------------
  |  Branch (143:6): [True: 103, False: 730]
  ------------------
  144|    833|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    103|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    103|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    103|	int _ret = r; \
  |  |  |  |  155|    103|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    103|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    103|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    103|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    103|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    103|	return _ret; \
  |  |  |  |  163|    103|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  145|       |
  146|    730|	if (file_out) {
  ------------------
  |  Branch (146:6): [True: 708, False: 22]
  ------------------
  147|    708|		file = sc_file_new();
  148|    708|		if (!file)
  ------------------
  |  Branch (148:7): [True: 0, False: 708]
  ------------------
  149|    708|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|    708|		file->id = ((unsigned)in_path->value[0] << 8) | in_path->value[1];
  152|    708|		file->path = *in_path;
  153|    708|		file->size = ((size_t)fci[2] << 8) | (size_t)fci[3];
  154|    708|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    708|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  155|    708|		*file_out = file;
  156|    708|	}
  157|       |
  158|    730|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    730|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    730|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    730|	int _ret = r; \
  |  |  |  |  155|    730|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 730, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    730|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 730]
  |  |  |  |  ------------------
  |  |  |  |  157|    730|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    730|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    730|	return _ret; \
  |  |  |  |  163|    730|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|    730|}

sc_get_starcos_driver:
 2118|  15.0k|{
 2119|  15.0k|	return sc_get_driver();
 2120|  15.0k|}
card-starcos.c:sc_get_driver:
 2093|  15.0k|{
 2094|  15.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2095|  15.0k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2095:6): [True: 1, False: 15.0k]
  ------------------
 2096|      1|		iso_ops = iso_drv->ops;
 2097|       |
 2098|  15.0k|	starcos_ops = *iso_drv->ops;
 2099|  15.0k|	starcos_ops.match_card = starcos_match_card;
 2100|  15.0k|	starcos_ops.init   = starcos_init;
 2101|  15.0k|	starcos_ops.finish = starcos_finish;
 2102|  15.0k|	starcos_ops.select_file = starcos_select_file;
 2103|  15.0k|	starcos_ops.get_challenge = starcos_get_challenge;
 2104|  15.0k|	starcos_ops.check_sw    = starcos_check_sw;
 2105|  15.0k|	starcos_ops.create_file = starcos_create_file;
 2106|  15.0k|	starcos_ops.delete_file = NULL;
 2107|  15.0k|	starcos_ops.set_security_env  = starcos_set_security_env;
 2108|  15.0k|	starcos_ops.compute_signature = starcos_compute_signature;
 2109|  15.0k|	starcos_ops.decipher = starcos_decipher;
 2110|  15.0k|	starcos_ops.card_ctl    = starcos_card_ctl;
 2111|  15.0k|	starcos_ops.logout      = starcos_logout;
 2112|  15.0k|	starcos_ops.pin_cmd     = starcos_pin_cmd;
 2113|       |
 2114|  15.0k|	return &starcos_drv;
 2115|  15.0k|}
card-starcos.c:starcos_match_card:
  125|  12.7k|{
  126|  12.7k|	int i;
  127|       |
  128|  12.7k|	i = _sc_match_atr(card, starcos_atrs, &card->type);
  129|  12.7k|	if (i < 0)
  ------------------
  |  Branch (129:6): [True: 12.0k, False: 700]
  ------------------
  130|  12.0k|		return 0;
  131|    700|	return 1;
  132|  12.7k|}
card-starcos.c:starcos_init:
  359|    700|{
  360|    700|	unsigned int flags;
  361|    700|	starcos_ex_data *ex_data;
  362|       |
  363|    700|	ex_data = calloc(1, sizeof(starcos_ex_data));
  364|    700|	if (ex_data == NULL)
  ------------------
  |  Branch (364:6): [True: 0, False: 700]
  ------------------
  365|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  366|       |
  367|    700|	card->name = "STARCOS";
  368|    700|	card->cla  = 0x00;
  369|    700|	card->drv_data = (void *)ex_data;
  370|    700|	ex_data->pin_encoding = PIN_ENCODING_DETERMINE;
  ------------------
  |  |   96|    700|#define PIN_ENCODING_DETERMINE	0
  ------------------
  371|       |
  372|    700|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  120|    700|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    700|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|    700|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  373|    700|		| SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    700|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  374|    700|		| SC_ALGORITHM_RSA_PAD_ISO9796
  ------------------
  |  |  115|    700|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  375|    700|		| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  142|    700|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  376|    700|		| SC_ALGORITHM_RSA_HASH_SHA1
  ------------------
  |  |  143|    700|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  377|    700|		| SC_ALGORITHM_RSA_HASH_MD5
  ------------------
  |  |  144|    700|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  378|    700|		| SC_ALGORITHM_RSA_HASH_RIPEMD160
  ------------------
  |  |  146|    700|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  379|    700|		| SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  145|    700|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  380|       |
  381|    700|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    700|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  382|       |
  383|    700|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  1.40k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    700|#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: 470, False: 230]
  |  |  |  |  |  Branch (119:65): [True: 0, False: 230]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    230|#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: 64, False: 166]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 166]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|       |
  385|    534|		flags |= SC_CARD_FLAG_RNG
  ------------------
  |  |  543|    534|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  386|    534|			| SC_ALGORITHM_RSA_HASH_SHA224
  ------------------
  |  |  150|    534|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  387|    534|			| SC_ALGORITHM_RSA_HASH_SHA256
  ------------------
  |  |  147|    534|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  388|    534|			| SC_ALGORITHM_RSA_HASH_SHA384
  ------------------
  |  |  148|    534|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  389|    534|			| SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  149|    534|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  390|    534|			| SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  116|    534|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  391|       |
  392|    534|		_sc_card_add_rsa_alg(card, 512, flags, 0x10001);
  393|    534|		_sc_card_add_rsa_alg(card, 768, flags, 0x10001);
  394|    534|		_sc_card_add_rsa_alg(card,1024, flags, 0x10001);
  395|    534|		_sc_card_add_rsa_alg(card,1728, flags, 0x10001);
  396|    534|		_sc_card_add_rsa_alg(card,1976, flags, 0x10001);
  397|    534|		_sc_card_add_rsa_alg(card,2048, flags, 0x10001);
  398|    534|		if ( IS_V34(card) ) {
  ------------------
  |  |  119|    534|#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: 470, False: 64]
  |  |  |  Branch (119:65): [True: 0, False: 64]
  |  |  ------------------
  ------------------
  399|    470|			card->name = "STARCOS 3.4";
  400|    470|			card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    470|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  401|    470|		} else {
  402|     64|			card->name = "STARCOS 3.5";
  403|     64|			_sc_card_add_rsa_alg(card,3072, flags, 0x10001);
  404|     64|		}
  405|    534|		card->max_send_size = 255;
  406|    534|		card->max_recv_size = 256;
  407|    534|	} else {
  408|    166|		_sc_card_add_rsa_alg(card, 512, flags, 0x10001);
  409|    166|		_sc_card_add_rsa_alg(card, 768, flags, 0x10001);
  410|    166|		_sc_card_add_rsa_alg(card,1024, flags, 0x10001);
  411|       |
  412|       |		/* we need read_binary&friends with max 128 bytes per read */
  413|    166|		card->max_send_size = 128;
  414|    166|		card->max_recv_size = 128;
  415|    166|	}
  416|       |
  417|    700|	if (sc_parse_ef_atr(card) == SC_SUCCESS) {
  ------------------
  |  |   28|    700|#define SC_SUCCESS				0
  ------------------
  |  Branch (417:6): [True: 127, False: 573]
  ------------------
  418|    127|		size_t max_recv_size = 0;
  419|    127|		size_t max_send_size = 0;
  420|       |
  421|       |		/* Add max. length values from IAS/ECC specific issuer data */
  422|    127|		if ( card->ef_atr->issuer_data_len >= 4 ) {
  ------------------
  |  Branch (422:8): [True: 20, False: 107]
  ------------------
  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|    127|		if (card->ef_atr->max_response_apdu > 0) {
  ------------------
  |  Branch (427:7): [True: 35, False: 92]
  ------------------
  428|     35|			max_recv_size = card->ef_atr->max_response_apdu;
  429|     35|		}
  430|    127|		if (card->ef_atr->max_command_apdu > 0) {
  ------------------
  |  Branch (430:7): [True: 37, False: 90]
  ------------------
  431|     37|			max_send_size = card->ef_atr->max_command_apdu;
  432|     37|		}
  433|       |
  434|    127|		if ( max_send_size > 256 && max_recv_size > 256 ) {
  ------------------
  |  Branch (434:8): [True: 53, False: 74]
  |  Branch (434:31): [True: 38, False: 15]
  ------------------
  435|     38|			size_t max_recv_size_prev = card->max_recv_size;
  436|     38|			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|     38|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|     38|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  439|       |			/* the received data should not exceed max_recv_size including the sw1/sw2 */
  440|     38|			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|     38|			card->max_send_size = max_send_size - 10;
  443|       |			/* probe reader for extended APDU support */
  444|     38|			if ( starcos_probe_reader_for_ext_apdu(card) ) {
  ------------------
  |  Branch (444:9): [True: 2, False: 36]
  ------------------
  445|      2|				sc_log(card->ctx, "Successfully probed extended APDU, enabling extended APDU with max send/recv %d/%d",
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  446|      2|					(int)card->max_send_size, (int)card->max_recv_size);
  447|     36|			} else {
  448|     36|				card->caps &= ~(SC_CARD_CAP_APDU_EXT);
  ------------------
  |  |  554|     36|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  449|     36|				card->max_recv_size = max_recv_size_prev;
  450|     36|				card->max_send_size = max_send_size_prev;
  451|     36|				sc_log(card->ctx, "Ext APDU probing failed, the actual reader does not support ext APDU");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  452|     36|			}
  453|     38|		}
  454|    127|	}
  455|       |
  456|    700|	if ( ex_data->pin_encoding == PIN_ENCODING_DETERMINE ) {
  ------------------
  |  |   96|    700|#define PIN_ENCODING_DETERMINE	0
  ------------------
  |  Branch (456:7): [True: 700, False: 0]
  ------------------
  457|       |		// about to determine PIN encoding
  458|    700|		ex_data->pin_encoding = starcos_determine_pin_encoding(card);
  459|    700|	}
  460|       |
  461|    700|	if ( card->type == SC_CARD_TYPE_STARCOS_V3_4 && starcos_has_esign_app(card) ) {
  ------------------
  |  Branch (461:7): [True: 470, False: 230]
  |  Branch (461:50): [True: 58, False: 412]
  ------------------
  462|     58|		card->type = SC_CARD_TYPE_STARCOS_V3_4_ESIGN;
  463|     58|		sc_log(card->ctx, "Card has eSign app, card type changed to %d", card->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  464|     58|	}
  465|       |
  466|    700|	return 0;
  467|    700|}
card-starcos.c:starcos_probe_reader_for_ext_apdu:
  301|     38|static int starcos_probe_reader_for_ext_apdu(sc_card_t * card) {
  302|     38|	sc_apdu_t apdu;
  303|     38|	int rv;
  304|       |	/* try to read STARCOS3X_PROBE_APDU_LENGTH bytes */
  305|     38|	u8 data[STARCOS3X_PROBE_APDU_LENGTH];
  306|       |
  307|       |	/* Get Data: Get Chip Serial Number */
  308|     38|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_EXT, 0xCA, 0x9F, 0x6C);
  ------------------
  |  |  297|     38|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|     38|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     38|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  309|     38|	apdu.cla = 0xA0;
  310|     38|	apdu.resp = data;
  311|     38|	apdu.resplen = sizeof(data);
  312|     38|	apdu.le = apdu.resplen;
  313|     38|	rv = sc_transmit_apdu(card, &apdu);
  314|     38|	LOG_TEST_RET(card->ctx, rv, "Failed to send Get Data ext. APDU");
  ------------------
  |  |  174|     38|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     38|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     38|	int _ret = (r); \
  |  |  |  |  168|     38|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  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|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|     36|	return (apdu.sw1 == 0x90 && apdu.sw2 == 0x00);
  ------------------
  |  Branch (315:10): [True: 1, False: 35]
  |  Branch (315:30): [True: 0, False: 1]
  ------------------
  316|     38|}
card-starcos.c:starcos_determine_pin_encoding:
  269|    700|{
  270|    700|	unsigned int pin_format = PIN_FORMAT_DEFAULT;
  ------------------
  |  |  107|    700|#define PIN_FORMAT_DEFAULT		PIN_FORMAT_F2
  |  |  ------------------
  |  |  |  |  101|    700|#define PIN_FORMAT_F2			0x12
  |  |  ------------------
  ------------------
  271|    700|	unsigned int encoding = PIN_ENCODING_DETERMINE;
  ------------------
  |  |   96|    700|#define PIN_ENCODING_DETERMINE	0
  ------------------
  272|       |
  273|    700|	if ( IS_V34(card) ) {
  ------------------
  |  |  119|    700|#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: 470, False: 230]
  |  |  |  Branch (119:65): [True: 0, False: 230]
  |  |  ------------------
  ------------------
  274|    470|		starcos_determine_pin_format34(card, &pin_format);
  275|    470|	} else if ( IS_V35(card) ) {
  ------------------
  |  |  120|    230|#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: 64, False: 166]
  |  |  |  Branch (120:65): [True: 0, False: 166]
  |  |  ------------------
  ------------------
  276|     64|		starcos_determine_pin_format35(card, &pin_format);
  277|     64|	}
  278|       |
  279|    700|	switch (pin_format) {
  ------------------
  |  Branch (279:10): [True: 698, False: 2]
  ------------------
  280|      1|	case PIN_FORMAT_PW_ASCII:
  ------------------
  |  |  105|      1|#define PIN_FORMAT_PW_ASCII		0x21
  ------------------
  |  Branch (280:2): [True: 1, False: 699]
  ------------------
  281|      2|	case PIN_FORMAT_ASCII:
  ------------------
  |  |  104|      2|#define PIN_FORMAT_ASCII		0x14
  ------------------
  |  Branch (281:2): [True: 1, False: 699]
  ------------------
  282|      2|		encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|      2|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  283|      2|		break;
  284|      3|	case PIN_FORMAT_BCD:
  ------------------
  |  |  103|      3|#define PIN_FORMAT_BCD			0x13
  ------------------
  |  Branch (284:2): [True: 3, False: 697]
  ------------------
  285|      3|		encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  433|      3|#define SC_PIN_ENCODING_BCD	1
  ------------------
  286|      3|		break;
  287|      1|	case PIN_FORMAT_F1:
  ------------------
  |  |  100|      1|#define PIN_FORMAT_F1			0x11
  ------------------
  |  Branch (287:2): [True: 1, False: 699]
  ------------------
  288|    693|	case PIN_FORMAT_F2:
  ------------------
  |  |  101|    693|#define PIN_FORMAT_F2			0x12
  ------------------
  |  Branch (288:2): [True: 692, False: 8]
  ------------------
  289|    693|		encoding = SC_PIN_ENCODING_GLP;
  ------------------
  |  |  434|    693|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  290|    693|		break;
  291|    700|	}
  292|       |
  293|    700|	sc_log(card->ctx, "Determined PIN encoding: %d", encoding);
  ------------------
  |  |   71|    700|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  294|    700|	return encoding;
  295|    700|}
card-starcos.c:starcos_determine_pin_format34:
  189|    470|{
  190|    470|	struct sc_context *ctx = card->ctx;
  191|    470|	struct sc_path path;
  192|    470|	struct sc_file *file;
  193|    470|	unsigned char buf[256];
  194|    470|	int rv;
  195|    470|	int retval = SC_SUCCESS;
  ------------------
  |  |   28|    470|#define SC_SUCCESS				0
  ------------------
  196|    470|	int rec_no=1;
  197|       |
  198|    470|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    470|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    470|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    470|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    470|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 470]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|    470|	sc_format_path(starcos_ef_pwdd, &path);
  201|    470|	rv = sc_select_file(card, &path, &file);
  202|    470|	LOG_TEST_RET(ctx, rv, "Cannot select EF.PWDD file");
  ------------------
  |  |  174|    470|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    470|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    470|	int _ret = (r); \
  |  |  |  |  168|    470|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 402, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  169|    402|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    402|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    402|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    402|		return _ret; \
  |  |  |  |  172|    402|	} \
  |  |  |  |  173|    470|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  203|       |
  204|     68|	if ( (rv = sc_read_record(card, rec_no, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0 ) {
  ------------------
  |  | 1305|     68|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (204:7): [True: 24, False: 44]
  ------------------
  205|     24|		starcos_ctrl_ref_template ctrl_ref_template;
  206|     24|		memset((void*)&ctrl_ref_template, 0, sizeof(ctrl_ref_template));
  207|     24|		rv = starcos_parse_supported_sec_mechanisms(card, buf, rv, &ctrl_ref_template);
  208|     24|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
  |  Branch (208:8): [True: 8, False: 16]
  ------------------
  209|      8|			*pin_format = ctrl_ref_template.transmission_format;
  210|      8|			sc_log(ctx, "Determined StarCOS 3.4 PIN format: 0x%x", *pin_format);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  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|     44|	} else {
  216|     44|		sc_log(ctx, "Failed to read record %d of EF.PWDD, err=%d", rec_no, rv);
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  217|     44|		retval = rv;
  218|     44|	}
  219|       |
  220|     68|	sc_file_free(file);
  221|     68|	LOG_FUNC_RETURN(ctx, retval);
  ------------------
  |  |  164|     68|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     68|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     68|	int _ret = r; \
  |  |  |  |  155|     68|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 68, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 58, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     68|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     68|	return _ret; \
  |  |  |  |  163|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|     68|}
card-starcos.c:starcos_parse_supported_sec_mechanisms:
  158|    861|{
  159|    861|	struct sc_context *ctx = card->ctx;
  160|    861|	const unsigned char *supported_sec_mechanisms_tag = NULL;
  161|    861|	size_t taglen;
  162|       |
  163|    861|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    861|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    861|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    861|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    861|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 861]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|    861|	supported_sec_mechanisms_tag = sc_asn1_find_tag(ctx, buf, buflen, TAG_STARCOS3X_SUPPORTED_SEC_MECHANISMS_tag, &taglen);
  ------------------
  |  |  146|    861|#define TAG_STARCOS3X_SUPPORTED_SEC_MECHANISMS_tag		0x7B
  ------------------
  166|    861|	if (supported_sec_mechanisms_tag != NULL && taglen >= 1)   {
  ------------------
  |  Branch (166:6): [True: 610, False: 251]
  |  Branch (166:46): [True: 589, False: 21]
  ------------------
  167|    589|		const unsigned char *tx_fmt_tag = NULL;
  168|    589|		const unsigned char *ctrl_ref_template_tag = NULL;
  169|    589|		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|    589|		ctrl_ref_template_tag = sc_asn1_find_tag(ctx, supported_sec_mechanisms_tag, taglen, TAG_STARCOS3X_CTRL_REF_TEMPLATE, &taglen);
  ------------------
  |  |  147|    589|#define TAG_STARCOS3X_CTRL_REF_TEMPLATE				0xA4
  ------------------
  173|    589|		if ( ctrl_ref_template_tag == NULL || taglen == 0 ) {
  ------------------
  |  Branch (173:8): [True: 587, False: 2]
  |  Branch (173:41): [True: 1, False: 1]
  ------------------
  174|    588|			ctrl_ref_template_tag = supported_sec_mechanisms_tag;
  175|    588|			taglen = supported_sec_mechanisms_taglen;
  176|    588|		}
  177|       |
  178|    589|		tx_fmt_tag = sc_asn1_find_tag(ctx, ctrl_ref_template_tag, taglen, TAG_STARCOS3X_TRANSMISSION_FORMAT, &taglen);
  ------------------
  |  |  148|    589|#define TAG_STARCOS3X_TRANSMISSION_FORMAT			0x89
  ------------------
  179|    589|		if ( tx_fmt_tag != NULL && taglen >= 1 ) {
  ------------------
  |  Branch (179:8): [True: 9, False: 580]
  |  Branch (179:30): [True: 8, False: 1]
  ------------------
  180|      8|			ctrl_ref_template->transmission_format = *(tx_fmt_tag + 0);
  181|      8|			LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|      8|		}
  183|    589|	}
  184|       |
  185|    853|	LOG_FUNC_RETURN(ctx, SC_ERROR_TEMPLATE_NOT_FOUND);
  ------------------
  |  |  164|    853|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    853|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    853|	int _ret = r; \
  |  |  |  |  155|    853|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 853, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    853|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    853|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 853, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    853|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    853|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    853|	return _ret; \
  |  |  |  |  163|    853|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  186|    853|}
card-starcos.c:starcos_determine_pin_format35:
  225|     64|{
  226|     64|	struct sc_context *ctx = card->ctx;
  227|     64|	struct sc_path path;
  228|     64|	struct sc_file *file;
  229|     64|	unsigned char buf[256];
  230|     64|	int rv;
  231|     64|	int retval = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     64|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  232|     64|	int rec_no=1;
  233|     64|	starcos_ctrl_ref_template ctrl_ref_template;
  234|       |
  235|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|     64|	sc_format_path(starcos_ef_keyd, &path);
  238|     64|	rv = sc_select_file(card, &path, &file);
  239|     64|	LOG_TEST_RET(ctx, rv, "Cannot select EF.KEYD file");
  ------------------
  |  |  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: 17, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  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|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|       |
  241|  1.67k|	while ( (rv = sc_read_record(card, rec_no++, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0 ) {
  ------------------
  |  | 1305|  1.67k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (241:10): [True: 1.62k, False: 47]
  ------------------
  242|  1.62k|		if ( buf[0] != TAG_STARCOS35_PIN_REFERENCE ) continue;
  ------------------
  |  |  145|  1.62k|#define TAG_STARCOS35_PIN_REFERENCE					0x88
  ------------------
  |  Branch (242:8): [True: 787, False: 837]
  ------------------
  243|       |
  244|    837|		memset((void*)&ctrl_ref_template, 0, sizeof(ctrl_ref_template));
  245|    837|		rv = starcos_parse_supported_sec_mechanisms(card, buf, rv, &ctrl_ref_template);
  246|    837|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    837|#define SC_SUCCESS				0
  ------------------
  |  Branch (246:8): [True: 0, False: 837]
  ------------------
  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|    837|		} else {
  253|    837|			sc_log(ctx, "Failed to parse record %d of EF.KEYD, err=%d", rec_no-1, rv);
  ------------------
  |  |   71|    837|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  254|    837|			retval = rv;
  255|    837|		}
  256|    837|	}
  257|       |
  258|     47|	sc_file_free(file);
  259|     47|	LOG_FUNC_RETURN(ctx, retval);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|     47|}
card-starcos.c:starcos_has_esign_app:
  339|    470|static int starcos_has_esign_app(sc_card_t * card) {
  340|    470|	static const char * starcos_esign_aid = "A0:00:00:02:45:53:69:67:6E";
  341|    470|	int rv;
  342|       |
  343|    470|	rv = starcos_select_mf(card);
  344|    470|	if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    470|#define SC_SUCCESS				0
  ------------------
  |  Branch (344:7): [True: 463, False: 7]
  ------------------
  345|    463|		u8 aid[SC_MAX_PATH_SIZE];
  346|    463|		size_t len = sizeof(aid);
  347|       |
  348|    463|		rv = sc_hex_to_bin(starcos_esign_aid, aid, &len);
  349|    463|		LOG_TEST_RET(card->ctx, rv, "Failed to convert eSing AID");
  ------------------
  |  |  174|    463|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    463|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    463|	int _ret = (r); \
  |  |  |  |  168|    463|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 463]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    463|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 463]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  350|    463|		rv = starcos_select_aid(card, aid, len, NULL);
  351|    463|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    463|#define SC_SUCCESS				0
  ------------------
  |  Branch (351:8): [True: 58, False: 405]
  ------------------
  352|     58|			starcos_select_mf(card);
  353|     58|		}
  354|    463|	}
  355|    470|	return ( rv == SC_SUCCESS );
  ------------------
  |  |   28|    470|#define SC_SUCCESS				0
  ------------------
  356|    470|}
card-starcos.c:starcos_select_mf:
  318|    528|static int starcos_select_mf(sc_card_t * card) {
  319|    528|	sc_apdu_t apdu;
  320|    528|	const u8 mf_buf[2] = {0x3f, 0x00};
  321|       |
  322|    528|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    528|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  323|    528|	apdu.le = 0;
  324|    528|	apdu.lc = 2;
  325|    528|	apdu.data    = mf_buf;
  326|    528|	apdu.datalen = 2;
  327|    528|	apdu.resplen = 0;
  328|       |
  329|    528|	return sc_transmit_apdu(card, &apdu);
  330|    528|}
card-starcos.c:starcos_select_aid:
  749|  1.83k|{
  750|  1.83k|	sc_apdu_t apdu;
  751|  1.83k|	int r;
  752|  1.83k|	size_t i = 0;
  753|       |
  754|  1.83k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x04, 0x0C);
  ------------------
  |  |  293|  1.83k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  755|  1.83k|	apdu.lc = len;
  756|  1.83k|	apdu.data = (u8*)aid;
  757|  1.83k|	apdu.datalen = len;
  758|  1.83k|	apdu.resplen = 0;
  759|  1.83k|	apdu.le = 0;
  760|  1.83k|	r = sc_transmit_apdu(card, &apdu);
  761|  1.83k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.83k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.83k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.83k|	int _ret = (r); \
  |  |  |  |  168|  1.83k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 1.82k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.83k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.82k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  762|       |
  763|       |	/* check return value */
  764|  1.82k|	if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61 )
  ------------------
  |  Branch (764:8): [True: 168, False: 1.65k]
  |  Branch (764:28): [True: 149, False: 19]
  |  Branch (764:49): [True: 1.67k, False: 0]
  ------------------
  765|  1.67k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  1.67k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.67k|	int _ret = r; \
  |  |  155|  1.67k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.67k, False: 0]
  |  |  ------------------
  |  |  156|  1.67k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.67k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.67k, False: 0]
  |  |  ------------------
  |  |  157|  1.67k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.67k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.67k|	return _ret; \
  |  |  163|  1.67k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  766|       |
  767|    149|	if (file_out) {
  ------------------
  |  Branch (767:6): [True: 0, False: 149]
  ------------------
  768|      0|		sc_file_t *file = sc_file_new();
  769|      0|		if (!file)
  ------------------
  |  Branch (769:7): [True: 0, False: 0]
  ------------------
  770|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  771|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  772|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  773|      0|		file->path.len = 0;
  774|      0|		file->size = 0;
  775|       |		/* AID */
  776|      0|		for (i = 0; i < len; i++)
  ------------------
  |  Branch (776:15): [True: 0, False: 0]
  ------------------
  777|      0|			file->name[i] = aid[i];
  778|      0|		file->namelen = len;
  779|      0|		file->id = 0x0000;
  780|      0|		file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  781|       |
  782|      0|		*file_out = file;
  783|      0|	}
  784|    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]
  |  |  ------------------
  ------------------
  785|    149|}
card-starcos.c:starcos_finish:
  470|    700|{
  471|    700|	if (card->drv_data)
  ------------------
  |  Branch (471:6): [True: 700, False: 0]
  ------------------
  472|    700|		free((starcos_ex_data *)card->drv_data);
  473|    700|	return 0;
  474|    700|}
card-starcos.c:starcos_select_file:
  917|  5.13k|{
  918|  5.13k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  919|  5.13k|	int    r, pathtype;
  920|  5.13k|	size_t i, pathlen;
  921|       |
  922|  5.13k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.13k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.13k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.13k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.13k]
  |  |  ------------------
  ------------------
  923|       |
  924|  5.13k|	if ( in_path->len > sizeof(pathbuf) ) {
  ------------------
  |  Branch (924:7): [True: 0, False: 5.13k]
  ------------------
  925|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  926|      0|	}
  927|  5.13k|	memcpy(path, in_path->value, in_path->len);
  928|  5.13k|	pathlen = in_path->len;
  929|  5.13k|	pathtype = in_path->type;
  930|       |
  931|  5.13k|	if (in_path->aid.len) {
  ------------------
  |  Branch (931:6): [True: 4, False: 5.13k]
  ------------------
  932|      4|		if (!pathlen) {
  ------------------
  |  Branch (932:7): [True: 0, False: 4]
  ------------------
  933|      0|			if ( in_path->aid.len > sizeof(pathbuf) ) {
  ------------------
  |  Branch (933:9): [True: 0, False: 0]
  ------------------
  934|      0|				SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  935|      0|			}
  936|      0|			memcpy(path, in_path->aid.value, in_path->aid.len);
  937|      0|			pathlen = in_path->aid.len;
  938|      0|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  939|      4|		} else {
  940|      4|			r = starcos_select_aid(card, in_path->aid.value, in_path->aid.len, NULL);
  941|      4|			LOG_TEST_RET(card->ctx, r, "Could not select AID!");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  942|       |
  943|      3|			if (pathtype == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|      3|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (943:8): [True: 0, False: 3]
  ------------------
  944|      0|				pathtype = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  945|      0|			}
  946|      3|		}
  947|      4|	}
  948|       |
  949|  5.13k|	if (pathtype == SC_PATH_TYPE_FILE_ID)
  ------------------
  |  |  117|  5.13k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (949:6): [True: 0, False: 5.13k]
  ------------------
  950|      0|	{	/* SELECT EF/DF with ID */
  951|       |		/* Select with 2byte File-ID */
  952|      0|		if (pathlen != 2)
  ------------------
  |  Branch (952:7): [True: 0, False: 0]
  ------------------
  953|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  954|      0|		r = starcos_select_fid(card, path[0],
  955|      0|				path[1], path[0] == 0x3F && path[1] == 0x00 ? NULL : file_out, 1);
  ------------------
  |  Branch (955:14): [True: 0, False: 0]
  |  Branch (955:33): [True: 0, False: 0]
  ------------------
  956|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  957|      0|	}
  958|  5.13k|	else if (pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  5.13k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (958:11): [True: 1.36k, False: 3.77k]
  ------------------
  959|  1.36k|	{	/* SELECT DF with AID */
  960|       |		/* Select with 1-16byte Application-ID */
  961|  1.36k|		r = starcos_select_aid(card, pathbuf, pathlen, file_out);
  962|  1.36k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.36k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.36k|	int _ret = r; \
  |  |  155|  1.36k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.36k, False: 0]
  |  |  ------------------
  |  |  156|  1.36k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.27k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.27k, False: 88]
  |  |  ------------------
  |  |  157|  1.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.36k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.36k|	return _ret; \
  |  |  163|  1.36k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  963|  1.36k|	}
  964|  3.77k|	else if (pathtype == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  3.77k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (964:11): [True: 3.77k, False: 0]
  ------------------
  965|  3.77k|	{
  966|  3.77k|		u8 n_pathbuf[SC_MAX_PATH_SIZE];
  967|       |
  968|       |		/* Select with path (sequence of File-IDs) */
  969|       |		/* Starcos (S 2.1 and SPK 2.3) only supports one
  970|       |		 * level of subdirectories, therefore a path is
  971|       |		 * at most 3 FID long (the last one being the FID
  972|       |		 * of a EF) => pathlen must be even and less than 6
  973|       |		 */
  974|  3.77k|		if (pathlen%2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (974:7): [True: 0, False: 3.77k]
  |  Branch (974:25): [True: 1, False: 3.77k]
  |  Branch (974:40): [True: 0, False: 3.77k]
  ------------------
  975|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  976|       |		/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  977|  3.77k|		if (pathlen == 6 && ( path[0] != 0x3f || path[1] != 0x00 ))
  ------------------
  |  Branch (977:7): [True: 219, False: 3.55k]
  |  Branch (977:25): [True: 1, False: 218]
  |  Branch (977:44): [True: 1, False: 217]
  ------------------
  978|      2|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      2|	int _ret = r; \
  |  |  155|      2|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  ------------------
  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  ------------------
  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      2|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      2|	return _ret; \
  |  |  163|      2|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  979|       |
  980|  3.76k|		if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  7.53k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  3.76k|#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.18k, False: 1.57k]
  |  |  |  |  |  Branch (119:65): [True: 309, False: 1.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  1.27k|#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: 322, False: 948]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 948]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  981|       |			/* unify path (the first FID should be MF) */
  982|  2.82k|			if (path[0] != 0x3f || path[1] != 0x00)
  ------------------
  |  Branch (982:8): [True: 40, False: 2.78k]
  |  Branch (982:27): [True: 0, False: 2.78k]
  ------------------
  983|     40|			{
  984|     40|				n_pathbuf[0] = 0x3f;
  985|     40|				n_pathbuf[1] = 0x00;
  986|     40|				memcpy(n_pathbuf+2, path, pathlen);
  987|     40|				path = n_pathbuf;
  988|     40|				pathlen += 2;
  989|     40|			}
  990|  2.82k|		}
  991|       |
  992|  4.79k|		for ( i=0; i<pathlen-2; i+=2 )
  ------------------
  |  Branch (992:14): [True: 3.87k, False: 921]
  ------------------
  993|  3.87k|		{
  994|  3.87k|			r = starcos_select_fid(card, path[i], path[i+1], NULL, 0);
  995|  3.87k|			LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|  3.87k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.87k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.87k|	int _ret = (r); \
  |  |  |  |  168|  3.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.84k, False: 1.02k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.84k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.84k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.84k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.84k|		return _ret; \
  |  |  |  |  172|  2.84k|	} \
  |  |  |  |  173|  3.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  996|  3.87k|		}
  997|    921|		r = starcos_select_fid(card, path[pathlen-2], path[pathlen-1], file_out, 1);
  998|    921|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    921|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    921|	int _ret = r; \
  |  |  155|    921|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 921, False: 0]
  |  |  ------------------
  |  |  156|    921|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    313|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 313, False: 608]
  |  |  ------------------
  |  |  157|    921|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    921|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    921|	return _ret; \
  |  |  163|    921|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  999|    921|	}
 1000|      0|	else
 1001|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1002|  5.13k|}
card-starcos.c:starcos_select_fid:
  790|  4.79k|{
  791|  4.79k|	sc_apdu_t apdu;
  792|  4.79k|	u8 data[] = {id_hi & 0xff, id_lo & 0xff};
  793|  4.79k|	u8 resp[SC_MAX_APDU_BUFFER_SIZE];
  794|  4.79k|	int bIsDF = 0, r;
  795|  4.79k|	int isFCP = 0;
  796|  4.79k|	int isMF = 0;
  797|       |
  798|       |	/* request FCI to distinguish between EFs and DFs */
  799|  4.79k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  4.79k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  800|  4.79k|	apdu.p2   = 0x00;
  801|  4.79k|	apdu.resp = (u8*)resp;
  802|  4.79k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  4.79k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  803|  4.79k|	apdu.le = 256;
  804|  4.79k|	apdu.lc = 2;
  805|  4.79k|	apdu.data = (u8*)data;
  806|  4.79k|	apdu.datalen = 2;
  807|       |
  808|  4.79k|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  9.58k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  4.79k|#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: 2.11k]
  |  |  |  |  |  Branch (119:65): [True: 455, False: 1.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  1.65k|#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: 400, False: 1.25k]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 1.25k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|  3.53k|		if (id_hi == 0x3f && id_lo == 0x0) {
  ------------------
  |  Branch (809:7): [True: 2.82k, False: 712]
  |  Branch (809:24): [True: 2.82k, False: 0]
  ------------------
  810|  2.82k|			apdu.p1 = 0x0;
  811|  2.82k|			apdu.p2 = 0x0C;
  812|  2.82k|			apdu.le = 0;
  813|  2.82k|			apdu.resplen = 0;
  814|  2.82k|			apdu.resp = NULL;
  815|  2.82k|			apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  2.82k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  816|  2.82k|			isMF = 1;
  817|  2.82k|		} else if (file_out || is_file) {
  ------------------
  |  Branch (817:14): [True: 636, False: 76]
  |  Branch (817:26): [True: 28, False: 48]
  ------------------
  818|       |			// last component (i.e. file or path)
  819|    664|			apdu.p1 = 0x2;
  820|    664|			apdu.p2 = 0x4;
  821|    664|		} else {
  822|       |			// path component
  823|     48|			apdu.p1 = 0x1;
  824|     48|			apdu.p2 = 0x0;
  825|     48|		}
  826|  3.53k|	}
  827|       |
  828|  4.79k|	r = sc_transmit_apdu(card, &apdu);
  829|  4.79k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  4.79k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.79k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.79k|	int _ret = (r); \
  |  |  |  |  168|  4.79k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 56, False: 4.73k]
  |  |  |  |  ------------------
  |  |  |  |  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|  4.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|       |
  831|  4.73k|	if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
  ------------------
  |  Branch (831:6): [True: 1.29k, False: 3.43k]
  |  Branch (831:25): [True: 31, False: 1.26k]
  |  Branch (831:45): [True: 20, False: 11]
  ------------------
  832|       |		/* no FCI => we have a DF (see comment in process_fci()) */
  833|     20|		bIsDF = 1;
  834|     20|		apdu.p2 = 0x0C;
  835|     20|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     20|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  836|     20|		apdu.resplen = 0;
  837|     20|		apdu.le = 0;
  838|     20|		r = sc_transmit_apdu(card, &apdu);
  839|     20|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|     20|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     20|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     20|	int _ret = (r); \
  |  |  |  |  168|     20|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  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|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|  4.71k|	} else if ((IS_V3x(card))
  ------------------
  |  |  121|  4.71k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  4.71k|#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.64k, False: 2.07k]
  |  |  |  |  |  Branch (119:65): [True: 449, False: 1.62k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  1.62k|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 391, False: 1.23k]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 1.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|  3.48k|			&& apdu.p2 == 0x4 && apdu.sw1 == 0x6a && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (841:7): [True: 655, False: 2.82k]
  |  Branch (841:25): [True: 239, False: 416]
  |  Branch (841:45): [True: 218, False: 21]
  ------------------
  842|       |		/* not a file, could be a path */
  843|    218|		bIsDF = 1;
  844|    218|		apdu.p1 = 0x1;
  845|    218|		apdu.p2 = 0x0;
  846|    218|		apdu.resplen = sizeof(resp);
  847|    218|		apdu.le = 256;
  848|    218|		apdu.lc = 2;
  849|    218|		r = sc_transmit_apdu(card, &apdu);
  850|    218|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|    218|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    218|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    218|	int _ret = (r); \
  |  |  |  |  168|    218|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 208]
  |  |  |  |  ------------------
  |  |  |  |  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|    218|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 208]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|  4.49k|	} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && !isMF)) {
  ------------------
  |  Branch (851:13): [True: 0, False: 4.49k]
  |  Branch (851:34): [True: 1.69k, False: 2.79k]
  |  Branch (851:54): [True: 1.62k, False: 74]
  |  Branch (851:74): [True: 950, False: 675]
  ------------------
  852|       |		/* SELECT returned some data (possible FCI) =>
  853|       |		 * try a READ BINARY to see if a EF is selected */
  854|    950|		sc_apdu_t apdu2;
  855|    950|		u8 resp2[2];
  856|    950|		sc_format_apdu(card, &apdu2, SC_APDU_CASE_2_SHORT, 0xB0, 0, 0);
  ------------------
  |  |  292|    950|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  857|    950|		apdu2.resp = (u8*)resp2;
  858|    950|		apdu2.resplen = 2;
  859|    950|		apdu2.le = 1;
  860|    950|		apdu2.lc = 0;
  861|    950|		r = sc_transmit_apdu(card, &apdu2);
  862|    950|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    950|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    950|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    950|	int _ret = (r); \
  |  |  |  |  168|    950|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 940]
  |  |  |  |  ------------------
  |  |  |  |  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|    950|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 940]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  863|    940|		if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86) {
  ------------------
  |  Branch (863:7): [True: 38, False: 902]
  |  Branch (863:28): [True: 18, False: 20]
  ------------------
  864|       |			/* no current EF is selected => we have a DF */
  865|     18|			bIsDF = 1;
  866|    922|		} else {
  867|    922|			isFCP = 1;
  868|    922|		}
  869|    940|	}
  870|       |
  871|  4.70k|	if (apdu.sw1 != 0x61 && (apdu.sw1 != 0x90 || apdu.sw2 != 0x00))
  ------------------
  |  Branch (871:6): [True: 4.70k, False: 0]
  |  Branch (871:27): [True: 2.81k, False: 1.88k]
  |  Branch (871:47): [True: 75, False: 1.81k]
  ------------------
  872|  2.89k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  2.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.89k|	int _ret = r; \
  |  |  155|  2.89k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.89k, False: 0]
  |  |  ------------------
  |  |  156|  2.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  2.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.89k, False: 0]
  |  |  ------------------
  |  |  157|  2.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.89k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.89k|	return _ret; \
  |  |  163|  2.89k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  873|       |
  874|  1.81k|	if (file_out) {
  ------------------
  |  Branch (874:6): [True: 678, False: 1.13k]
  ------------------
  875|    678|		sc_file_t *file = sc_file_new();
  876|    678|		if (!file)
  ------------------
  |  Branch (876:7): [True: 0, False: 678]
  ------------------
  877|    678|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    678|		file->id = (id_hi << 8) + id_lo;
  879|       |
  880|    678|		if (bIsDF || isMF) {
  ------------------
  |  Branch (880:7): [True: 206, False: 472]
  |  Branch (880:16): [True: 0, False: 472]
  ------------------
  881|       |			/* we have a DF */
  882|    206|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    206|#define SC_FILE_TYPE_DF			0x04
  ------------------
  883|    206|			file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    206|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  884|    206|			file->size = 0;
  885|    206|			file->namelen = 0;
  886|    206|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    206|#define SC_FILE_MAGIC			0x14426950
  ------------------
  887|    206|			*file_out = file;
  888|    472|		} else {
  889|       |			/* ok, assume we have a EF */
  890|    472|			if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    944|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    472|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 254, False: 218]
  |  |  |  |  |  Branch (119:65): [True: 75, False: 143]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    143|#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: 13, False: 130]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  891|    342|				if (isFCP) {
  ------------------
  |  Branch (891:9): [True: 342, False: 0]
  ------------------
  892|    342|					r = process_fcp_v3_4(card->ctx, file, apdu.resp,
  893|    342|							apdu.resplen);
  894|    342|				} else {
  895|      0|					r = process_fci_v3_4(card->ctx, file, apdu.resp,
  896|      0|							apdu.resplen);
  897|      0|				}
  898|    342|			} else {
  899|    130|				r = process_fci(card->ctx, file, apdu.resp,
  900|    130|						apdu.resplen);
  901|    130|			}
  902|    472|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    472|#define SC_SUCCESS				0
  ------------------
  |  Branch (902:8): [True: 183, False: 289]
  ------------------
  903|    183|				sc_file_free(file);
  904|    183|				return r;
  905|    183|			}
  906|       |
  907|    289|			*file_out = file;
  908|    289|		}
  909|    678|	}
  910|       |
  911|  1.63k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|  1.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.63k|	int _ret = r; \
  |  |  155|  1.63k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.63k, False: 0]
  |  |  ------------------
  |  |  156|  1.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 1.63k]
  |  |  ------------------
  |  |  157|  1.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.63k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.63k|	return _ret; \
  |  |  163|  1.63k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  912|  1.63k|}
card-starcos.c:process_fcp_v3_4:
  606|    342|{
  607|    342|	size_t taglen, len = buflen;
  608|    342|	const u8 *tag = NULL, *p;
  609|       |
  610|    342|	sc_log(ctx,
  ------------------
  |  |   71|    342|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  611|    342|		 "processing %"SC_FORMAT_LEN_SIZE_T"u FCP bytes\n", buflen);
  612|       |
  613|    342|	if (buflen < 2)
  ------------------
  |  Branch (613:6): [True: 42, False: 300]
  ------------------
  614|     42|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     42|#define SC_ERROR_INTERNAL			-1400
  ------------------
  615|    300|	if (buf[0] != 0x62)
  ------------------
  |  Branch (615:6): [True: 11, False: 289]
  ------------------
  616|     11|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     11|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  617|    289|	len = (size_t)buf[1];
  618|    289|	if (buflen - 2 < len)
  ------------------
  |  Branch (618:6): [True: 10, False: 279]
  ------------------
  619|     10|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     10|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  620|    279|	p = buf + 2;
  621|       |
  622|    279|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  623|    279|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (623:6): [True: 30, False: 249]
  |  Branch (623:21): [True: 16, False: 14]
  ------------------
  624|     16|		int bytes = (tag[0] << 8) + tag[1];
  625|     16|		sc_log(ctx,
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  626|     16|			"  bytes in file: %d\n", bytes);
  627|     16|		file->size = bytes;
  628|     16|	}
  629|       |
  630|    279|	tag = sc_asn1_find_tag(ctx, p, len, 0xc5, &taglen);
  631|    279|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (631:6): [True: 25, False: 254]
  |  Branch (631:21): [True: 13, False: 12]
  ------------------
  632|     13|		int bytes = (tag[0] << 8) + tag[1];
  633|     13|		sc_log(ctx,
  ------------------
  |  |   71|     13|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  634|     13|			"  bytes in file 2: %d\n", bytes);
  635|     13|		file->size = bytes;
  636|     13|	}
  637|       |
  638|    279|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  639|    279|	if (tag != NULL) {
  ------------------
  |  Branch (639:6): [True: 91, False: 188]
  ------------------
  640|     91|		const char *type = "unknown";
  641|     91|		const char *structure = "unknown";
  642|       |
  643|     91|		if (taglen >= 1) {
  ------------------
  |  Branch (643:7): [True: 76, False: 15]
  ------------------
  644|     76|			unsigned char byte = tag[0];
  645|     76|			if (byte & 0x40) {
  ------------------
  |  Branch (645:8): [True: 29, False: 47]
  ------------------
  646|     29|				file->shareable = 1;
  647|     29|			}
  648|     76|			if (byte == 0x38) {
  ------------------
  |  Branch (648:8): [True: 11, False: 65]
  ------------------
  649|     11|				type = "DF";
  650|     11|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     11|#define SC_FILE_TYPE_DF			0x04
  ------------------
  651|     11|				file->shareable = 1;
  652|     11|			}
  653|     76|			switch (byte & 7) {
  654|     14|			case 1:
  ------------------
  |  Branch (654:4): [True: 14, False: 62]
  ------------------
  655|       |				/* transparent EF */
  656|     14|				type = "working EF";
  657|     14|				structure = "transparent";
  658|     14|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     14|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  659|     14|				file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     14|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  660|     14|				break;
  661|     10|			case 2:
  ------------------
  |  Branch (661:4): [True: 10, False: 66]
  ------------------
  662|       |				/* linear fixed EF */
  663|     10|				type = "working EF";
  664|     10|				structure = "linear fixed";
  665|     10|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     10|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  666|     10|				file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     10|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  667|     10|				break;
  668|      6|			case 4:
  ------------------
  |  Branch (668:4): [True: 6, False: 70]
  ------------------
  669|       |				/* linear variable EF */
  670|      6|				type = "working EF";
  671|      6|				structure = "linear variable";
  672|      6|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      6|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  673|      6|				file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|      6|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  674|      6|				break;
  675|     23|			case 6:
  ------------------
  |  Branch (675:4): [True: 23, False: 53]
  ------------------
  676|       |				/* cyclic EF */
  677|     23|				type = "working EF";
  678|     23|				structure = "cyclic";
  679|     23|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     23|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  680|     23|				file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|     23|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  681|     23|				break;
  682|     23|			default:
  ------------------
  |  Branch (682:4): [True: 23, False: 53]
  ------------------
  683|       |				/* use defaults from above */
  684|     23|				break;
  685|     76|			}
  686|     76|		}
  687|     91|		sc_log(ctx,
  ------------------
  |  |   71|     91|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  688|     91|			"  type: %s\n", type);
  689|     91|		sc_log(ctx,
  ------------------
  |  |   71|     91|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  690|     91|			"  EF structure: %s\n", structure);
  691|     91|		if (taglen >= 2) {
  ------------------
  |  Branch (691:7): [True: 69, False: 22]
  ------------------
  692|     69|			if (tag[1] != 0x41 || taglen != 5) {
  ------------------
  |  Branch (692:8): [True: 52, False: 17]
  |  Branch (692:26): [True: 17, False: 0]
  ------------------
  693|     69|				SC_FUNC_RETURN(ctx, 2,SC_ERROR_INVALID_DATA);
  ------------------
  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     69|	int _ret = r; \
  |  |  155|     69|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  ------------------
  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 69, False: 0]
  |  |  ------------------
  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     69|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     69|	return _ret; \
  |  |  163|     69|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  694|     69|			}
  695|       |			/* formatted EF */
  696|      0|			file->record_length = (tag[2] << 8) + tag[3];
  697|      0|			file->record_count = tag[4];
  698|      0|			sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  699|      0|				"  rec_len: %"SC_FORMAT_LEN_SIZE_T"u  rec_cnt: %"SC_FORMAT_LEN_SIZE_T"u\n\n",
  700|      0|				file->record_length, file->record_count);
  701|      0|		}
  702|     91|	}
  703|       |
  704|    210|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
  705|    210|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (705:6): [True: 42, False: 168]
  |  Branch (705:21): [True: 16, False: 26]
  ------------------
  706|     16|		file->id = (tag[0] << 8) | tag[1];
  707|     16|		sc_log(ctx,  "  file identifier: 0x%02X%02X\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  708|     16|			tag[0], tag[1]);
  709|     16|	}
  710|       |
  711|    210|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
  712|    210|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (712:6): [True: 24, False: 186]
  |  Branch (712:21): [True: 12, False: 12]
  |  Branch (712:35): [True: 11, False: 1]
  ------------------
  713|     11|		memcpy(file->name, tag, taglen);
  714|     11|		file->namelen = taglen;
  715|     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__
  |  |  ------------------
  ------------------
  716|     11|			sc_dump_hex(file->name, file->namelen));
  717|     11|	}
  718|       |
  719|    210|	tag = sc_asn1_find_tag(ctx, p, len, 0x8a, &taglen);
  720|    210|	if (tag != NULL && taglen == 1) {
  ------------------
  |  Branch (720:6): [True: 53, False: 157]
  |  Branch (720:21): [True: 42, False: 11]
  ------------------
  721|     42|		char* status = "unknown";
  722|     42|		switch (tag[0]) {
  723|     10|		case 1:
  ------------------
  |  Branch (723:3): [True: 10, False: 32]
  ------------------
  724|     10|			status = "creation";
  725|     10|			file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     10|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  726|     10|			break;
  727|     10|		case 5:
  ------------------
  |  Branch (727:3): [True: 10, False: 32]
  ------------------
  728|     10|			status = "operational active";
  729|     10|			file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     10|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  730|     10|			break;
  731|      1|		case 12:
  ------------------
  |  Branch (731:3): [True: 1, False: 41]
  ------------------
  732|     11|		case 13:
  ------------------
  |  Branch (732:3): [True: 10, False: 32]
  ------------------
  733|     11|			status = "creation";
  734|     11|			file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     11|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  735|     11|			break;
  736|     11|		default:
  ------------------
  |  Branch (736:3): [True: 11, False: 31]
  ------------------
  737|     11|			break;
  738|     42|		}
  739|     42|		sc_log(ctx,  "  file status: %s\n", status);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  740|     42|	}
  741|       |
  742|    210|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    210|#define SC_FILE_MAGIC			0x14426950
  ------------------
  743|    210|	return SC_SUCCESS;
  ------------------
  |  |   28|    210|#define SC_SUCCESS				0
  ------------------
  744|    210|}
card-starcos.c:process_fci:
  478|    130|{
  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|    130|	size_t taglen, len = buflen;
  486|    130|	const u8 *tag = NULL, *p;
  487|       |
  488|    130|	sc_log(ctx,  "processing FCI bytes\n");
  ------------------
  |  |   71|    130|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  489|       |
  490|    130|	if (buflen < 2)
  ------------------
  |  Branch (490:6): [True: 21, False: 109]
  ------------------
  491|     21|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     21|#define SC_ERROR_INTERNAL			-1400
  ------------------
  492|    109|	if (buf[0] != 0x6f)
  ------------------
  |  Branch (492:6): [True: 18, False: 91]
  ------------------
  493|     18|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     18|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  494|     91|	len = (size_t)buf[1];
  495|     91|	if (buflen - 2 < len)
  ------------------
  |  Branch (495:6): [True: 12, False: 79]
  ------------------
  496|     12|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     12|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  497|     79|	p = buf + 2;
  498|       |
  499|       |	/* defaults */
  500|     79|	file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     79|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  501|     79|	file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     79|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  502|     79|	file->shareable = 0;
  503|     79|	file->record_length = 0;
  504|     79|	file->size = 0;
  505|       |
  506|     79|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  507|     79|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (507:6): [True: 16, False: 63]
  |  Branch (507:21): [True: 9, False: 7]
  ------------------
  508|      9|		int bytes = (tag[0] << 8) + tag[1];
  509|      9|		sc_log(ctx,
  ------------------
  |  |   71|      9|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  510|      9|			"  bytes in file: %d\n", bytes);
  511|      9|		file->size = bytes;
  512|      9|	}
  513|       |
  514|     79|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  515|     79|	if (tag != NULL) {
  ------------------
  |  Branch (515:6): [True: 45, False: 34]
  ------------------
  516|     45|		const char *type = "unknown";
  517|     45|		const char *structure = "unknown";
  518|       |
  519|     45|		if (taglen == 1 && tag[0] == 0x01) {
  ------------------
  |  Branch (519:7): [True: 16, False: 29]
  |  Branch (519:22): [True: 6, False: 10]
  ------------------
  520|       |			/* transparent EF */
  521|      6|			type = "working EF";
  522|      6|			structure = "transparent";
  523|      6|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      6|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  524|      6|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|      6|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  525|     39|		} else if (taglen == 1 && tag[0] == 0x11) {
  ------------------
  |  Branch (525:14): [True: 10, False: 29]
  |  Branch (525:29): [True: 6, False: 4]
  ------------------
  526|       |			/* object EF */
  527|      6|			type = "working EF";
  528|      6|			structure = "object";
  529|      6|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      6|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  530|      6|			file->ef_structure = SC_FILE_EF_TRANSPARENT; /* TODO */
  ------------------
  |  |  221|      6|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  531|     33|		} else if (taglen == 3 && tag[1] == 0x21) {
  ------------------
  |  Branch (531:14): [True: 27, False: 6]
  |  Branch (531:29): [True: 14, False: 13]
  ------------------
  532|     14|			type = "working EF";
  533|     14|			file->record_length = tag[2];
  534|     14|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     14|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  535|       |			/* linear fixed, cyclic or compute */
  536|     14|			switch ( tag[0] )
  537|     14|			{
  538|      6|				case 0x02:
  ------------------
  |  Branch (538:5): [True: 6, False: 8]
  ------------------
  539|      6|					structure = "linear fixed";
  540|      6|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|      6|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  541|      6|					break;
  542|      1|				case 0x07:
  ------------------
  |  Branch (542:5): [True: 1, False: 13]
  ------------------
  543|      1|					structure = "cyclic";
  544|      1|					file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|      1|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  545|      1|					break;
  546|      1|				case 0x17:
  ------------------
  |  Branch (546:5): [True: 1, False: 13]
  ------------------
  547|      1|					structure = "compute";
  548|      1|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      1|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  549|      1|					break;
  550|      6|				default:
  ------------------
  |  Branch (550:5): [True: 6, False: 8]
  ------------------
  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|     14|			}
  556|     14|		}
  557|       |
  558|     45|		sc_log(ctx,
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  559|     45|			"  type: %s\n", type);
  560|     45|		sc_log(ctx,
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  561|     45|			"  EF structure: %s\n", structure);
  562|     45|	}
  563|     79|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|     79|#define SC_FILE_MAGIC			0x14426950
  ------------------
  564|       |
  565|     79|	return SC_SUCCESS;
  ------------------
  |  |   28|     79|#define SC_SUCCESS				0
  ------------------
  566|     79|}
card-starcos.c:starcos_check_sw:
 1939|  9.33k|{
 1940|  9.33k|	const int err_count = sizeof(starcos_errors)/sizeof(starcos_errors[0]);
 1941|  9.33k|	int i;
 1942|       |
 1943|  9.33k|	sc_log(card->ctx,
  ------------------
  |  |   71|  9.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__
  |  |  ------------------
  ------------------
 1944|  9.33k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
 1945|       |
 1946|  9.33k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (1946:6): [True: 3.77k, False: 5.56k]
  |  Branch (1946:21): [True: 3.52k, False: 249]
  ------------------
 1947|  3.52k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.52k|#define SC_SUCCESS				0
  ------------------
 1948|  5.81k|	if (sw1 == 0x63 && (sw2 & ~0x0fU) == 0xc0 )
  ------------------
  |  Branch (1948:6): [True: 42, False: 5.77k]
  |  Branch (1948:21): [True: 18, False: 24]
  ------------------
 1949|     18|	{
 1950|     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__
  |  |  ------------------
  ------------------
 1951|     18|		(sw2 & 0x0f));
 1952|     18|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     18|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 1953|     18|	}
 1954|       |
 1955|       |	/* check starcos error messages */
 1956|  86.3k|	for (i = 0; i < err_count; i++)
  ------------------
  |  Branch (1956:14): [True: 80.5k, False: 5.74k]
  ------------------
 1957|  80.5k|		if (starcos_errors[i].SWs == ((sw1 << 8) | sw2))
  ------------------
  |  Branch (1957:7): [True: 47, False: 80.5k]
  ------------------
 1958|     47|		{
 1959|     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__
  |  |  ------------------
  ------------------
 1960|     47|			return starcos_errors[i].errorno;
 1961|     47|		}
 1962|       |
 1963|       |	/* iso error */
 1964|  5.74k|	return iso_ops->check_sw(card, sw1, sw2);
 1965|  5.79k|}
card-starcos.c:starcos_card_ctl:
 2014|     81|{
 2015|     81|	sc_starcos_create_data *tmp;
 2016|       |
 2017|     81|	switch (cmd)
 2018|     81|	{
 2019|      0|	case SC_CARDCTL_STARCOS_CREATE_FILE:
  ------------------
  |  Branch (2019:2): [True: 0, False: 81]
  ------------------
 2020|      0|		tmp = (sc_starcos_create_data *) ptr;
 2021|      0|		if (tmp->type == SC_STARCOS_MF_DATA)
  ------------------
  |  |  373|      0|#define	SC_STARCOS_MF_DATA	0x01
  ------------------
  |  Branch (2021:7): [True: 0, False: 0]
  ------------------
 2022|      0|			return starcos_create_mf(card, tmp);
 2023|      0|		else if (tmp->type == SC_STARCOS_DF_DATA)
  ------------------
  |  |  374|      0|#define SC_STARCOS_DF_DATA	0x02
  ------------------
  |  Branch (2023:12): [True: 0, False: 0]
  ------------------
 2024|      0|			return starcos_create_df(card, tmp);
 2025|      0|		else if (tmp->type == SC_STARCOS_EF_DATA)
  ------------------
  |  |  375|      0|#define SC_STARCOS_EF_DATA	0x04
  ------------------
  |  Branch (2025:12): [True: 0, False: 0]
  ------------------
 2026|      0|			return starcos_create_ef(card, tmp);
 2027|      0|		else
 2028|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2029|      0|	case SC_CARDCTL_STARCOS_CREATE_END:
  ------------------
  |  Branch (2029:2): [True: 0, False: 81]
  ------------------
 2030|      0|		return starcos_create_end(card, (sc_file_t *)ptr);
 2031|      0|	case SC_CARDCTL_STARCOS_WRITE_KEY:
  ------------------
  |  Branch (2031:2): [True: 0, False: 81]
  ------------------
 2032|      0|		return starcos_write_key(card, (sc_starcos_wkey_data *)ptr);
 2033|      0|	case SC_CARDCTL_STARCOS_GENERATE_KEY:
  ------------------
  |  Branch (2033:2): [True: 0, False: 81]
  ------------------
 2034|      0|		return starcos_gen_key(card, (sc_starcos_gen_key_data *)ptr);
 2035|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (2035:2): [True: 0, False: 81]
  ------------------
 2036|      0|		return starcos_erase_card(card);
 2037|     81|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2037:2): [True: 81, False: 0]
  ------------------
 2038|     81|		return starcos_get_serialnr(card, (sc_serial_number_t *)ptr);
 2039|      0|	default:
  ------------------
  |  Branch (2039:2): [True: 0, False: 81]
  ------------------
 2040|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2041|     81|	}
 2042|     81|}
card-starcos.c:starcos_get_serialnr:
 1968|     81|{
 1969|     81|	int r;
 1970|     81|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1971|     81|	sc_apdu_t apdu;
 1972|       |
 1973|     81|	if (!serial)
  ------------------
  |  Branch (1973:6): [True: 0, False: 81]
  ------------------
 1974|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1975|       |
 1976|       |	/* see if we have cached serial number */
 1977|     81|	if (card->serialnr.len) {
  ------------------
  |  Branch (1977:6): [True: 2, False: 79]
  ------------------
 1978|      2|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1979|      2|		return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 1980|      2|	}
 1981|       |
 1982|     79|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    158|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|     79|#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: 75]
  |  |  |  |  |  Branch (119:65): [True: 31, False: 44]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     44|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 1, False: 43]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|     36|		card->serialnr.len = SC_MAX_SERIALNR;
  ------------------
  |  |  372|     36|#define SC_MAX_SERIALNR         32
  ------------------
 1984|     36|		r = sc_parse_ef_gdo(card, card->serialnr.value, &card->serialnr.len, NULL, 0);
 1985|     36|		if (r < 0) {
  ------------------
  |  Branch (1985:7): [True: 35, False: 1]
  ------------------
 1986|     35|			card->serialnr.len = 0;
 1987|     35|			return r;
 1988|     35|		}
 1989|     43|	} else {
 1990|       |		/* get serial number via GET CARD DATA */
 1991|     43|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xf6, 0x00, 0x00);
  ------------------
  |  |  292|     43|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1992|     43|		apdu.cla |= 0x80;
 1993|     43|		apdu.resp = rbuf;
 1994|     43|		apdu.resplen = sizeof(rbuf);
 1995|     43|		apdu.le   = 256;
 1996|     43|		apdu.lc   = 0;
 1997|     43|		apdu.datalen = 0;
 1998|     43|		r = sc_transmit_apdu(card, &apdu);
 1999|     43|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     43|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     43|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     43|	int _ret = (r); \
  |  |  |  |  168|     43|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2000|     40|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (2000:7): [True: 7, False: 33]
  |  Branch (2000:27): [True: 3, False: 30]
  ------------------
 2001|     10|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     10|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2002|       |		/* cache serial number */
 2003|     30|		memcpy(card->serialnr.value, apdu.resp, MIN(apdu.resplen, SC_MAX_SERIALNR));
  ------------------
  |  |   70|     30|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 28, False: 2]
  |  |  ------------------
  ------------------
 2004|     30|		card->serialnr.len = MIN(apdu.resplen, SC_MAX_SERIALNR);
  ------------------
  |  |   70|     30|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 28, False: 2]
  |  |  ------------------
  ------------------
 2005|     30|	}
 2006|       |
 2007|       |	/* copy and return serial number */
 2008|     31|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2009|       |
 2010|     31|	return SC_SUCCESS;
  ------------------
  |  |   28|     31|#define SC_SUCCESS				0
  ------------------
 2011|     79|}
card-starcos.c:starcos_pin_cmd:
 2079|     28|{
 2080|     28|	int r;
 2081|       |
 2082|     28|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     28|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     28|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     28|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     28|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2083|     28|	starcos_ex_data * ex_data = (starcos_ex_data*)card->drv_data;
 2084|     28|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|     56|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|     28|#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: 24]
  |  |  |  |  |  Branch (119:65): [True: 8, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     16|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 1, False: 15]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2085|     13|		data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|     13|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 2086|     13|		data->pin1.encoding = ex_data->pin_encoding;
 2087|     13|	}
 2088|     28|	r = iso_ops->pin_cmd(card, data);
 2089|     28|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     28|	int _ret = r; \
  |  |  155|     28|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  ------------------
  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 20, False: 8]
  |  |  ------------------
  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     28|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     28|	return _ret; \
  |  |  163|     28|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2090|     28|}

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

sc_check_sw:
   45|   463k|{
   46|   463k|	if (card == NULL)
  ------------------
  |  Branch (46:6): [True: 0, False: 463k]
  ------------------
   47|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   48|   463k|	if (card->ops->check_sw == NULL)
  ------------------
  |  Branch (48:6): [True: 0, False: 463k]
  ------------------
   49|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
   50|   463k|	return card->ops->check_sw(card, sw1, sw2);
   51|   463k|}
sc_format_apdu:
   55|   530k|{
   56|   530k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (56:6): [True: 0, False: 530k]
  |  Branch (56:22): [True: 0, False: 530k]
  ------------------
   57|      0|		return;
   58|      0|	}
   59|   530k|	memset(apdu, 0, sizeof(*apdu));
   60|   530k|	apdu->cla = (u8) card->cla;
   61|   530k|	apdu->cse = cse;
   62|   530k|	apdu->ins = (u8) ins;
   63|   530k|	apdu->p1 = (u8) p1;
   64|   530k|	apdu->p2 = (u8) p2;
   65|   530k|}
sc_format_apdu_cse_lc_le:
   68|  7.25k|{
   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|  7.25k|	if (!apdu)
  ------------------
  |  Branch (73:6): [True: 0, False: 7.25k]
  ------------------
   74|      0|		return;
   75|  7.25k|	if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
  ------------------
  |  |   35|  14.5k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (75:6): [True: 0, False: 7.25k]
  ------------------
   76|  7.25k|			|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|  7.25k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (76:7): [True: 90, False: 7.16k]
  ------------------
   77|       |		/* extended length  or data chaining and/or get response */
   78|     90|		if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
  ------------------
  |  |   38|     90|#define SC_MAX_EXT_APDU_DATA_SIZE		0xFFFF
  ------------------
  |  Branch (78:7): [True: 90, False: 0]
  ------------------
   79|     90|			apdu->lc = apdu->datalen;
   80|     90|		if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
  ------------------
  |  |   39|     90|#define SC_MAX_EXT_APDU_RESP_SIZE		(0xFFFF+1)
  ------------------
  |  Branch (80:7): [True: 90, False: 0]
  ------------------
   81|     90|			apdu->le = apdu->resplen;
   82|     90|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (82:7): [True: 90, False: 0]
  |  Branch (82:24): [True: 90, False: 0]
  ------------------
   83|     90|			apdu->cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|     90|#define SC_APDU_CASE_2			0x22
  ------------------
   84|     90|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (84:7): [True: 0, False: 90]
  |  Branch (84:25): [True: 0, False: 0]
  ------------------
   85|      0|			apdu->cse = SC_APDU_CASE_3;
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
   86|     90|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (86:7): [True: 90, False: 0]
  |  Branch (86:24): [True: 0, False: 90]
  ------------------
   87|      0|			apdu->cse = SC_APDU_CASE_4;
  ------------------
  |  |  303|      0|#define SC_APDU_CASE_4			0x24
  ------------------
   88|  7.16k|	} else {
   89|       |		/* short length */
   90|  7.16k|		if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
  ------------------
  |  |   35|  7.16k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (90:7): [True: 7.16k, False: 0]
  ------------------
   91|  7.16k|			apdu->lc = apdu->datalen;
   92|  7.16k|		if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
  ------------------
  |  |   36|  7.16k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (92:7): [True: 7.16k, False: 0]
  ------------------
   93|  7.16k|			apdu->le = apdu->resplen;
   94|  7.16k|		if (!apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (94:7): [True: 2.61k, False: 4.55k]
  |  Branch (94:25): [True: 0, False: 2.61k]
  ------------------
   95|      0|			apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
   96|  7.16k|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (96:7): [True: 4.55k, False: 2.61k]
  |  Branch (96:24): [True: 1.96k, False: 2.59k]
  ------------------
   97|  1.96k|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  1.96k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   98|  7.16k|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (98:7): [True: 2.61k, False: 4.55k]
  |  Branch (98:25): [True: 2.61k, False: 0]
  ------------------
   99|  2.61k|			apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  2.61k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  100|  7.16k|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (100:7): [True: 4.55k, False: 2.61k]
  |  Branch (100:24): [True: 2.59k, False: 1.96k]
  ------------------
  101|  2.59k|			apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  2.59k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  102|  7.16k|	}
  103|  7.25k|}
sc_format_apdu_ex:
  109|  7.25k|{
  110|  7.25k|	if (!apdu) {
  ------------------
  |  Branch (110:6): [True: 0, False: 7.25k]
  ------------------
  111|      0|		return;
  112|      0|	}
  113|       |
  114|  7.25k|	memset(apdu, 0, sizeof(*apdu));
  115|  7.25k|	apdu->cla = cla;
  116|  7.25k|	apdu->ins = ins;
  117|  7.25k|	apdu->p1 = p1;
  118|  7.25k|	apdu->p2 = p2;
  119|  7.25k|	apdu->resp = resp;
  120|  7.25k|	apdu->resplen = resplen;
  121|  7.25k|	apdu->data = data;
  122|  7.25k|	apdu->datalen = datalen;
  123|  7.25k|	sc_format_apdu_cse_lc_le(apdu);
  124|  7.25k|}
sc_get_max_recv_size:
  188|   325k|{
  189|   325k|	size_t max_recv_size;
  190|   325k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (190:6): [True: 0, False: 325k]
  |  Branch (190:22): [True: 0, False: 325k]
  ------------------
  191|      0|		return 0;
  192|      0|	}
  193|   325k|	max_recv_size = card->max_recv_size;
  194|       |
  195|       |	/* initialize max_recv_size to a meaningful value */
  196|   325k|	if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  554|   325k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (196:6): [True: 52.2k, False: 273k]
  ------------------
  197|  52.2k|		if (!max_recv_size)
  ------------------
  |  Branch (197:7): [True: 2.08k, False: 50.1k]
  ------------------
  198|  2.08k|			max_recv_size = 65536;
  199|   273k|	} else {
  200|   273k|		if (!max_recv_size)
  ------------------
  |  Branch (200:7): [True: 158k, False: 114k]
  ------------------
  201|   158k|			max_recv_size = 256;
  202|   273k|	}
  203|       |
  204|       |	/*  Override card limitations with reader limitations. */
  205|   325k|	if (card->reader->max_recv_size != 0
  ------------------
  |  Branch (205:6): [True: 7.09k, False: 318k]
  ------------------
  206|  7.09k|			&& (card->reader->max_recv_size < card->max_recv_size))
  ------------------
  |  Branch (206:7): [True: 0, False: 7.09k]
  ------------------
  207|      0|		max_recv_size = card->reader->max_recv_size;
  208|       |
  209|   325k|	return max_recv_size;
  210|   325k|}
sc_get_max_send_size:
  213|  96.5k|{
  214|  96.5k|	size_t max_send_size;
  215|       |
  216|  96.5k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (216:6): [True: 0, False: 96.5k]
  |  Branch (216:22): [True: 0, False: 96.5k]
  ------------------
  217|      0|		return 0;
  218|      0|	}
  219|       |
  220|  96.5k|	max_send_size = card->max_send_size;
  221|       |
  222|       |	/* initialize max_send_size to a meaningful value */
  223|  96.5k|	if (card->caps & SC_CARD_CAP_APDU_EXT
  ------------------
  |  |  554|   193k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (223:6): [True: 29.6k, False: 66.9k]
  ------------------
  224|  29.6k|			&& card->reader->active_protocol != SC_PROTO_T0) {
  ------------------
  |  |  359|  29.6k|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (224:7): [True: 29.6k, False: 0]
  ------------------
  225|  29.6k|		if (!max_send_size)
  ------------------
  |  Branch (225:7): [True: 1.11k, False: 28.5k]
  ------------------
  226|  1.11k|			max_send_size = 65535;
  227|  66.9k|	} else {
  228|  66.9k|		if (!max_send_size)
  ------------------
  |  Branch (228:7): [True: 12.1k, False: 54.7k]
  ------------------
  229|  12.1k|			max_send_size = 255;
  230|  66.9k|	}
  231|       |
  232|       |	/*  Override card limitations with reader limitations. */
  233|  96.5k|	if (card->reader->max_send_size != 0
  ------------------
  |  Branch (233:6): [True: 0, False: 96.5k]
  ------------------
  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|  96.5k|	return max_send_size;
  238|  96.5k|}
sc_connect_card:
  241|  15.0k|{
  242|  15.0k|	sc_card_t *card;
  243|  15.0k|	sc_context_t *ctx;
  244|  15.0k|	struct sc_card_driver *driver;
  245|  15.0k|	int i, r = 0, idx, connected = 0;
  246|       |
  247|  15.0k|	if (card_out == NULL || reader == NULL)
  ------------------
  |  Branch (247:6): [True: 0, False: 15.0k]
  |  Branch (247:26): [True: 0, False: 15.0k]
  ------------------
  248|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  249|  15.0k|	ctx = reader->ctx;
  250|  15.0k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.0k]
  |  |  ------------------
  ------------------
  251|  15.0k|	if (reader->ops->connect == NULL)
  ------------------
  |  Branch (251:6): [True: 0, False: 15.0k]
  ------------------
  252|  15.0k|		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.0k|	card = sc_card_new(ctx);
  255|  15.0k|	if (card == NULL)
  ------------------
  |  Branch (255:6): [True: 0, False: 15.0k]
  ------------------
  256|  15.0k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|  15.0k|	r = reader->ops->connect(reader);
  258|  15.0k|	if (r)
  ------------------
  |  Branch (258:6): [True: 0, False: 15.0k]
  ------------------
  259|      0|		goto err;
  260|       |
  261|  15.0k|	connected = 1;
  262|  15.0k|	card->reader = reader;
  263|  15.0k|	card->ctx = ctx;
  264|       |
  265|  15.0k|	if (reader->flags & SC_READER_ENABLE_ESCAPE)
  ------------------
  |  |  379|  15.0k|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (265:6): [True: 0, False: 15.0k]
  ------------------
  266|      0|		sc_detect_escape_cmds(reader);
  267|       |
  268|  15.0k|	memcpy(&card->atr, &reader->atr, sizeof(card->atr));
  269|  15.0k|	memcpy(&card->uid, &reader->uid, sizeof(card->uid));
  270|       |
  271|  15.0k|	_sc_parse_atr(reader);
  272|       |
  273|       |	/* See if the ATR matches any ATR specified in the config file */
  274|  15.0k|	if ((driver = ctx->forced_driver) == NULL) {
  ------------------
  |  Branch (274:6): [True: 15.0k, False: 0]
  ------------------
  275|  15.0k|		sc_log(ctx, "matching configured ATRs");
  ------------------
  |  |   71|  15.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__
  |  |  ------------------
  ------------------
  276|   675k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (276:15): [True: 660k, False: 15.0k]
  ------------------
  277|   660k|			driver = ctx->card_drivers[i];
  278|       |
  279|   660k|			if (driver->atr_map == NULL ||
  ------------------
  |  Branch (279:8): [True: 660k, False: 0]
  ------------------
  280|   660k|			    !strcmp(driver->short_name, "default")) {
  ------------------
  |  Branch (280:8): [True: 0, False: 0]
  ------------------
  281|   660k|				driver = NULL;
  282|   660k|				continue;
  283|   660k|			}
  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.0k|	}
  299|       |
  300|  15.0k|	if (driver != NULL) {
  ------------------
  |  Branch (300:6): [True: 0, False: 15.0k]
  ------------------
  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.0k|	else {
  318|  15.0k|		sc_card_t uninitialized = *card;
  319|  15.0k|		sc_log(ctx, "matching built-in ATRs");
  ------------------
  |  |   71|  15.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__
  |  |  ------------------
  ------------------
  320|   362k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (320:15): [True: 360k, False: 2.35k]
  ------------------
  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|   360k|			*card = uninitialized;
  333|       |
  334|   360k|			struct sc_card_driver *drv = ctx->card_drivers[i];
  335|   360k|			const struct sc_card_operations *ops = drv->ops;
  336|       |
  337|   360k|			sc_log(ctx, "trying driver '%s'", drv->short_name);
  ------------------
  |  |   71|   360k|#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|   360k|			if (ops == NULL || ops->match_card == NULL)   {
  ------------------
  |  Branch (338:8): [True: 0, False: 360k]
  |  Branch (338:23): [True: 0, False: 360k]
  ------------------
  339|      0|				continue;
  340|      0|			}
  341|   360k|			else if (!(ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER)
  ------------------
  |  |  867|   360k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  |  Branch (341:13): [True: 360k, False: 0]
  ------------------
  342|   360k|				   	&& !strcmp("default", drv->short_name))   {
  ------------------
  |  Branch (342:12): [True: 2.35k, False: 358k]
  ------------------
  343|  2.35k|				sc_log(ctx , "ignore 'default' card driver");
  ------------------
  |  |   71|  2.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  344|  2.35k|				continue;
  345|  2.35k|			}
  346|       |
  347|       |			/* Needed if match_card() needs to talk with the card (e.g. card-muscle) */
  348|   358k|			*card->ops = *ops;
  349|   358k|			if (ops->match_card(card) != 1)
  ------------------
  |  Branch (349:8): [True: 344k, False: 13.5k]
  ------------------
  350|   344k|				continue;
  351|  13.5k|			sc_log(ctx, "matched: %s", drv->name);
  ------------------
  |  |   71|  13.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  352|  13.5k|			memcpy(card->ops, ops, sizeof(struct sc_card_operations));
  353|  13.5k|			card->driver = drv;
  354|  13.5k|			r = ops->init(card);
  355|  13.5k|			if (r) {
  ------------------
  |  Branch (355:8): [True: 1.63k, False: 11.9k]
  ------------------
  356|  1.63k|				sc_log(ctx, "driver '%s' init() failed: %s", drv->name, sc_strerror(r));
  ------------------
  |  |   71|  1.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  357|  1.63k|				if (r == SC_ERROR_INVALID_CARD) {
  ------------------
  |  |   60|  1.63k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (357:9): [True: 881, False: 753]
  ------------------
  358|    881|					card->driver = NULL;
  359|    881|					continue;
  360|    881|				}
  361|    753|				goto err;
  362|  1.63k|			}
  363|  11.9k|			break;
  364|  13.5k|		}
  365|  15.0k|	}
  366|  14.2k|	if (card->driver == NULL) {
  ------------------
  |  Branch (366:6): [True: 2.35k, False: 11.9k]
  ------------------
  367|  2.35k|		sc_log(ctx, "unable to find driver for inserted card");
  ------------------
  |  |   71|  2.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  368|  2.35k|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  2.35k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  369|  2.35k|		goto err;
  370|  2.35k|	}
  371|  11.9k|	if (card->name == NULL)
  ------------------
  |  Branch (371:6): [True: 2.55k, False: 9.35k]
  ------------------
  372|  2.55k|		card->name = card->driver->name;
  373|       |
  374|       |	/* initialize max_send_size/max_recv_size to a meaningful value */
  375|  11.9k|	card->max_recv_size = sc_get_max_recv_size(card);
  376|  11.9k|	card->max_send_size = sc_get_max_send_size(card);
  377|       |
  378|  11.9k|	sc_log(ctx,
  ------------------
  |  |   71|  11.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  379|  11.9k|	       "card info name:'%s', type:%i, flags:0x%lX, max_send/recv_size:%"SC_FORMAT_LEN_SIZE_T"u/%"SC_FORMAT_LEN_SIZE_T"u",
  380|  11.9k|	       card->name, card->type, card->flags, card->max_send_size,
  381|  11.9k|	       card->max_recv_size);
  382|       |
  383|  11.9k|#ifdef ENABLE_SM
  384|       |        /* Check, if secure messaging module present. */
  385|  11.9k|	r = sc_card_sm_check(card);
  386|  11.9k|	if (r)   {
  ------------------
  |  Branch (386:6): [True: 0, False: 11.9k]
  ------------------
  387|      0|		sc_log(ctx, "cannot load secure messaging module");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  388|      0|		goto err;
  389|      0|	}
  390|  11.9k|#endif
  391|  11.9k|	*card_out = card;
  392|       |
  393|  11.9k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  11.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.9k|	int _ret = r; \
  |  |  |  |  155|  11.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 11.9k]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.9k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.9k|	return _ret; \
  |  |  |  |  163|  11.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|  3.10k|err:
  395|  3.10k|	if (connected)
  ------------------
  |  Branch (395:6): [True: 3.10k, False: 0]
  ------------------
  396|  3.10k|		reader->ops->disconnect(reader);
  397|  3.10k|	if (card != NULL)
  ------------------
  |  Branch (397:6): [True: 3.10k, False: 0]
  ------------------
  398|  3.10k|		sc_card_free(card);
  399|  3.10k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  3.10k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.10k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.10k|	int _ret = r; \
  |  |  |  |  155|  3.10k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.10k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.10k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.10k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.10k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.10k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.10k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.10k|	return _ret; \
  |  |  |  |  163|  3.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  400|  3.10k|}
sc_disconnect_card:
  403|  15.0k|{
  404|  15.0k|	sc_context_t *ctx;
  405|       |
  406|  15.0k|	if (!card)
  ------------------
  |  Branch (406:6): [True: 3.10k, False: 11.9k]
  ------------------
  407|  3.10k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  3.10k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  408|       |
  409|  11.9k|	ctx = card->ctx;
  410|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  411|       |
  412|  11.9k|	if (card->ops->finish) {
  ------------------
  |  Branch (412:6): [True: 11.0k, False: 841]
  ------------------
  413|  11.0k|		int r = card->ops->finish(card);
  414|  11.0k|		if (r)
  ------------------
  |  Branch (414:7): [True: 467, False: 10.5k]
  ------------------
  415|    467|			sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|    467|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  416|  11.0k|	}
  417|       |
  418|  11.9k|	if (card->reader->ops->disconnect) {
  ------------------
  |  Branch (418:6): [True: 11.9k, False: 0]
  ------------------
  419|  11.9k|		int r = card->reader->ops->disconnect(card->reader);
  420|  11.9k|		if (r)
  ------------------
  |  Branch (420:7): [True: 0, False: 11.9k]
  ------------------
  421|      0|			sc_log(ctx, "disconnect() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  422|  11.9k|	}
  423|       |
  424|  11.9k|#ifdef ENABLE_SM
  425|       |	/* release SM related resources */
  426|  11.9k|	sc_card_sm_unload(card);
  427|  11.9k|#endif
  428|       |
  429|  11.9k|	sc_card_free(card);
  430|  11.9k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  11.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.9k|	int _ret = r; \
  |  |  |  |  155|  11.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 11.9k]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.9k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.9k|	return _ret; \
  |  |  |  |  163|  11.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  11.9k|}
sc_lock:
  458|   607k|{
  459|   607k|	int r = 0, r2 = 0;
  460|   607k|	int was_reset = 0;
  461|   607k|	int reader_lock_obtained  = 0;
  462|       |
  463|   607k|	if (card == NULL)
  ------------------
  |  Branch (463:6): [True: 0, False: 607k]
  ------------------
  464|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  465|       |
  466|   607k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   607k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   607k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   607k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   607k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 607k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|       |
  468|   607k|	r = sc_mutex_lock(card->ctx, card->mutex);
  469|   607k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   607k|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 0, False: 607k]
  ------------------
  470|      0|		return r;
  471|   607k|	if (card->lock_count == 0) {
  ------------------
  |  Branch (471:6): [True: 254k, False: 353k]
  ------------------
  472|   254k|		if (card->reader->ops->lock != NULL) {
  ------------------
  |  Branch (472:7): [True: 254k, False: 0]
  ------------------
  473|   254k|			r = card->reader->ops->lock(card->reader);
  474|   254k|			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   508k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   254k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (474:11): [True: 0, False: 254k]
  |  Branch (474:39): [True: 0, False: 254k]
  ------------------
  475|      0|				if (was_reset++ > 4) /* TODO retry a few times */
  ------------------
  |  Branch (475:9): [True: 0, False: 0]
  ------------------
  476|      0|					break;
  477|      0|				r = card->reader->ops->lock(card->reader);
  478|      0|			}
  479|   254k|			if (r == 0)
  ------------------
  |  Branch (479:8): [True: 254k, False: 0]
  ------------------
  480|   254k|				reader_lock_obtained = 1;
  481|   254k|		}
  482|   254k|	}
  483|   607k|	if (r == 0)
  ------------------
  |  Branch (483:6): [True: 607k, False: 0]
  ------------------
  484|   607k|		card->lock_count++;
  485|       |
  486|   607k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  487|   607k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   607k|#define SC_SUCCESS				0
  ------------------
  |  Branch (487:6): [True: 0, False: 607k]
  ------------------
  488|      0|		sc_log(card->ctx, "unable to release card->mutex lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  489|      0|		r = r != SC_SUCCESS ? r : r2;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (489:7): [True: 0, False: 0]
  ------------------
  490|      0|	}
  491|       |
  492|   607k|	if (r == 0 && was_reset > 0) {
  ------------------
  |  Branch (492:6): [True: 607k, False: 0]
  |  Branch (492:16): [True: 0, False: 607k]
  ------------------
  493|      0|#ifdef ENABLE_SM
  494|      0|		if (card->sm_ctx.ops.open)
  ------------------
  |  Branch (494:7): [True: 0, False: 0]
  ------------------
  495|      0|			card->sm_ctx.ops.open(card);
  496|      0|#endif
  497|      0|	}
  498|       |
  499|       |	/* give card driver a chance to do something when reader lock first obtained */
  500|   607k|	if (r == 0 && reader_lock_obtained == 1  && card->ops->card_reader_lock_obtained) {
  ------------------
  |  Branch (500:6): [True: 607k, False: 0]
  |  Branch (500:16): [True: 254k, False: 353k]
  |  Branch (500:46): [True: 55.4k, False: 198k]
  ------------------
  501|  55.4k|		if (SC_SUCCESS != card->ops->card_reader_lock_obtained(card, was_reset))
  ------------------
  |  |   28|  55.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (501:7): [True: 502, False: 54.9k]
  ------------------
  502|    502|			sc_log(card->ctx, "card_reader_lock_obtained failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  503|  55.4k|	}
  504|       |
  505|   607k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   607k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   607k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   607k|	int _ret = r; \
  |  |  |  |  155|   607k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 607k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   607k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 607k]
  |  |  |  |  ------------------
  |  |  |  |  157|   607k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   607k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   607k|	return _ret; \
  |  |  |  |  163|   607k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  506|   607k|}
sc_unlock:
  509|   607k|{
  510|   607k|	int r, r2;
  511|       |
  512|   607k|	if (!card)
  ------------------
  |  Branch (512:6): [True: 0, False: 607k]
  ------------------
  513|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  514|       |
  515|   607k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   607k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   607k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   607k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   607k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 607k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|       |
  517|   607k|	r = sc_mutex_lock(card->ctx, card->mutex);
  518|   607k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   607k|#define SC_SUCCESS				0
  ------------------
  |  Branch (518:6): [True: 0, False: 607k]
  ------------------
  519|   607k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|       |
  521|   607k|	if (card->lock_count < 1) {
  ------------------
  |  Branch (521:6): [True: 0, False: 607k]
  ------------------
  522|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  523|      0|	}
  524|   607k|	if (--card->lock_count == 0) {
  ------------------
  |  Branch (524:6): [True: 254k, False: 353k]
  ------------------
  525|       |		/* release reader lock */
  526|   254k|		if (card->reader->ops->unlock != NULL)
  ------------------
  |  Branch (526:7): [True: 254k, False: 0]
  ------------------
  527|   254k|			r = card->reader->ops->unlock(card->reader);
  528|   254k|	}
  529|   607k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  530|   607k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   607k|#define SC_SUCCESS				0
  ------------------
  |  Branch (530:6): [True: 0, False: 607k]
  ------------------
  531|      0|		sc_log(card->ctx, "unable to release lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  532|      0|		r = (r == SC_SUCCESS) ? r2 : r;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (532:7): [True: 0, False: 0]
  ------------------
  533|      0|	}
  534|       |
  535|   607k|	return r;
  536|   607k|}
sc_read_binary:
  607|  10.6k|{
  608|  10.6k|	size_t max_le = sc_get_max_recv_size(card);
  609|  10.6k|	size_t todo = count;
  610|  10.6k|	int r;
  611|       |
  612|  10.6k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (612:6): [True: 0, False: 10.6k]
  |  Branch (612:22): [True: 0, False: 10.6k]
  |  Branch (612:43): [True: 0, False: 10.6k]
  ------------------
  613|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  614|      0|	}
  615|  10.6k|	sc_log(card->ctx, "called; %"SC_FORMAT_LEN_SIZE_T"u bytes at index %d",
  ------------------
  |  |   71|  10.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  616|  10.6k|	       count, idx);
  617|  10.6k|	if (count == 0)
  ------------------
  |  Branch (617:6): [True: 414, False: 10.2k]
  ------------------
  618|  10.6k|		LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|       |
  620|  10.2k|#ifdef ENABLE_SM
  621|  10.2k|	if (card->sm_ctx.ops.read_binary)   {
  ------------------
  |  Branch (621:6): [True: 259, False: 9.99k]
  ------------------
  622|    259|		r = card->sm_ctx.ops.read_binary(card, idx, buf, count);
  623|    259|		if (r)
  ------------------
  |  Branch (623:7): [True: 178, False: 81]
  ------------------
  624|    259|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    178|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    178|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    178|	int _ret = r; \
  |  |  |  |  155|    178|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 178, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    178|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    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|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    178|	return _ret; \
  |  |  |  |  163|    178|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|    259|	}
  626|  10.0k|#endif
  627|       |
  628|  10.0k|	if (card->ops->read_binary == NULL)
  ------------------
  |  Branch (628:6): [True: 0, False: 10.0k]
  ------------------
  629|  10.0k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|       |
  631|       |	/* lock the card now to avoid deselection of the file */
  632|  10.0k|	r = sc_lock(card);
  633|  10.0k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  10.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  10.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  10.0k|	int _ret = (r); \
  |  |  |  |  168|  10.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 10.0k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  10.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  634|       |
  635|  60.8k|	while (todo > 0) {
  ------------------
  |  Branch (635:9): [True: 58.5k, False: 2.32k]
  ------------------
  636|  58.5k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  58.5k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 11.4k, False: 47.1k]
  |  |  ------------------
  ------------------
  637|       |
  638|  58.5k|		r = card->ops->read_binary(card, idx, buf, chunk, flags);
  639|  58.5k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  56.6k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (639:7): [True: 1.88k, False: 56.6k]
  |  Branch (639:17): [True: 35, False: 56.6k]
  ------------------
  640|  1.92k|			break;
  641|  56.6k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (641:7): [True: 5.82k, False: 50.7k]
  |  Branch (641:16): [True: 3.97k, False: 1.84k]
  ------------------
  642|       |			/* the last command failed, but previous ones succeeded.
  643|       |			 * Let's just return what we've successfully read. */
  644|  3.97k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  645|  3.97k|			break;
  646|  3.97k|		}
  647|  52.6k|		if (r < 0) {
  ------------------
  |  Branch (647:7): [True: 1.84k, False: 50.7k]
  ------------------
  648|  1.84k|			sc_unlock(card);
  649|  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|  1.84k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.84k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|  1.84k|		}
  651|  50.7k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (651:7): [True: 0, False: 50.7k]
  |  Branch (651:40): [True: 0, False: 50.7k]
  ------------------
  652|       |			/* `idx + r` or `todo - r` would overflow */
  653|      0|			sc_unlock(card);
  654|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OFFSET_TOO_LARGE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  655|      0|		}
  656|       |
  657|  50.7k|		todo -= (size_t) r;
  658|  50.7k|		buf  += (size_t) r;
  659|  50.7k|		idx  += (size_t) r;
  660|  50.7k|	}
  661|       |
  662|  8.22k|	sc_unlock(card);
  663|       |
  664|  8.22k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  8.22k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.22k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.22k|	int _ret = r; \
  |  |  |  |  155|  8.22k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.09k, False: 7.12k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.09k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.12k|	} else { \
  |  |  |  |  159|  7.12k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  7.12k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  7.12k|	} \
  |  |  |  |  162|  8.22k|	return _ret; \
  |  |  |  |  163|  8.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  665|  8.22k|}
sc_select_file:
  818|  89.4k|{
  819|  89.4k|	int r;
  820|  89.4k|	char pbuf[SC_MAX_PATH_STRING_SIZE];
  821|       |
  822|  89.4k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (822:6): [True: 0, False: 89.4k]
  |  Branch (822:22): [True: 0, False: 89.4k]
  ------------------
  823|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  824|      0|	}
  825|       |
  826|  89.4k|	r = sc_path_print(pbuf, sizeof(pbuf), in_path);
  827|  89.4k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  89.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (827:6): [True: 67, False: 89.3k]
  ------------------
  828|     67|		pbuf[0] = '\0';
  829|       |
  830|       |	/* FIXME We should be a bit less strict and let the upper layers do
  831|       |	 * the initialization (including reuse of existing file objects). We
  832|       |	 * implemented this here because we are lazy. */
  833|  89.4k|	if (file != NULL)
  ------------------
  |  Branch (833:6): [True: 45.9k, False: 43.4k]
  ------------------
  834|  45.9k|		*file = NULL;
  835|       |
  836|  89.4k|	sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
  ------------------
  |  |   71|  89.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__
  |  |  ------------------
  ------------------
  837|  89.4k|	if (in_path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  89.4k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (837:6): [True: 0, False: 89.4k]
  ------------------
  838|  89.4k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|  89.4k|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|  89.4k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (840:6): [True: 63.7k, False: 25.6k]
  ------------------
  841|       |		/* Perform a sanity check */
  842|  63.7k|		size_t i;
  843|       |
  844|  63.7k|		if ((in_path->len & 1) != 0)
  ------------------
  |  Branch (844:7): [True: 98, False: 63.6k]
  ------------------
  845|  63.7k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     98|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     98|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     98|	int _ret = r; \
  |  |  |  |  155|     98|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 98, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     98|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     98|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 98, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     98|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     98|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     98|	return _ret; \
  |  |  |  |  163|     98|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|       |
  847|   195k|		for (i = 0; i < in_path->len/2; i++) {
  ------------------
  |  Branch (847:15): [True: 131k, False: 63.5k]
  ------------------
  848|   131k|			u8 p1 = in_path->value[2*i],
  849|   131k|			   p2 = in_path->value[2*i+1];
  850|       |
  851|   131k|			if ((p1 == 0x3F && p2 == 0x00) && i != 0)
  ------------------
  |  Branch (851:9): [True: 48.5k, False: 82.9k]
  |  Branch (851:23): [True: 47.6k, False: 902]
  |  Branch (851:38): [True: 81, False: 47.6k]
  ------------------
  852|   131k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     81|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     81|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     81|	int _ret = r; \
  |  |  |  |  155|     81|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     81|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     81|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  853|   131k|		}
  854|  63.6k|	}
  855|  89.2k|	if (card->ops->select_file == NULL)
  ------------------
  |  Branch (855:6): [True: 0, False: 89.2k]
  ------------------
  856|  89.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  857|  89.2k|	r = card->ops->select_file(card, in_path, file);
  858|  89.2k|	LOG_TEST_RET(card->ctx, r, "'SELECT' error");
  ------------------
  |  |  174|  89.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  89.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  89.2k|	int _ret = (r); \
  |  |  |  |  168|  89.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 69.2k, False: 20.0k]
  |  |  |  |  ------------------
  |  |  |  |  169|  69.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  69.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  69.2k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  69.2k|		return _ret; \
  |  |  |  |  172|  69.2k|	} \
  |  |  |  |  173|  89.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|       |
  860|  20.0k|	if (file) {
  ------------------
  |  Branch (860:6): [True: 12.5k, False: 7.49k]
  ------------------
  861|  12.5k|		if (*file)
  ------------------
  |  Branch (861:7): [True: 12.4k, False: 74]
  ------------------
  862|       |			/* Remember file path */
  863|  12.4k|			(*file)->path = *in_path;
  864|     74|		else
  865|       |			/* FIXME We should be a bit less strict and let the upper layers do
  866|       |			 * the error checking. We implemented this here because we are
  867|       |			 * lazy.  */
  868|     74|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     74|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  869|  12.5k|	}
  870|       |
  871|  20.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  20.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  20.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  20.0k|	int _ret = r; \
  |  |  |  |  155|  20.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  20.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|     74|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 74, False: 19.9k]
  |  |  |  |  ------------------
  |  |  |  |  157|  20.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  20.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|  20.0k|	return _ret; \
  |  |  |  |  163|  20.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  872|  20.0k|}
sc_get_data:
  876|  4.97k|{
  877|  4.97k|	int	r;
  878|       |
  879|  4.97k|	sc_log(card->ctx, "called, tag=%04x", tag);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
  880|  4.97k|	if (card->ops->get_data == NULL)
  ------------------
  |  Branch (880:6): [True: 0, False: 4.97k]
  ------------------
  881|  4.97k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  882|  4.97k|	r = card->ops->get_data(card, tag, buf, len);
  883|       |
  884|  4.97k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.97k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.97k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.97k|	int _ret = r; \
  |  |  |  |  155|  4.97k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.71k, False: 1.25k]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.40k, False: 311]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.71k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.71k|	} else { \
  |  |  |  |  159|  1.25k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.25k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.25k|	} \
  |  |  |  |  162|  4.97k|	return _ret; \
  |  |  |  |  163|  4.97k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  885|  4.97k|}
sc_read_record:
  940|  16.8k|{
  941|  16.8k|	size_t max_le = sc_get_max_recv_size(card);
  942|  16.8k|	size_t todo = count;
  943|  16.8k|	int r;
  944|       |
  945|  16.8k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (945:6): [True: 0, False: 16.8k]
  |  Branch (945:22): [True: 0, False: 16.8k]
  |  Branch (945:43): [True: 0, False: 16.8k]
  ------------------
  946|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  947|      0|	}
  948|  16.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  16.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  16.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  16.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  16.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 16.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  949|  16.8k|	if (count == 0)
  ------------------
  |  Branch (949:6): [True: 2.60k, False: 14.2k]
  ------------------
  950|  16.8k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.60k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  951|       |
  952|  14.2k|	if (card->ops->read_record == NULL)
  ------------------
  |  Branch (952:6): [True: 4, False: 14.2k]
  ------------------
  953|  14.2k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  954|       |
  955|       |	/* lock the card now to avoid deselection of the file */
  956|  14.2k|	r = sc_lock(card);
  957|  14.2k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  14.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  14.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  14.2k|	int _ret = (r); \
  |  |  |  |  168|  14.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 14.2k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  14.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  958|       |
  959|  28.7k|	while (todo > 0) {
  ------------------
  |  Branch (959:9): [True: 28.2k, False: 457]
  ------------------
  960|  28.2k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  28.2k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 21.8k, False: 6.37k]
  |  |  ------------------
  ------------------
  961|       |
  962|  28.2k|		r = card->ops->read_record(card, rec_nr, idx, buf, chunk, flags);
  963|  28.2k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  27.2k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (963:7): [True: 962, False: 27.2k]
  |  Branch (963:17): [True: 493, False: 26.8k]
  ------------------
  964|  1.45k|			break;
  965|  26.8k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (965:7): [True: 12.2k, False: 14.5k]
  |  Branch (965:16): [True: 11.1k, False: 1.15k]
  ------------------
  966|       |			/* the last command failed, but previous ones succeeded.
  967|       |			 * Let's just return what we've successfully read. */
  968|  11.1k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  11.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  969|  11.1k|			break;
  970|  11.1k|		}
  971|  15.6k|		if (r < 0) {
  ------------------
  |  Branch (971:7): [True: 1.15k, False: 14.5k]
  ------------------
  972|  1.15k|			sc_unlock(card);
  973|  1.15k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.15k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.15k|	int _ret = r; \
  |  |  |  |  155|  1.15k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.15k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.15k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.15k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.15k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.15k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.15k|	return _ret; \
  |  |  |  |  163|  1.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  974|  1.15k|		}
  975|  14.5k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (975:7): [True: 0, False: 14.5k]
  |  Branch (975:40): [True: 0, False: 14.5k]
  ------------------
  976|       |			/* `idx + r` or `todo - r` would overflow */
  977|      0|			sc_unlock(card);
  978|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OFFSET_TOO_LARGE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  979|      0|		}
  980|       |
  981|  14.5k|		todo -= (size_t) r;
  982|  14.5k|		buf  += (size_t) r;
  983|  14.5k|		idx  += (size_t) r;
  984|  14.5k|	}
  985|       |
  986|  13.0k|	sc_unlock(card);
  987|       |
  988|  13.0k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  13.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.0k|	int _ret = r; \
  |  |  |  |  155|  13.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 728, False: 12.3k]
  |  |  |  |  ------------------
  |  |  |  |  156|    728|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 728]
  |  |  |  |  ------------------
  |  |  |  |  157|    728|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.3k|	} else { \
  |  |  |  |  159|  12.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  12.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  12.3k|	} \
  |  |  |  |  162|  13.0k|	return _ret; \
  |  |  |  |  163|  13.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  989|  13.0k|}
sc_card_ctl:
 1099|  96.4k|{
 1100|  96.4k|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  96.4k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1101|       |
 1102|  96.4k|	if (card == NULL) {
  ------------------
  |  Branch (1102:6): [True: 0, False: 96.4k]
  ------------------
 1103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1104|      0|	}
 1105|  96.4k|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called with cmd=%lu\n", cmd);
  ------------------
  |  |   70|  96.4k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1106|       |
 1107|  96.4k|	if (card->ops->card_ctl != NULL)
  ------------------
  |  Branch (1107:6): [True: 94.5k, False: 1.88k]
  ------------------
 1108|  94.5k|		r = card->ops->card_ctl(card, cmd, args);
 1109|       |
 1110|       |	/* suppress "not supported" error messages */
 1111|  96.4k|	if (r == SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|  96.4k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (1111:6): [True: 3.95k, False: 92.4k]
  ------------------
 1112|  3.95k|		sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
  ------------------
  |  |   71|  3.95k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1113|  3.95k|		return r;
 1114|  3.95k|	}
 1115|  92.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  92.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  92.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  92.4k|	int _ret = r; \
  |  |  |  |  155|  92.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 67.4k, False: 24.9k]
  |  |  |  |  ------------------
  |  |  |  |  156|  67.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|  29.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 29.9k, False: 37.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|  67.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  67.4k|	} else { \
  |  |  |  |  159|  24.9k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  24.9k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  24.9k|	} \
  |  |  |  |  162|  92.4k|	return _ret; \
  |  |  |  |  163|  92.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1116|  92.4k|}
_sc_card_add_algorithm:
 1119|  46.3k|{
 1120|  46.3k|	sc_algorithm_info_t *p;
 1121|       |
 1122|  46.3k|	if (info == NULL) {
  ------------------
  |  Branch (1122:6): [True: 0, False: 46.3k]
  ------------------
 1123|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1124|      0|	}
 1125|  46.3k|	p = (sc_algorithm_info_t *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info));
 1126|  46.3k|	if (!p) {
  ------------------
  |  Branch (1126:6): [True: 0, False: 46.3k]
  ------------------
 1127|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1128|      0|	}
 1129|  46.3k|	card->algorithms = p;
 1130|  46.3k|	p += card->algorithm_count;
 1131|  46.3k|	card->algorithm_count++;
 1132|  46.3k|	*p = *info;
 1133|  46.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  46.3k|#define SC_SUCCESS				0
  ------------------
 1134|  46.3k|}
_sc_card_add_symmetric_alg:
 1138|    139|{
 1139|    139|	sc_algorithm_info_t info;
 1140|       |
 1141|    139|	memset(&info, 0, sizeof(info));
 1142|    139|	info.algorithm = algorithm;
 1143|    139|	info.key_length = key_length;
 1144|    139|	info.flags = flags;
 1145|       |
 1146|    139|	return _sc_card_add_algorithm(card, &info);
 1147|    139|}
_sc_card_add_ec_alg:
 1184|  6.25k|{
 1185|  6.25k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1186|  6.25k|		curve_oid, SC_ALGORITHM_EC);
  ------------------
  |  |   79|  6.25k|#define SC_ALGORITHM_EC		2
  ------------------
 1187|  6.25k|}
_sc_card_add_eddsa_alg:
 1192|    209|{
 1193|       |	/* For simplicity, share the ec union with the curve information */
 1194|    209|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1195|    209|		curve_oid, SC_ALGORITHM_EDDSA);
  ------------------
  |  |   81|    209|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1196|    209|}
_sc_card_add_xeddsa_alg:
 1201|  2.36k|{
 1202|       |	/* For simplicity, share the ec union with the curve information */
 1203|  2.36k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1204|  2.36k|		curve_oid, SC_ALGORITHM_XEDDSA);
  ------------------
  |  |   82|  2.36k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1205|  2.36k|}
_sc_card_add_rsa_alg:
 1248|  37.3k|{
 1249|  37.3k|	sc_algorithm_info_t info;
 1250|       |
 1251|  37.3k|	memset(&info, 0, sizeof(info));
 1252|  37.3k|	info.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   78|  37.3k|#define SC_ALGORITHM_RSA		0
  ------------------
 1253|  37.3k|	info.key_length = key_length;
 1254|  37.3k|	info.flags = flags;
 1255|       |	/* disable particular PKCS1 v1.5 padding type if also RAW is supported on card */
 1256|  37.3k|	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  120|  37.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  37.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  37.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  37.3k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  120|  37.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  37.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  37.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  37.3k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (1256:6): [True: 6.49k, False: 30.8k]
  ------------------
 1257|  6.49k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  118|  6.49k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1257:7): [True: 0, False: 6.49k]
  ------------------
 1258|      0|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  118|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
 1259|  6.49k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  119|  6.49k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1259:7): [True: 6.49k, False: 0]
  ------------------
 1260|  6.49k|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  119|  6.49k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 1261|  6.49k|	}
 1262|  37.3k|	info.u._rsa.exponent = exponent;
 1263|       |
 1264|  37.3k|	return _sc_card_add_algorithm(card, &info);
 1265|  37.3k|}
_sc_match_atr:
 1341|   308k|{
 1342|   308k|	int res;
 1343|       |
 1344|   308k|	if (card == NULL)
  ------------------
  |  Branch (1344:6): [True: 0, False: 308k]
  ------------------
 1345|      0|		return -1;
 1346|   308k|	res = match_atr_table(card->ctx, table, &card->atr);
 1347|   308k|	if (res < 0)
  ------------------
  |  Branch (1347:6): [True: 298k, False: 10.1k]
  ------------------
 1348|   298k|		return res;
 1349|  10.1k|	if (type_out != NULL)
  ------------------
  |  Branch (1349:6): [True: 9.81k, False: 380]
  ------------------
 1350|  9.81k|		*type_out = table[res].type;
 1351|  10.1k|	return res;
 1352|   308k|}
_sc_match_atr_block:
 1355|  11.9k|{
 1356|  11.9k|	struct sc_card_driver *drv;
 1357|  11.9k|	struct sc_atr_table *table;
 1358|  11.9k|	int res;
 1359|       |
 1360|  11.9k|	if (ctx == NULL)
  ------------------
  |  Branch (1360:6): [True: 0, False: 11.9k]
  ------------------
 1361|      0|		return NULL;
 1362|  11.9k|	if (driver) {
  ------------------
  |  Branch (1362:6): [True: 11.9k, False: 0]
  ------------------
 1363|  11.9k|		drv = driver;
 1364|  11.9k|		table = drv->atr_map;
 1365|  11.9k|		res = match_atr_table(ctx, table, atr);
 1366|  11.9k|		if (res < 0)
  ------------------
  |  Branch (1366:7): [True: 11.9k, False: 0]
  ------------------
 1367|  11.9k|			return NULL;
 1368|      0|		return table[res].card_atr;
 1369|  11.9k|	} else {
 1370|      0|		unsigned int i;
 1371|       |
 1372|      0|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (1372:15): [True: 0, False: 0]
  ------------------
 1373|      0|			drv = ctx->card_drivers[i];
 1374|      0|			table = drv->atr_map;
 1375|      0|			res = match_atr_table(ctx, table, atr);
 1376|      0|			if (res < 0)
  ------------------
  |  Branch (1376:8): [True: 0, False: 0]
  ------------------
 1377|      0|				continue;
 1378|      0|			return table[res].card_atr;
 1379|      0|		}
 1380|      0|	}
 1381|      0|	return NULL;
 1382|  11.9k|}
sc_get_conf_block:
 1453|  42.9k|{
 1454|  42.9k|	int i;
 1455|  42.9k|	scconf_block *conf_block = NULL;
 1456|       |
 1457|  85.8k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (1457:14): [True: 42.9k, False: 42.9k]
  ------------------
 1458|  42.9k|		scconf_block **blocks;
 1459|       |
 1460|  42.9k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], name1, name2);
 1461|  42.9k|		if (blocks != NULL) {
  ------------------
  |  Branch (1461:7): [True: 42.9k, False: 0]
  ------------------
 1462|  42.9k|			conf_block = blocks[0];
 1463|  42.9k|			free(blocks);
 1464|  42.9k|		}
 1465|  42.9k|		if (conf_block != NULL && priority)
  ------------------
  |  Branch (1465:7): [True: 0, False: 42.9k]
  |  Branch (1465:29): [True: 0, False: 0]
  ------------------
 1466|      0|			break;
 1467|  42.9k|	}
 1468|  42.9k|	return conf_block;
 1469|  42.9k|}
sc_clear_ec_params:
 1473|  8.82k|{
 1474|  8.82k|	if (ecp) {
  ------------------
  |  Branch (1474:6): [True: 8.82k, False: 0]
  ------------------
 1475|  8.82k|		free(ecp->named_curve);
 1476|  8.82k|		free(ecp->der.value);
 1477|  8.82k|		memset(ecp, 0, sizeof(struct sc_ec_parameters));
 1478|  8.82k|	}
 1479|  8.82k|	return;
 1480|  8.82k|}
card.c:sc_card_new:
  127|  15.0k|{
  128|  15.0k|	sc_card_t *card;
  129|       |
  130|  15.0k|	if (ctx == NULL)
  ------------------
  |  Branch (130:6): [True: 0, False: 15.0k]
  ------------------
  131|      0|		return NULL;
  132|       |
  133|  15.0k|	card = calloc(1, sizeof(struct sc_card));
  134|  15.0k|	if (card == NULL)
  ------------------
  |  Branch (134:6): [True: 0, False: 15.0k]
  ------------------
  135|      0|		return NULL;
  136|  15.0k|	card->ops = malloc(sizeof(struct sc_card_operations));
  137|  15.0k|	if (card->ops == NULL) {
  ------------------
  |  Branch (137:6): [True: 0, False: 15.0k]
  ------------------
  138|      0|		free(card);
  139|      0|		return NULL;
  140|      0|	}
  141|       |
  142|  15.0k|	card->ctx = ctx;
  143|  15.0k|	if (sc_mutex_create(ctx, &card->mutex) != SC_SUCCESS) {
  ------------------
  |  |   28|  15.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (143:6): [True: 0, False: 15.0k]
  ------------------
  144|      0|		free(card->ops);
  145|      0|		free(card);
  146|      0|		return NULL;
  147|      0|	}
  148|       |
  149|  15.0k|	card->type = -1;
  150|  15.0k|	card->app_count = -1;
  151|       |
  152|  15.0k|	return card;
  153|  15.0k|}
card.c:sc_card_free:
  156|  15.0k|{
  157|  15.0k|	sc_free_apps(card);
  158|  15.0k|	sc_free_ef_atr(card);
  159|       |
  160|  15.0k|	free(card->ops);
  161|       |
  162|  15.0k|	if (card->algorithms != NULL)   {
  ------------------
  |  Branch (162:6): [True: 10.9k, False: 4.11k]
  ------------------
  163|  10.9k|		int i;
  164|  57.2k|		for (i=0; i<card->algorithm_count; i++)   {
  ------------------
  |  Branch (164:13): [True: 46.3k, False: 10.9k]
  ------------------
  165|  46.3k|			struct sc_algorithm_info *info = (card->algorithms + i);
  166|  46.3k|			if (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   79|  92.7k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (166:8): [True: 6.25k, False: 40.1k]
  ------------------
  167|  40.1k|					info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|  86.4k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (167:6): [True: 209, False: 39.9k]
  ------------------
  168|  39.9k|					info->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|  39.9k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (168:6): [True: 2.36k, False: 37.5k]
  ------------------
  169|  8.82k|				sc_clear_ec_params(&info->u._ec.params);
  170|  8.82k|			}
  171|  46.3k|		}
  172|  10.9k|		free(card->algorithms);
  173|       |
  174|  10.9k|		card->algorithms = NULL;
  175|  10.9k|		card->algorithm_count = 0;
  176|  10.9k|	}
  177|       |
  178|  15.0k|	if (card->mutex != NULL) {
  ------------------
  |  Branch (178:6): [True: 0, False: 15.0k]
  ------------------
  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.0k|	sc_mem_clear(card, sizeof(*card));
  184|  15.0k|	free(card);
  185|  15.0k|}
card.c:_sc_card_add_ec_alg_int:
 1154|  8.82k|{
 1155|  8.82k|	sc_algorithm_info_t info;
 1156|  8.82k|	int r;
 1157|       |
 1158|  8.82k|	memset(&info, 0, sizeof(info));
 1159|  8.82k|	sc_init_oid(&info.u._ec.params.id);
 1160|       |
 1161|  8.82k|	info.algorithm = algorithm;
 1162|  8.82k|	info.key_length = key_length;
 1163|  8.82k|	info.flags = flags;
 1164|       |
 1165|  8.82k|	info.u._ec.ext_flags = ext_flags;
 1166|  8.82k|	if (curve_oid) {
  ------------------
  |  Branch (1166:6): [True: 4.84k, False: 3.98k]
  ------------------
 1167|  4.84k|		info.u._ec.params.id = *curve_oid;
 1168|  4.84k|		r = sc_encode_oid(card->ctx, &info.u._ec.params.id, &info.u._ec.params.der.value, &info.u._ec.params.der.len);
 1169|  4.84k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_encode_oid failed");
  ------------------
  |  |  184|  4.84k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.84k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.84k|	int _ret = (r); \
  |  |  |  |  178|  4.84k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 4.84k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  4.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1170|  4.84k|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &info.u._ec.params);
 1171|  4.84k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_pkcs15_fix_ec_parameters failed");
  ------------------
  |  |  184|  4.84k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.84k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.84k|	int _ret = (r); \
  |  |  |  |  178|  4.84k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 4.84k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  4.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1172|  4.84k|	}
 1173|       |
 1174|  8.82k|	r = _sc_card_add_algorithm(card, &info);
 1175|  8.82k|	return r;
 1176|      0|err:
 1177|      0|	sc_clear_ec_params(&info.u._ec.params);
 1178|      0|	return r;
 1179|  8.82k|}
card.c:match_atr_table:
 1278|   320k|{
 1279|   320k|	u8 *card_atr_bin;
 1280|   320k|	size_t card_atr_bin_len;
 1281|   320k|	char card_atr_hex[3 * SC_MAX_ATR_SIZE];
 1282|   320k|	size_t card_atr_hex_len;
 1283|   320k|	unsigned int i = 0;
 1284|       |
 1285|   320k|	if (ctx == NULL || table == NULL || atr == NULL)
  ------------------
  |  Branch (1285:6): [True: 0, False: 320k]
  |  Branch (1285:21): [True: 11.9k, False: 308k]
  |  Branch (1285:38): [True: 0, False: 308k]
  ------------------
 1286|  11.9k|		return -1;
 1287|   308k|	card_atr_bin = atr->value;
 1288|   308k|	card_atr_bin_len = atr->len;
 1289|   308k|	sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
 1290|   308k|	card_atr_hex_len = strlen(card_atr_hex);
 1291|       |
 1292|   308k|	sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR     : %s", card_atr_hex);
  ------------------
  |  |   70|   308k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1293|       |
 1294|  2.67M|	for (i = 0; table[i].atr != NULL; i++) {
  ------------------
  |  Branch (1294:14): [True: 2.37M, False: 298k]
  ------------------
 1295|  2.37M|		const char *tatr = table[i].atr;
 1296|  2.37M|		const char *matr = table[i].atrmask;
 1297|  2.37M|		size_t tatr_len = strlen(tatr);
 1298|  2.37M|		u8 mbin[SC_MAX_ATR_SIZE], tbin[SC_MAX_ATR_SIZE];
 1299|  2.37M|		size_t mbin_len, tbin_len, s, matr_len;
 1300|  2.37M|		size_t fix_hex_len = card_atr_hex_len;
 1301|  2.37M|		size_t fix_bin_len = card_atr_bin_len;
 1302|       |
 1303|  2.37M|		sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR try : %s", tatr);
  ------------------
  |  |   70|  2.37M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1304|       |
 1305|  2.37M|		if (tatr_len != fix_hex_len) {
  ------------------
  |  Branch (1305:7): [True: 2.29M, False: 81.9k]
  ------------------
 1306|  2.29M|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ignored - wrong length");
  ------------------
  |  |   70|  2.29M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1307|  2.29M|			continue;
 1308|  2.29M|		}
 1309|  81.9k|		if (matr != NULL) {
  ------------------
  |  Branch (1309:7): [True: 21.8k, False: 60.1k]
  ------------------
 1310|  21.8k|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR mask: %s", matr);
  ------------------
  |  |   70|  21.8k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1311|       |
 1312|  21.8k|			matr_len = strlen(matr);
 1313|  21.8k|			if (tatr_len != matr_len)
  ------------------
  |  Branch (1313:8): [True: 0, False: 21.8k]
  ------------------
 1314|      0|				continue;
 1315|  21.8k|			tbin_len = sizeof(tbin);
 1316|  21.8k|			sc_hex_to_bin(tatr, tbin, &tbin_len);
 1317|  21.8k|			mbin_len = sizeof(mbin);
 1318|  21.8k|			sc_hex_to_bin(matr, mbin, &mbin_len);
 1319|  21.8k|			if (mbin_len != fix_bin_len) {
  ------------------
  |  Branch (1319:8): [True: 0, False: 21.8k]
  ------------------
 1320|      0|				sc_debug(ctx, SC_LOG_DEBUG_MATCH, "length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1321|      0|				continue;
 1322|      0|			}
 1323|   433k|			for (s = 0; s < tbin_len; s++) {
  ------------------
  |  Branch (1323:16): [True: 411k, False: 21.8k]
  ------------------
 1324|       |				/* reduce tatr with mask */
 1325|   411k|				tbin[s] = (tbin[s] & mbin[s]);
 1326|       |				/* create copy of card_atr_bin masked) */
 1327|   411k|				mbin[s] = (card_atr_bin[s] & mbin[s]);
 1328|   411k|			}
 1329|  21.8k|			if (memcmp(tbin, mbin, tbin_len) != 0)
  ------------------
  |  Branch (1329:8): [True: 17.6k, False: 4.16k]
  ------------------
 1330|  17.6k|				continue;
 1331|  60.1k|		} else {
 1332|  60.1k|			if (strncasecmp(tatr, card_atr_hex, tatr_len) != 0)
  ------------------
  |  Branch (1332:8): [True: 54.1k, False: 6.03k]
  ------------------
 1333|  54.1k|				continue;
 1334|  60.1k|		}
 1335|  10.1k|		return i;
 1336|  81.9k|	}
 1337|   298k|	return -1;
 1338|   308k|}
card.c:sc_card_sm_unload:
 1519|  11.9k|{
 1520|  11.9k|	if (card->sm_ctx.module.ops.module_cleanup)
  ------------------
  |  Branch (1520:6): [True: 0, False: 11.9k]
  ------------------
 1521|      0|		card->sm_ctx.module.ops.module_cleanup(card->ctx);
 1522|       |
 1523|  11.9k|	if (card->sm_ctx.module.handle)
  ------------------
  |  Branch (1523:6): [True: 0, False: 11.9k]
  ------------------
 1524|      0|		sc_dlclose(card->sm_ctx.module.handle);
 1525|       |	card->sm_ctx.module.handle = NULL;
 1526|  11.9k|	return 0;
 1527|  11.9k|}
card.c:sc_card_sm_check:
 1622|  11.9k|{
 1623|  11.9k|	const char *sm = NULL, *module_name = NULL, *module_path = NULL, *module_data = NULL, *sm_mode = NULL;
 1624|  11.9k|	struct sc_context *ctx = card->ctx;
 1625|  11.9k|	scconf_block *atrblock = NULL, *sm_conf_block = NULL;
 1626|  11.9k|	int rv, ii;
 1627|       |#ifdef _WIN32
 1628|       |	char temp_path[PATH_MAX];
 1629|       |	size_t temp_len = PATH_MAX - 1;
 1630|       |	char expanded_val[PATH_MAX];
 1631|       |	DWORD expanded_len = PATH_MAX;
 1632|       |#endif
 1633|       |
 1634|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|       |
 1636|       |	/* get the name of card specific SM configuration section */
 1637|  11.9k|	atrblock = _sc_match_atr_block(ctx, card->driver, &card->atr);
 1638|  11.9k|	if (atrblock == NULL)
  ------------------
  |  Branch (1638:6): [True: 11.9k, False: 0]
  ------------------
 1639|  11.9k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  11.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.9k|	int _ret = r; \
  |  |  |  |  155|  11.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 11.9k]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.9k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.9k|	return _ret; \
  |  |  |  |  163|  11.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1640|      0|	sm = scconf_get_str(atrblock, "secure_messaging", NULL);
 1641|      0|	if (!sm)
  ------------------
  |  Branch (1641:6): [True: 0, False: 0]
  ------------------
 1642|      0|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1643|       |
 1644|       |	/* get SM configuration section by the name */
 1645|      0|	sc_log(ctx, "secure_messaging configuration block '%s'", sm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1646|      0|        for (ii = 0; ctx->conf_blocks[ii]; ii++) {
  ------------------
  |  Branch (1646:22): [True: 0, False: 0]
  ------------------
 1647|      0|		scconf_block **blocks;
 1648|       |
 1649|      0|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[ii], "secure_messaging", sm);
 1650|      0|		if (blocks) {
  ------------------
  |  Branch (1650:7): [True: 0, False: 0]
  ------------------
 1651|      0|			sm_conf_block = blocks[0];
 1652|      0|			free(blocks);
 1653|      0|		}
 1654|      0|		if (sm_conf_block != NULL)
  ------------------
  |  Branch (1654:7): [True: 0, False: 0]
  ------------------
 1655|      0|			break;
 1656|      0|	}
 1657|       |
 1658|      0|	if (!sm_conf_block)
  ------------------
  |  Branch (1658:6): [True: 0, False: 0]
  ------------------
 1659|      0|		LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "SM configuration block not preset");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|       |
 1661|       |	/* check if an external SM module has to be used */
 1662|       |#ifdef _WIN32
 1663|       |	rv = sc_ctx_win32_get_config_value(NULL, "SmDir", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
 1664|       |			temp_path, &temp_len);
 1665|       |	if (rv == SC_SUCCESS) {
 1666|       |		temp_path[temp_len] = '\0';
 1667|       |		module_path = temp_path;
 1668|       |	}
 1669|       |	expanded_len = ExpandEnvironmentStringsA(module_path, expanded_val, expanded_len);
 1670|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1671|       |		module_path = expanded_val;
 1672|       |#else
 1673|      0|	module_path = scconf_get_str(sm_conf_block, "module_path", DEFAULT_SM_MODULE_PATH);
 1674|      0|#endif
 1675|      0|	module_name = scconf_get_str(sm_conf_block, "module_name", DEFAULT_SM_MODULE);
 1676|      0|	sc_log(ctx, "SM module '%s' in  '%s'", module_name, module_path);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1677|      0|	if (!module_name)
  ------------------
  |  Branch (1677:6): [True: 0, False: 0]
  ------------------
 1678|      0|		LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "Invalid SM configuration: module not defined");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|       |
 1680|      0|	rv = sc_card_sm_load(card, module_path, module_name);
 1681|      0|	LOG_TEST_RET(ctx, rv, "Failed to load SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1682|       |
 1683|      0|	strlcpy(card->sm_ctx.module.filename, module_name, sizeof(card->sm_ctx.module.filename));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1684|      0|	strlcpy(card->sm_ctx.config_section, sm, sizeof(card->sm_ctx.config_section));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1685|       |
 1686|       |	/* allocate resources for the external SM module */
 1687|      0|	if (card->sm_ctx.module.ops.module_init)   {
  ------------------
  |  Branch (1687:6): [True: 0, False: 0]
  ------------------
 1688|      0|		module_data = scconf_get_str(sm_conf_block, "module_data", NULL);
 1689|       |
 1690|      0|		rv = card->sm_ctx.module.ops.module_init(ctx, module_data);
 1691|      0|		LOG_TEST_RET(ctx, rv, "Cannot initialize SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1692|      0|	}
 1693|       |
 1694|       |	/* initialize SM session in the case of 'APDU TRANSMIT' SM mode */
 1695|      0|	sm_mode = scconf_get_str(sm_conf_block, "mode", NULL);
 1696|      0|	if (sm_mode && !strcasecmp("Transmit", sm_mode))   {
  ------------------
  |  Branch (1696:6): [True: 0, False: 0]
  |  Branch (1696:17): [True: 0, False: 0]
  ------------------
 1697|      0|		if (!card->sm_ctx.ops.open || !card->sm_ctx.ops.get_sm_apdu || !card->sm_ctx.ops.free_sm_apdu)
  ------------------
  |  Branch (1697:7): [True: 0, False: 0]
  |  Branch (1697:33): [True: 0, False: 0]
  |  Branch (1697:66): [True: 0, False: 0]
  ------------------
 1698|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "'Transmit' SM asked but not supported by card driver");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1699|       |
 1700|      0|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1701|      0|		rv = card->sm_ctx.ops.open(card);
 1702|      0|		LOG_TEST_RET(ctx, rv, "Cannot initialize SM");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1703|      0|	}
 1704|       |
 1705|      0|	sc_log(ctx, "SM mode:%X", card->sm_ctx.sm_mode);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1706|      0|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, rv);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1707|      0|}

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

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

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

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

sc_enum_apps:
  163|  11.1k|{
  164|  11.1k|	struct sc_context *ctx = card->ctx;
  165|  11.1k|	sc_path_t path;
  166|  11.1k|	int ef_structure;
  167|  11.1k|	size_t file_size, jj;
  168|  11.1k|	int r, ii, idx;
  169|  11.1k|	struct sc_file *ef_dir = NULL;
  170|       |
  171|  11.1k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  11.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  172|       |
  173|  11.1k|	sc_free_apps(card);
  174|  11.1k|	card->app_count = 0;
  175|       |
  176|  11.1k|	sc_format_path("3F002F00", &path);
  177|  11.1k|	r = sc_select_file(card, &path, &ef_dir);
  178|  11.1k|	if (r < 0)
  ------------------
  |  Branch (178:6): [True: 8.85k, False: 2.33k]
  ------------------
  179|  8.85k|		sc_file_free(ef_dir);
  180|  11.1k|	LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file");
  ------------------
  |  |  174|  11.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  11.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  11.1k|	int _ret = (r); \
  |  |  |  |  168|  11.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8.85k, False: 2.33k]
  |  |  |  |  ------------------
  |  |  |  |  169|  8.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.85k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  8.85k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  8.85k|		return _ret; \
  |  |  |  |  172|  8.85k|	} \
  |  |  |  |  173|  11.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.33k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|       |
  182|  2.33k|	if (ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
  ------------------
  |  |  216|  2.33k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (182:6): [True: 1.14k, False: 1.19k]
  ------------------
  183|  1.14k|		sc_file_free(ef_dir);
  184|  1.14k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_CARD, "EF(DIR) is not a working EF.");
  ------------------
  |  |  174|  1.14k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.14k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.14k|	int _ret = (r); \
  |  |  |  |  168|  1.14k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.14k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.14k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.14k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.14k|		return _ret; \
  |  |  |  |  172|  1.14k|	} \
  |  |  |  |  173|  1.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  185|  1.14k|	}
  186|       |
  187|  1.19k|	ef_structure = ef_dir->ef_structure;
  188|  1.19k|	file_size = ef_dir->size;
  189|  1.19k|	sc_file_free(ef_dir);
  190|  1.19k|	if (ef_structure == SC_FILE_EF_TRANSPARENT) {
  ------------------
  |  |  221|  1.19k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (190:6): [True: 705, False: 485]
  ------------------
  191|    705|		u8 *buf = NULL, *p;
  192|    705|		size_t bufsize;
  193|       |
  194|    705|		if (file_size == 0)
  ------------------
  |  Branch (194:7): [True: 25, False: 680]
  ------------------
  195|    705|			LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|     25|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     25|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     25|	int _ret = r; \
  |  |  |  |  155|     25|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  157|     25|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     25|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     25|	return _ret; \
  |  |  |  |  163|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|    680|		if (file_size > MAX_FILE_SIZE)
  ------------------
  |  |  229|    680|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (196:7): [True: 25, False: 655]
  ------------------
  197|    680|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|    655|		buf = malloc(file_size);
  200|    655|		if (buf == NULL)
  ------------------
  |  Branch (200:7): [True: 0, False: 655]
  ------------------
  201|    655|			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|    655|		p = buf;
  203|    655|		r = sc_read_binary(card, 0, buf, file_size, 0);
  204|    655|		if (r < 0) {
  ------------------
  |  Branch (204:7): [True: 236, False: 419]
  ------------------
  205|    236|			free(buf);
  206|    236|			LOG_TEST_RET(ctx, r, "sc_read_binary() failed");
  ------------------
  |  |  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: 236, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    236|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    236|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    236|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    236|		return _ret; \
  |  |  |  |  172|    236|	} \
  |  |  |  |  173|    236|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|    236|		}
  208|    419|		bufsize = r;
  209|    796|		while (bufsize > 0) {
  ------------------
  |  Branch (209:10): [True: 615, False: 181]
  ------------------
  210|    615|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    615|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (210:8): [True: 1, False: 614]
  ------------------
  211|      1|				sc_log(ctx, "Too many applications on card");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  212|      1|				break;
  213|      1|			}
  214|    614|			r = parse_dir_record(card, &p, &bufsize, -1);
  215|    614|			if (r)
  ------------------
  |  Branch (215:8): [True: 237, False: 377]
  ------------------
  216|    237|				break;
  217|    614|		}
  218|    419|		if (buf)
  ------------------
  |  Branch (218:7): [True: 419, False: 0]
  ------------------
  219|    419|			free(buf);
  220|       |
  221|    419|	}
  222|    485|	else {	/* record structure */
  223|    485|		unsigned char buf[256], *p;
  224|    485|		unsigned int rec_nr;
  225|    485|		size_t rec_size;
  226|       |
  227|       |		/* Arbitrary set '16' as maximal number of records to check out:
  228|       |		 * to avoid endless loop because of some incomplete cards/drivers */
  229|  1.36k|		for (rec_nr = 1; rec_nr < 16; rec_nr++) {
  ------------------
  |  Branch (229:20): [True: 1.36k, False: 6]
  ------------------
  230|  1.36k|			r = sc_read_record(card, rec_nr, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1305|  1.36k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  231|  1.36k|			if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.36k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (231:8): [True: 1, False: 1.35k]
  ------------------
  232|      1|				break;
  233|  1.35k|			LOG_TEST_RET(ctx, r, "read_record() failed");
  ------------------
  |  |  174|  1.35k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.35k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.35k|	int _ret = (r); \
  |  |  |  |  168|  1.35k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 477, False: 882]
  |  |  |  |  ------------------
  |  |  |  |  169|    477|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    477|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    477|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    477|		return _ret; \
  |  |  |  |  172|    477|	} \
  |  |  |  |  173|  1.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 882]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|       |
  235|    882|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    882|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (235:8): [True: 1, False: 881]
  ------------------
  236|      1|				sc_log(ctx, "Too many applications on card");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  237|      1|				break;
  238|      1|			}
  239|       |
  240|    881|			rec_size = r;
  241|    881|			p = buf;
  242|    881|			parse_dir_record(card, &p, &rec_size, (int)rec_nr);
  243|    881|		}
  244|    485|	}
  245|       |
  246|       |	/* Move known PKCS#15 applications to the head of the list */
  247|    812|	for (ii=0, idx=0; ii<card->app_count; ii++)   {
  ------------------
  |  Branch (247:20): [True: 385, False: 427]
  ------------------
  248|  3.29k|		for (jj=0; jj < sizeof(apps)/sizeof(apps[0]); jj++) {
  ------------------
  |  Branch (248:14): [True: 2.94k, False: 348]
  ------------------
  249|  2.94k|			if (apps[jj].aid_len != card->app[ii]->aid.len)
  ------------------
  |  Branch (249:8): [True: 2.83k, False: 104]
  ------------------
  250|  2.83k|				continue;
  251|    104|			if (memcmp(apps[jj].aid, card->app[ii]->aid.value, apps[jj].aid_len))
  ------------------
  |  Branch (251:8): [True: 67, False: 37]
  ------------------
  252|     67|				continue;
  253|     37|			break;
  254|    104|		}
  255|       |
  256|    385|		if (ii != idx && jj < sizeof(apps)/sizeof(apps[0]))   {
  ------------------
  |  Branch (256:7): [True: 100, False: 285]
  |  Branch (256:20): [True: 28, False: 72]
  ------------------
  257|     28|			struct sc_app_info *tmp = card->app[idx];
  258|       |
  259|     28|			card->app[idx] = card->app[ii];
  260|     28|			card->app[ii] = tmp;
  261|     28|			idx++;
  262|     28|		}
  263|    385|	}
  264|       |
  265|    427|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    427|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    427|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    427|	int _ret = r; \
  |  |  |  |  155|    427|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 427, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    427|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 427]
  |  |  |  |  ------------------
  |  |  |  |  157|    427|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    427|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    427|	return _ret; \
  |  |  |  |  163|    427|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|    427|}
sc_free_apps:
  269|  26.2k|{
  270|  26.2k|	int	i;
  271|       |
  272|  26.8k|	for (i = 0; i < card->app_count; i++) {
  ------------------
  |  Branch (272:14): [True: 608, False: 26.2k]
  ------------------
  273|    608|		free(card->app[i]->label);
  274|    608|		free(card->app[i]->ddo.value);
  275|    608|		free(card->app[i]);
  276|    608|	}
  277|  26.2k|	card->app_count = -1;
  278|  26.2k|}
dir.c:parse_dir_record:
   65|  1.49k|{
   66|  1.49k|	struct sc_context *ctx = card->ctx;
   67|  1.49k|	struct sc_asn1_entry asn1_dirrecord[5], asn1_dir[2];
   68|  1.49k|	scconf_block *conf_block = NULL;
   69|  1.49k|	sc_app_info_t *app = NULL;
   70|  1.49k|	struct sc_aid aid;
   71|  1.49k|	u8 label[128], path[128], ddo[128];
   72|  1.49k|	size_t label_len = sizeof(label) - 1, path_len = sizeof(path), ddo_len = sizeof(ddo);
   73|  1.49k|	int r;
   74|       |
   75|  1.49k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.49k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.49k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.49k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.49k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   76|  1.49k|	aid.len = sizeof(aid.value);
   77|       |
   78|  1.49k|	memset(label, 0, sizeof(label));
   79|  1.49k|	sc_copy_asn1_entry(c_asn1_dirrecord, asn1_dirrecord);
   80|  1.49k|	sc_copy_asn1_entry(c_asn1_dir, asn1_dir);
   81|  1.49k|	sc_format_asn1_entry(asn1_dir + 0, asn1_dirrecord, NULL, 0);
   82|  1.49k|	sc_format_asn1_entry(asn1_dirrecord + 0, aid.value, &aid.len, 0);
   83|  1.49k|	sc_format_asn1_entry(asn1_dirrecord + 1, label, &label_len, 0);
   84|  1.49k|	sc_format_asn1_entry(asn1_dirrecord + 2, path, &path_len, 0);
   85|  1.49k|	sc_format_asn1_entry(asn1_dirrecord + 3, ddo, &ddo_len, 0);
   86|       |
   87|  1.49k|	r = sc_asn1_decode(ctx, asn1_dir, *buf, *buflen, (const u8 **) buf, buflen);
   88|  1.49k|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  1.49k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (88:6): [True: 103, False: 1.39k]
  ------------------
   89|  1.49k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    103|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    103|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    103|	int _ret = r; \
  |  |  |  |  155|    103|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    103|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    103|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    103|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    103|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    103|	return _ret; \
  |  |  |  |  163|    103|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|  1.39k|	LOG_TEST_RET(ctx, r, "EF(DIR) parsing failed");
  ------------------
  |  |  174|  1.39k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.39k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.39k|	int _ret = (r); \
  |  |  |  |  168|  1.39k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 774, False: 618]
  |  |  |  |  ------------------
  |  |  |  |  169|    774|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    774|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    774|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    774|		return _ret; \
  |  |  |  |  172|    774|	} \
  |  |  |  |  173|  1.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 618]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|       |
   92|    618|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
   93|    618|	if (conf_block)   {
  ------------------
  |  Branch (93:6): [True: 0, False: 618]
  ------------------
   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|    618|	app = calloc(1, sizeof(struct sc_app_info));
  112|    618|	if (app == NULL)
  ------------------
  |  Branch (112:6): [True: 0, False: 618]
  ------------------
  113|    618|		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|    618|	memcpy(&app->aid, &aid, sizeof(struct sc_aid));
  116|       |
  117|    618|	if (asn1_dirrecord[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    618|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (117:6): [True: 20, False: 598]
  ------------------
  118|     20|		app->label = strdup((char *) label);
  119|    598|	else
  120|    598|		app->label = NULL;
  121|       |
  122|    618|	if (asn1_dirrecord[2].flags & SC_ASN1_PRESENT && path_len > 0) {
  ------------------
  |  |  147|  1.23k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (122:6): [True: 248, False: 370]
  |  Branch (122:51): [True: 226, False: 22]
  ------------------
  123|       |		/* application path present: ignore AID */
  124|    226|		if (path_len > SC_MAX_PATH_SIZE) {
  ------------------
  |  |   47|    226|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (124:7): [True: 10, False: 216]
  ------------------
  125|     10|			free(app->label);
  126|     10|			free(app);
  127|     10|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "Application path is too long.");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|     10|		}
  129|    216|		memcpy(app->path.value, path, path_len);
  130|    216|		app->path.len = path_len;
  131|    216|		app->path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    216|#define SC_PATH_TYPE_PATH		2
  ------------------
  132|    216|	}
  133|    392|	else {
  134|       |		/* application path not present: use AID as application path */
  135|    392|		memcpy(app->path.value, aid.value, aid.len);
  136|    392|		app->path.len = aid.len;
  137|    392|		app->path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    392|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  138|    392|	}
  139|       |
  140|    608|	if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    608|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (140:6): [True: 149, False: 459]
  ------------------
  141|    149|		app->ddo.value = malloc(ddo_len);
  142|    149|		if (app->ddo.value == NULL) {
  ------------------
  |  Branch (142:7): [True: 0, False: 149]
  ------------------
  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|    149|		memcpy(app->ddo.value, ddo, ddo_len);
  148|    149|		app->ddo.len = ddo_len;
  149|    459|	} else {
  150|    459|		app->ddo.value = NULL;
  151|    459|		app->ddo.len = 0;
  152|    459|	}
  153|       |
  154|    608|	app->rec_nr = rec_nr;
  155|    608|	card->app[card->app_count] = app;
  156|    608|	card->app_count++;
  157|       |
  158|    608|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    608|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    608|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    608|	int _ret = r; \
  |  |  |  |  155|    608|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 608, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    608|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 608]
  |  |  |  |  ------------------
  |  |  |  |  157|    608|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    608|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    608|	return _ret; \
  |  |  |  |  163|    608|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|    608|}

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

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

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

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

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

iasecc_sm_initialize:
  270|    168|{
  271|    168|	struct sc_context *ctx = card->ctx;
  272|    168|#ifdef ENABLE_SM
  273|    168|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    168|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    168|	struct sc_remote_data rdata;
  276|    168|	int rv;
  277|       |
  278|    168|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    168|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    168|#define strlcpy _strlcpy
  ------------------
  281|    168|	sm_info->cmd = cmd;
  282|    168|	sm_info->serialnr = card->serialnr;
  283|    168|	sm_info->card_type = card->type;
  284|    168|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    168|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    168|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    168|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() MUTUAL AUTHENTICATION failed");
  ------------------
  |  |  174|    168|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    168|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    168|	int _ret = (r); \
  |  |  |  |  168|    168|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 168, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    168|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    168|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    168|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    168|		return _ret; \
  |  |  |  |  172|    168|	} \
  |  |  |  |  173|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  288|       |
  289|      0|	rv = sc_get_challenge(card, cwa_session->card_challenge, SM_SMALL_CHALLENGE_LEN);
  ------------------
  |  |   85|      0|#define SM_SMALL_CHALLENGE_LEN	8
  ------------------
  290|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() GET CHALLENGE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|      0|	sc_remote_data_init(&rdata);
  293|       |
  294|      0|	rv = sm_save_sc_context(card, sm_info);
  295|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() cannot save current context");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  296|       |
  297|      0|	if (!card->sm_ctx.module.ops.initialize)
  ------------------
  |  Branch (297:6): [True: 0, False: 0]
  ------------------
  298|      0|		LOG_TEST_RET(ctx, SC_ERROR_SM_NOT_INITIALIZED, "iasecc_sm_initialize() no SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|      0|	rv = card->sm_ctx.module.ops.initialize(ctx, sm_info, &rdata);
  300|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() INITIALIZE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|       |
  302|       |
  303|      0|	if (rdata.length == 1)   {
  ------------------
  |  Branch (303:6): [True: 0, False: 0]
  ------------------
  304|      0|		rdata.data->flags |= SC_REMOTE_APDU_FLAG_RETURN_ANSWER;
  ------------------
  |  |  386|      0|#define SC_REMOTE_APDU_FLAG_RETURN_ANSWER	0x02
  ------------------
  305|      0|		rdata.data->apdu.flags &= ~SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|      0|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  306|      0|	}
  307|      0|	else   {
  308|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "TODO: SM init with more then one APDU");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|      0|	}
  310|       |
  311|      0|	cwa_session->mdata_len = sizeof(cwa_session->mdata);
  312|      0|	rv = iasecc_sm_transmit_apdus (card, &rdata, cwa_session->mdata, &cwa_session->mdata_len);
  313|      0|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (313:6): [True: 0, False: 0]
  ------------------
  314|      0|		sc_log(ctx, "SM initialization failed, %i tries left", (rdata.data + rdata.length - 1)->apdu.sw2 & 0x0F);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() transmit APDUs failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|       |
  317|      0|	rdata.free(&rdata);
  318|       |
  319|      0|	sc_log(ctx, "MA data(len:%"SC_FORMAT_LEN_SIZE_T"u) '%s'",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|      0|	       cwa_session->mdata_len,
  321|      0|	       sc_dump_hex(cwa_session->mdata, cwa_session->mdata_len));
  322|      0|	if (cwa_session->mdata_len != 0x48)
  ------------------
  |  Branch (322:6): [True: 0, False: 0]
  ------------------
  323|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "iasecc_sm_initialize() invalid MUTUAL AUTHENTICATE result data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  324|       |
  325|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  326|       |#else
  327|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  328|       |	return SC_ERROR_NOT_SUPPORTED;
  329|       |#endif
  330|      0|}
iasecc_sm_read_binary:
  593|    168|{
  594|    168|	struct sc_context *ctx = card->ctx;
  595|    168|#ifdef ENABLE_SM
  596|    168|	struct sm_info *sm_info = &card->sm_ctx.info;
  597|    168|	struct sc_remote_data rdata;
  598|    168|	struct iasecc_sm_cmd_update_binary cmd_data;
  599|    168|	int rv;
  600|       |
  601|    168|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  602|    168|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  603|    168|	       "SM read binary: acl:%X, offs:%"SC_FORMAT_LEN_SIZE_T"u, count:%"SC_FORMAT_LEN_SIZE_T"u",
  604|    168|	       se_num, offs, count);
  605|       |
  606|    168|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    168|#define SM_CMD_FILE_READ		0x201
  ------------------
  607|    168|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM INITIALIZE failed");
  ------------------
  |  |  174|    168|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    168|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    168|	int _ret = (r); \
  |  |  |  |  168|    168|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 168, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    168|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    168|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    168|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    168|		return _ret; \
  |  |  |  |  172|    168|	} \
  |  |  |  |  173|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|      0|	cmd_data.offs = offs;
  610|      0|	cmd_data.count = count;
  611|      0|	sm_info->cmd_data = &cmd_data;
  612|       |
  613|      0|	sc_remote_data_init(&rdata);
  614|      0|	rv = iasecc_sm_cmd(card, &rdata);
  615|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM 'READ BINARY' failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  616|       |
  617|      0|	sc_log(ctx, "IAS/ECC decode answer() rdata length %i", rdata.length);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  618|       |
  619|      0|	rv = sm_release (card, &rdata, buff, count);
  620|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM release failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|       |
  622|      0|	rdata.free(&rdata);
  623|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  624|       |#else
  625|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  626|       |	return SC_ERROR_NOT_SUPPORTED;
  627|       |#endif
  628|      0|}
iasecc-sm.c:iasecc_sm_se_mutual_authentication:
  222|    168|{
  223|    168|	struct sc_context *ctx = card->ctx;
  224|    168|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    168|	struct iasecc_se_info se;
  226|    168|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    168|	struct sc_apdu apdu;
  228|    168|	unsigned char sbuf[0x100];
  229|    168|	int rv, offs;
  230|       |
  231|    168|	memset(&se, 0, sizeof(se));
  232|       |
  233|    168|	se.reference = se_num;
  234|    168|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    168|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    168|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    168|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    168|	rv = iasecc_se_get_info(card, &se);
  238|    168|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  174|    168|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    168|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    168|	int _ret = (r); \
  |  |  |  |  168|    168|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 155, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|    168|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|       |
  240|     13|	rv = iasecc_se_get_crt(card, &se, crt);
  241|     13|	sc_file_free(se.df);
  242|     13|	LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  76.5k|{
   37|  76.5k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (37:6): [True: 0, False: 76.5k]
  |  Branch (37:22): [True: 0, False: 76.5k]
  ------------------
   38|      0|		return;
   39|      0|	}
   40|       |
   41|  76.5k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (41:6): [True: 706, False: 75.8k]
  ------------------
   42|       |		/* The lower layers will automatically do chaining */
   43|    706|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    706|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   44|    706|	}
   45|       |
   46|  76.5k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (46:6): [True: 2.93k, False: 73.5k]
  ------------------
   47|       |		/* The lower layers will automatically do a GET RESPONSE, if possible.
   48|       |		 * All other workarounds must be carried out by the upper layers. */
   49|  2.93k|		apdu->le = sc_get_max_recv_size(card);
   50|  2.93k|	}
   51|  76.5k|}
encode_do_data:
  177|  14.0k|{
  178|  14.0k|	unsigned char offset_buffer[2];
  179|  14.0k|	size_t offset_buffer_len = sizeof offset_buffer;
  180|  14.0k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  181|  14.0k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  182|       |
  183|  14.0k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (183:6): [True: 0, False: 14.0k]
  ------------------
  184|  14.0k|		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|  14.0k|	offset_buffer[0] = (u8) (idx >> 8);
  186|  14.0k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  187|  14.0k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  188|       |
  189|  14.0k|	if (data && data_len) {
  ------------------
  |  Branch (189:6): [True: 0, False: 14.0k]
  |  Branch (189:14): [True: 0, False: 0]
  ------------------
  190|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  191|  14.0k|	} else {
  192|  14.0k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  193|  14.0k|	}
  194|       |
  195|  14.0k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  14.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  14.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  14.0k|	int _ret = (r); \
  |  |  |  |  168|  14.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 14.0k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  14.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  14.0k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  197|  14.0k|			"sc_asn1_encode() failed");
  198|       |
  199|  14.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  14.0k|#define SC_SUCCESS				0
  ------------------
  200|  14.0k|}
decode_do_data:
  205|  10.2k|{
  206|  10.2k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  207|  10.2k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  208|       |
  209|  10.2k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  210|  10.2k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  211|       |
  212|  10.2k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  10.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  10.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  10.2k|	int _ret = (r); \
  |  |  |  |  168|  10.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 984, False: 9.27k]
  |  |  |  |  ------------------
  |  |  |  |  169|    984|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    984|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    984|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    984|		return _ret; \
  |  |  |  |  172|    984|	} \
  |  |  |  |  173|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|  9.27k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  214|  9.27k|			"sc_asn1_decode() failed");
  215|       |
  216|  9.27k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  9.27k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (216:6): [True: 6.62k, False: 2.64k]
  ------------------
  217|  6.62k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  6.62k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  218|       |
  219|  2.64k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.64k|#define SC_SUCCESS				0
  ------------------
  220|  9.27k|}
iso7816_build_pin_apdu:
 1189|    545|{
 1190|    545|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1191|    545|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|    545|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1192|       |
 1193|    545|	switch (data->pin_type) {
 1194|    528|	case SC_AC_CHV:
  ------------------
  |  |  151|    528|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1194:2): [True: 528, False: 17]
  ------------------
 1195|       |		/* fall through */
 1196|    528|	case SC_AC_SESSION:
  ------------------
  |  |  159|    528|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1196:2): [True: 0, False: 545]
  ------------------
 1197|    528|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|    528|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1197:2): [True: 0, False: 545]
  ------------------
 1198|    528|		break;
 1199|     17|	default:
  ------------------
  |  Branch (1199:2): [True: 17, False: 528]
  ------------------
 1200|     17|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     17|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1201|    545|	}
 1202|       |
 1203|    528|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  429|    528|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1203:6): [True: 12, False: 516]
  ------------------
 1204|     12|		pad = 1;
 1205|    528|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  428|    528|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1205:6): [True: 0, False: 528]
  ------------------
 1206|      0|		use_pin_pad = 1;
 1207|       |
 1208|    528|	data->pin1.offset = 5;
 1209|       |
 1210|    528|	switch (data->cmd) {
 1211|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1211:2): [True: 0, False: 528]
  ------------------
 1212|      0|		ins = 0x20;
 1213|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1214|      0|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1214:7): [True: 0, False: 0]
  |  Branch (1214:30): [True: 0, False: 0]
  ------------------
 1215|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1216|      0|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1216:7): [True: 0, False: 0]
  ------------------
 1217|      0|			return r;
 1218|      0|		len = r;
 1219|      0|		break;
 1220|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1220:2): [True: 0, False: 528]
  ------------------
 1221|      0|		ins = 0x24;
 1222|      0|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1222:7): [True: 0, False: 0]
  |  Branch (1222:31): [True: 0, False: 0]
  |  Branch (1222:46): [True: 0, False: 0]
  ------------------
 1223|      0|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1223:8): [True: 0, False: 0]
  ------------------
 1224|      0|				return r;
 1225|      0|			len += r;
 1226|      0|		}
 1227|      0|		else {
 1228|       |			/* implicit test */
 1229|      0|			p1 = 1;
 1230|      0|		}
 1231|       |
 1232|      0|		data->pin2.offset = data->pin1.offset + len;
 1233|      0|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1233:7): [True: 0, False: 0]
  ------------------
 1234|      0|			return r;
 1235|       |		/* Special case - where provided the old PIN on the command line
 1236|       |		 * but expect the new one to be entered on the keypad.
 1237|       |		 */
 1238|      0|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1238:7): [True: 0, False: 0]
  |  Branch (1238:25): [True: 0, False: 0]
  ------------------
 1239|      0|			sc_log(card->ctx, "Special case - initial pin provided - but new pin asked on keypad");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1240|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1241|      0|		};
 1242|      0|		len += r;
 1243|      0|		break;
 1244|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1244:2): [True: 0, False: 528]
  ------------------
 1245|      0|		ins = 0x2C;
 1246|      0|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1246:7): [True: 0, False: 0]
  |  Branch (1246:31): [True: 0, False: 0]
  |  Branch (1246:46): [True: 0, False: 0]
  ------------------
 1247|      0|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1247:8): [True: 0, False: 0]
  ------------------
 1248|      0|				return r;
 1249|      0|			len += r;
 1250|      0|		} else {
 1251|      0|			p1 |= 0x02;
 1252|      0|		}
 1253|       |
 1254|      0|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1254:7): [True: 0, False: 0]
  |  Branch (1254:30): [True: 0, False: 0]
  ------------------
 1255|      0|			data->pin2.offset = data->pin1.offset + len;
 1256|      0|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1256:8): [True: 0, False: 0]
  ------------------
 1257|      0|				return r;
 1258|      0|			len += r;
 1259|      0|		} else {
 1260|      0|			p1 |= 0x01;
 1261|      0|		}
 1262|      0|		if (p1 == 0x03) {
  ------------------
  |  Branch (1262:7): [True: 0, False: 0]
  ------------------
 1263|       |			/* No data to send or to receive */
 1264|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1265|      0|		}
 1266|      0|		break;
 1267|    528|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|    528|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1267:2): [True: 528, False: 0]
  ------------------
 1268|    528|		ins = 0x20;
 1269|       |		/* No data to send or to receive */
 1270|    528|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|    528|#define SC_APDU_CASE_1			0x01
  ------------------
 1271|    528|		break;
 1272|      0|	default:
  ------------------
  |  Branch (1272:2): [True: 0, False: 528]
  ------------------
 1273|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1274|    528|	}
 1275|       |
 1276|    528|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1277|    528|	apdu->lc = len;
 1278|    528|	apdu->datalen = len;
 1279|    528|	apdu->data = buf;
 1280|    528|	apdu->resplen = 0;
 1281|       |
 1282|    528|	return 0;
 1283|    528|}
iso7816_select_aid:
 1401|  13.0k|{
 1402|  13.0k|	struct sc_context *ctx = card->ctx;
 1403|  13.0k|	struct sc_apdu apdu;
 1404|  13.0k|	int rv;
 1405|       |
 1406|  13.0k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1407|       |
 1408|  13.0k|	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.10k|#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|  5.90k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1408:30): [True: 7.10k, False: 5.90k]
  |  Branch (1408:102): [True: 7.10k, False: 5.90k]
  ------------------
 1409|  13.0k|	apdu.lc = reqlen;
 1410|  13.0k|	apdu.data = req;
 1411|  13.0k|	apdu.datalen = reqlen;
 1412|  13.0k|	apdu.resp = resp;
 1413|  13.0k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1413:17): [True: 7.10k, False: 5.90k]
  ------------------
 1414|  13.0k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1414:12): [True: 7.10k, False: 5.90k]
  ------------------
 1415|       |
 1416|  13.0k|	rv = sc_transmit_apdu(card, &apdu);
 1417|  13.0k|	if (resplen)
  ------------------
  |  Branch (1417:6): [True: 5.90k, False: 7.10k]
  ------------------
 1418|  5.90k|		*resplen = apdu.resplen;
 1419|  13.0k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  13.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.0k|	int _ret = (r); \
  |  |  |  |  168|  13.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 105, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |  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|  13.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1420|       |
 1421|  12.9k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1422|  12.9k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  12.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.9k|	int _ret = r; \
  |  |  |  |  155|  12.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.65k, False: 4.24k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.9k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.9k|	return _ret; \
  |  |  |  |  163|  12.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1423|  12.9k|}
sc_get_iso7816_driver:
 1491|   498k|{
 1492|   498k|	return &iso_driver;
 1493|   498k|}
iso7816.c:no_match:
 1437|  7.08k|{
 1438|  7.08k|	return 0;
 1439|  7.08k|}
iso7816.c:iso7816_read_record:
  225|  27.8k|{
  226|  27.8k|	struct sc_apdu apdu;
  227|  27.8k|	int r;
  228|       |	/* XXX maybe use some bigger buffer */
  229|  27.8k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  230|  27.8k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  231|  27.8k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  232|       |
  233|  27.8k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (233:6): [True: 18, False: 27.8k]
  ------------------
  234|  27.8k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  27.8k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 13.8k, False: 14.0k]
  ------------------
  237|  13.8k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  13.8k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  13.8k|		apdu.le = count;
  239|  13.8k|		apdu.resplen = count;
  240|  13.8k|		apdu.resp = buf;
  241|  14.0k|	} else {
  242|  14.0k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  14.0k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  14.0k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  14.0k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  14.0k|	int _ret = (r); \
  |  |  |  |  178|  14.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 14.0k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  14.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 14.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  14.0k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  14.0k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  14.0k|		apdu.lc = encoded_data_len;
  247|  14.0k|		apdu.datalen = encoded_data_len;
  248|  14.0k|		apdu.data = encoded_data;
  249|  14.0k|		apdu.le = sizeof resp;
  250|  14.0k|		apdu.resplen = sizeof resp;
  251|  14.0k|		apdu.resp = resp;
  252|  14.0k|	}
  253|  27.8k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1300|  27.8k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  27.8k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1305|  27.8k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 27.8k, False: 0]
  ------------------
  255|  27.8k|		apdu.p2 |= 0x04;
  256|       |
  257|  27.8k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  27.8k|	r = sc_transmit_apdu(card, &apdu);
  259|  27.8k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  27.8k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  27.8k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  27.8k|	int _ret = (r); \
  |  |  |  |  178|  27.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 614, False: 27.2k]
  |  |  |  |  ------------------
  |  |  |  |  179|    614|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    614|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    614|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    614|		goto err; \
  |  |  |  |  182|    614|	} \
  |  |  |  |  183|  27.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 27.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  27.2k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  27.2k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  27.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  27.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  27.2k|	int _ret = (r); \
  |  |  |  |  178|  27.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.45k, False: 22.7k]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.45k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.45k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.45k|		goto err; \
  |  |  |  |  182|  4.45k|	} \
  |  |  |  |  183|  27.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 22.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  22.7k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 12.5k, False: 10.2k]
  ------------------
  264|  12.5k|		r = (int)apdu.resplen;
  265|  12.5k|	} else {
  266|  10.2k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  10.2k|				&decoded_data, &decoded_data_len);
  268|  10.2k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  10.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  10.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  10.2k|	int _ret = (r); \
  |  |  |  |  178|  10.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7.61k, False: 2.64k]
  |  |  |  |  ------------------
  |  |  |  |  179|  7.61k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.61k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  7.61k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  7.61k|		goto err; \
  |  |  |  |  182|  7.61k|	} \
  |  |  |  |  183|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  2.64k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 2.41k, False: 227]
  ------------------
  270|  2.41k|			count = decoded_data_len;
  271|  2.41k|		}
  272|  2.64k|		memcpy(buf, decoded_data, count);
  273|  2.64k|		r = (int)count;
  274|  2.64k|	}
  275|       |
  276|  27.8k|err:
  277|  27.8k|	free(encoded_data);
  278|  27.8k|	free(decoded_data);
  279|  27.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  27.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  27.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  27.8k|	int _ret = r; \
  |  |  |  |  155|  27.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.5k, False: 14.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.6k, False: 912]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.2k|	} else { \
  |  |  |  |  159|  14.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  14.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  14.2k|	} \
  |  |  |  |  162|  27.8k|	return _ret; \
  |  |  |  |  163|  27.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  27.8k|}
iso7816.c:iso7816_select_file:
  631|  45.0k|{
  632|  45.0k|	struct sc_context *ctx;
  633|  45.0k|	struct sc_apdu apdu;
  634|  45.0k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  635|  45.0k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  636|  45.0k|	int r, pathtype;
  637|  45.0k|	size_t pathlen;
  638|  45.0k|	int select_mf = 0;
  639|  45.0k|	struct sc_file *file = NULL;
  640|  45.0k|	const u8 *buffer;
  641|  45.0k|	size_t buffer_len;
  642|  45.0k|	unsigned int cla, tag;
  643|       |
  644|  45.0k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (644:6): [True: 0, False: 45.0k]
  |  Branch (644:22): [True: 0, False: 45.0k]
  ------------------
  645|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  646|      0|	}
  647|  45.0k|	ctx = card->ctx;
  648|  45.0k|	memcpy(path, in_path->value, in_path->len);
  649|  45.0k|	pathlen = in_path->len;
  650|  45.0k|	pathtype = in_path->type;
  651|       |
  652|  45.0k|	if (in_path->aid.len) {
  ------------------
  |  Branch (652:6): [True: 1.48k, False: 43.5k]
  ------------------
  653|  1.48k|		if (!pathlen) {
  ------------------
  |  Branch (653:7): [True: 1.43k, False: 52]
  ------------------
  654|  1.43k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  655|  1.43k|			pathlen = in_path->aid.len;
  656|  1.43k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.43k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  657|  1.43k|		} else {
  658|       |			/* First, select the application */
  659|     52|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|     52|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  660|     52|			apdu.data = in_path->aid.value;
  661|     52|			apdu.datalen = in_path->aid.len;
  662|     52|			apdu.lc = in_path->aid.len;
  663|       |
  664|     52|			r = sc_transmit_apdu(card, &apdu);
  665|     52|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     52|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     52|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     52|	int _ret = (r); \
  |  |  |  |  168|     52|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  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|     52|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  666|     49|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  667|     49|			if (r)
  ------------------
  |  Branch (667:8): [True: 12, False: 37]
  ------------------
  668|     49|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     12|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  669|       |
  670|     37|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|     74|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (670:8): [True: 37, False: 0]
  ------------------
  671|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (671:9): [True: 0, False: 0]
  ------------------
  672|     37|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|     37|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  673|     37|		}
  674|  1.48k|	}
  675|       |
  676|  45.0k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  45.0k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  677|       |
  678|  45.0k|	switch (pathtype) {
  679|  6.28k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  6.28k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (679:2): [True: 6.28k, False: 38.7k]
  ------------------
  680|  6.28k|		apdu.p1 = 0;
  681|  6.28k|		if (pathlen != 2)
  ------------------
  |  Branch (681:7): [True: 0, False: 6.28k]
  ------------------
  682|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  683|  6.28k|		break;
  684|  19.9k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  19.9k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (684:2): [True: 19.9k, False: 25.0k]
  ------------------
  685|  19.9k|		apdu.p1 = 4;
  686|  19.9k|		break;
  687|  18.6k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  18.6k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (687:2): [True: 18.6k, False: 26.3k]
  ------------------
  688|  18.6k|		apdu.p1 = 8;
  689|  18.6k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (689:7): [True: 18.6k, False: 49]
  |  Branch (689:23): [True: 12.9k, False: 5.60k]
  ------------------
  690|  12.9k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (690:8): [True: 3.31k, False: 9.67k]
  ------------------
  691|  3.31k|				select_mf = 1;
  692|  3.31k|				apdu.p1 = 0;
  693|  3.31k|				break;
  694|  3.31k|			}
  695|  9.67k|			path += 2;
  696|  9.67k|			pathlen -= 2;
  697|  9.67k|		}
  698|  15.3k|		break;
  699|  15.3k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|     37|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (699:2): [True: 37, False: 44.9k]
  ------------------
  700|     37|		apdu.p1 = 9;
  701|     37|		break;
  702|    110|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    110|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (702:2): [True: 110, False: 44.9k]
  ------------------
  703|    110|		apdu.p1 = 3;
  704|    110|		pathlen = 0;
  705|    110|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    110|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  706|    110|		break;
  707|      0|	default:
  ------------------
  |  Branch (707:2): [True: 0, False: 45.0k]
  ------------------
  708|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  45.0k|	}
  710|  45.0k|	apdu.lc = pathlen;
  711|  45.0k|	apdu.data = path;
  712|  45.0k|	apdu.datalen = pathlen;
  713|       |
  714|  45.0k|	if (file_out != NULL) {
  ------------------
  |  Branch (714:6): [True: 28.9k, False: 16.0k]
  ------------------
  715|  28.9k|		apdu.p2 = 0;		/* first record, return FCI */
  716|  28.9k|		apdu.resp = buf;
  717|  28.9k|		apdu.resplen = sizeof(buf);
  718|  28.9k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (718:13): [True: 848, False: 28.0k]
  ------------------
  719|  28.9k|	}
  720|  16.0k|	else {
  721|  16.0k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  722|  16.0k|		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
              		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  32.1k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (722:14): [True: 0, False: 16.0k]
  ------------------
  723|  16.0k|	}
  724|       |
  725|  45.0k|	r = sc_transmit_apdu(card, &apdu);
  726|  45.0k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  45.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  45.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  45.0k|	int _ret = (r); \
  |  |  |  |  168|  45.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 418, False: 44.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|    418|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    418|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    418|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    418|		return _ret; \
  |  |  |  |  172|    418|	} \
  |  |  |  |  173|  45.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|  44.6k|	if (file_out == NULL) {
  ------------------
  |  Branch (727:6): [True: 16.0k, False: 28.5k]
  ------------------
  728|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  729|  16.0k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  730|  16.0k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (730:7): [True: 134, False: 15.9k]
  |  Branch (730:27): [True: 31, False: 103]
  ------------------
  731|     31|			apdu.p2 = 0x00;
  732|     31|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     31|#define SC_SUCCESS				0
  ------------------
  |  Branch (732:8): [True: 20, False: 11]
  ------------------
  733|     20|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  734|     31|		}
  735|  16.0k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (735:7): [True: 0, False: 16.0k]
  ------------------
  736|  16.0k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|  16.0k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  16.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.0k|	int _ret = r; \
  |  |  |  |  155|  16.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.0k, False: 4.05k]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  16.0k|	return _ret; \
  |  |  |  |  163|  16.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  738|  16.0k|	}
  739|       |
  740|  28.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  741|  28.5k|	if (r)
  ------------------
  |  Branch (741:6): [True: 17.6k, False: 10.8k]
  ------------------
  742|  28.5k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  17.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.6k|	int _ret = r; \
  |  |  |  |  155|  17.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  17.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.6k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  17.6k|	return _ret; \
  |  |  |  |  163|  17.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  743|       |
  744|  10.8k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (744:6): [True: 10.8k, False: 0]
  |  Branch (744:18): [True: 2.03k, False: 8.81k]
  ------------------
  745|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  746|  2.03k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.52k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (746:7): [True: 504, False: 1.52k]
  |  Branch (746:20): [True: 1.33k, False: 189]
  ------------------
  747|  1.84k|			file = sc_file_new();
  748|  1.84k|			if (file == NULL)
  ------------------
  |  Branch (748:8): [True: 0, False: 1.84k]
  ------------------
  749|  1.84k|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  750|  1.84k|			file->path = *in_path;
  751|       |
  752|  1.84k|			*file_out = file;
  753|  1.84k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  754|  1.84k|		}
  755|  2.03k|	}
  756|       |
  757|  9.00k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (757:6): [True: 311, False: 8.69k]
  ------------------
  758|  9.00k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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: 311, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    311|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    311|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 311, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    311|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    311|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    311|	return _ret; \
  |  |  |  |  163|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  759|  8.69k|	switch (apdu.resp[0]) {
  760|  8.04k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  8.04k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (760:2): [True: 8.04k, False: 650]
  ------------------
  761|  8.29k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  8.29k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (761:2): [True: 253, False: 8.44k]
  ------------------
  762|  8.29k|		file = sc_file_new();
  763|  8.29k|		if (file == NULL)
  ------------------
  |  Branch (763:7): [True: 0, False: 8.29k]
  ------------------
  764|  8.29k|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  765|  8.29k|		file->path = *in_path;
  766|  8.29k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (766:7): [True: 0, False: 8.29k]
  ------------------
  767|      0|			sc_file_free(file);
  768|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  769|      0|		}
  770|  8.29k|		buffer = apdu.resp;
  771|  8.29k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  772|  8.29k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  8.29k|#define SC_SUCCESS				0
  ------------------
  |  Branch (772:7): [True: 7.50k, False: 793]
  ------------------
  773|  7.50k|			card->ops->process_fci(card, file, buffer, buffer_len);
  774|  8.29k|		*file_out = file;
  775|  8.29k|		break;
  776|     83|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (776:2): [True: 83, False: 8.61k]
  ------------------
  777|     83|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 83, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|    314|	default:
  ------------------
  |  Branch (778:2): [True: 314, False: 8.38k]
  ------------------
  779|    314|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|  8.69k|	}
  781|       |
  782|  8.29k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.29k|#define SC_SUCCESS				0
  ------------------
  783|  8.69k|}
iso7816.c:iso7816_get_response:
  906|  45.0k|{
  907|  45.0k|	struct sc_apdu apdu = {0};
  908|  45.0k|	int r;
  909|  45.0k|	size_t rlen;
  910|       |
  911|       |	/* request at most max_recv_size bytes */
  912|  45.0k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (912:6): [True: 2.35k, False: 42.6k]
  ------------------
  913|  2.35k|		rlen = sc_get_max_recv_size(card);
  914|  42.6k|	else
  915|  42.6k|		rlen = *count;
  916|       |
  917|  45.0k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  45.0k|#define SC_APDU_CASE_2			0x22
  ------------------
  918|  45.0k|	apdu.le      = rlen;
  919|  45.0k|	apdu.resplen = rlen;
  920|  45.0k|	apdu.resp    = buf;
  921|       |	/* don't call GET RESPONSE recursively */
  922|  45.0k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  45.0k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  923|       |
  924|  45.0k|	r = sc_transmit_apdu(card, &apdu);
  925|  45.0k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  45.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  45.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  45.0k|	int _ret = (r); \
  |  |  |  |  168|  45.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 571, False: 44.4k]
  |  |  |  |  ------------------
  |  |  |  |  169|    571|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    571|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    571|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    571|		return _ret; \
  |  |  |  |  172|    571|	} \
  |  |  |  |  173|  45.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|       |
  927|  44.4k|	*count = apdu.resplen;
  928|       |
  929|  44.4k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (929:6): [True: 5.05k, False: 39.4k]
  ------------------
  930|  5.05k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  5.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.05k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.05k|	int _ret = r; \
  |  |  |  |  155|  5.05k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.05k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.03k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.03k, False: 2.01k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.05k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.05k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.05k|	return _ret; \
  |  |  |  |  163|  5.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  931|  5.05k|	}
  932|  39.4k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (932:6): [True: 27.3k, False: 12.1k]
  |  Branch (932:26): [True: 27.2k, False: 58]
  ------------------
  933|  27.2k|		r = 0;					/* no more data to read */
  934|  12.1k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (934:11): [True: 10.0k, False: 2.16k]
  ------------------
  935|  10.0k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (935:7): [True: 2.39k, False: 7.62k]
  ------------------
  936|  2.16k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (936:11): [True: 1.05k, False: 1.10k]
  |  Branch (936:31): [True: 994, False: 61]
  ------------------
  937|    994|		r = 0; /* Le not reached but file/record ended */
  938|  1.16k|	else
  939|  1.16k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  940|       |
  941|  39.4k|	return r;
  942|  44.4k|}
iso7816.c:iso7816_check_sw:
  111|   422k|{
  112|   422k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  113|   422k|	int i;
  114|       |
  115|       |	/* Handle special cases here */
  116|   422k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (116:6): [True: 197, False: 422k]
  ------------------
  117|    197|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  118|    197|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    197|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  119|    197|	}
  120|   422k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (120:6): [True: 186k, False: 235k]
  |  Branch (120:21): [True: 184k, False: 2.60k]
  ------------------
  121|   184k|		return SC_SUCCESS;
  ------------------
  |  |   28|   184k|#define SC_SUCCESS				0
  ------------------
  122|   238k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (122:6): [True: 411, False: 237k]
  |  Branch (122:22): [True: 142, False: 269]
  ------------------
  123|    142|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  124|    142|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    142|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  125|    142|	}
  126|  9.75M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (126:14): [True: 9.73M, False: 17.7k]
  ------------------
  127|  9.73M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (127:7): [True: 220k, False: 9.51M]
  ------------------
  128|   220k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   220k|#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|   220k|			return iso7816_errors[i].errorno;
  130|   220k|		}
  131|  9.73M|	}
  132|       |
  133|  17.7k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  17.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  134|  17.7k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  17.7k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  135|   238k|}
iso7816.c:iso7816_process_fci:
  431|  9.94k|{
  432|  9.94k|	struct sc_context *ctx = card->ctx;
  433|  9.94k|	const unsigned char *p, *end;
  434|  9.94k|	unsigned int cla = 0, tag = 0;
  435|  9.94k|	size_t length;
  436|       |
  437|  9.94k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.94k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  438|       |
  439|  9.94k|	for (p = buf, length = buflen, end = buf + buflen;
  440|  31.1k|			p < end;
  ------------------
  |  Branch (440:4): [True: 27.2k, False: 3.94k]
  ------------------
  441|  27.2k|			p += length, length = end - p) {
  442|       |
  443|  27.2k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  27.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:7): [True: 3.55k, False: 23.6k]
  ------------------
  444|  23.6k|				|| p == NULL) {
  ------------------
  |  Branch (444:8): [True: 2.44k, False: 21.2k]
  ------------------
  445|  6.00k|			break;
  446|  6.00k|		}
  447|  21.2k|		switch (cla | tag) {
  ------------------
  |  Branch (447:11): [True: 15.5k, False: 5.71k]
  ------------------
  448|    712|			case 0x81:
  ------------------
  |  Branch (448:4): [True: 712, False: 20.5k]
  ------------------
  449|    712|				if (file->size != 0) {
  ------------------
  |  Branch (449:9): [True: 220, False: 492]
  ------------------
  450|       |					/* don't overwrite existing file size excluding structural information */
  451|    220|					break;
  452|    220|				}
  453|       |				/* fall through */
  454|  4.91k|			case 0x80:
  ------------------
  |  Branch (454:4): [True: 4.42k, False: 16.8k]
  ------------------
  455|       |				/* determine the file size */
  456|  4.91k|				file->size = 0;
  457|  4.91k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (457:9): [True: 4.91k, False: 0]
  |  Branch (457:14): [True: 4.87k, False: 36]
  ------------------
  458|  4.87k|					size_t size = 0, i;
  459|  14.8k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (459:18): [True: 10.0k, False: 4.87k]
  ------------------
  460|  10.0k|						size <<= 8;
  461|  10.0k|						size |= p[i];
  462|  10.0k|					}
  463|  4.87k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  4.87k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (463:10): [True: 444, False: 4.43k]
  ------------------
  464|    444|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  229|    444|#define MAX_FILE_SIZE 65535
  ------------------
  465|    444|						sc_log(ctx, "  file size truncated, encoded length: %"SC_FORMAT_LEN_SIZE_T"u", size);
  ------------------
  |  |   71|    444|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|  4.43k|					} else {
  467|  4.43k|						file->size = size;
  468|  4.43k|					}
  469|  4.87k|				}
  470|       |
  471|  4.91k|				sc_log(ctx, "  bytes in file: %"SC_FORMAT_LEN_SIZE_T"u", file->size);
  ------------------
  |  |   71|  4.91k|#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.91k|				break;
  473|       |
  474|  2.92k|			case 0x82:
  ------------------
  |  Branch (474:4): [True: 2.92k, False: 18.3k]
  ------------------
  475|  2.92k|				if (length > 0) {
  ------------------
  |  Branch (475:9): [True: 2.60k, False: 314]
  ------------------
  476|  2.60k|					unsigned char byte = p[0];
  477|  2.60k|					const char *type;
  478|       |
  479|  2.60k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (479:24): [True: 269, False: 2.33k]
  ------------------
  480|  2.60k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  5.21k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 269, False: 2.33k]
  |  |  ------------------
  ------------------
  481|  2.60k|					file->ef_structure = byte & 0x07;
  482|  2.60k|					switch ((byte >> 3) & 7) {
  483|  1.65k|						case 0:
  ------------------
  |  Branch (483:7): [True: 1.65k, False: 952]
  ------------------
  484|  1.65k|							type = "working EF";
  485|  1.65k|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.65k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  486|  1.65k|							break;
  487|    221|						case 1:
  ------------------
  |  Branch (487:7): [True: 221, False: 2.38k]
  ------------------
  488|    221|							type = "internal EF";
  489|    221|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    221|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  490|    221|							break;
  491|    427|						case 7:
  ------------------
  |  Branch (491:7): [True: 427, False: 2.18k]
  ------------------
  492|    427|							type = "DF";
  493|    427|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    427|#define SC_FILE_TYPE_DF			0x04
  ------------------
  494|    427|							break;
  495|    304|						default:
  ------------------
  |  Branch (495:7): [True: 304, False: 2.30k]
  ------------------
  496|    304|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    304|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  497|    304|							type = "unknown";
  498|    304|							break;
  499|  2.60k|					}
  500|  2.60k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  501|  2.60k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  502|  2.60k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  503|       |
  504|       |					/* if possible, get additional information for non-DFs */
  505|  2.60k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  2.60k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (505:10): [True: 2.18k, False: 427]
  ------------------
  506|       |						/* max. record length for fixed- & variable-sized records */
  507|  2.18k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (507:11): [True: 539, False: 1.64k]
  |  Branch (507:25): [True: 383, False: 156]
  ------------------
  508|    383|							file->record_length = (length > 3)
  ------------------
  |  Branch (508:30): [True: 212, False: 171]
  ------------------
  509|    383|								? bebytes2ushort(p+2)
  510|    383|								: p[2];
  511|    383|							sc_log(ctx, "  record length: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   71|    383|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  512|    383|								file->record_length);
  513|    383|						}
  514|       |
  515|       |						/* number of records */
  516|  2.18k|						if (length > 4) {
  ------------------
  |  Branch (516:11): [True: 307, False: 1.87k]
  ------------------
  517|    307|							file->record_count = (length > 5)
  ------------------
  |  Branch (517:29): [True: 146, False: 161]
  ------------------
  518|    307|								? bebytes2ushort(p+4)
  519|    307|								: p[4];
  520|    307|							sc_log(ctx, "  records: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   71|    307|#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|    307|								file->record_count);
  522|    307|						}
  523|  2.18k|					}
  524|       |
  525|  2.60k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  2.60k|#define SC_SUCCESS				0
  ------------------
  |  Branch (525:10): [True: 0, False: 2.60k]
  ------------------
  526|      0|						sc_log(ctx, "Warning: Could not set file attributes");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  527|  2.60k|				}
  528|  2.92k|				break;
  529|       |
  530|  2.92k|			case 0x83:
  ------------------
  |  Branch (530:4): [True: 1.06k, False: 20.1k]
  ------------------
  531|  1.06k|				if (length == 2) {
  ------------------
  |  Branch (531:9): [True: 946, False: 118]
  ------------------
  532|    946|					file->id = (p[0] << 8) | p[1];
  533|    946|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|    946|#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|    946|				}
  535|  1.06k|				break;
  536|       |
  537|    830|			case 0x84:
  ------------------
  |  Branch (537:4): [True: 830, False: 20.3k]
  ------------------
  538|    830|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (538:9): [True: 741, False: 89]
  |  Branch (538:23): [True: 722, False: 19]
  ------------------
  539|    722|					memcpy(file->name, p, length);
  540|    722|					file->namelen = length;
  541|       |
  542|    722|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    722|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    722|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  543|    722|					if (!file->type)
  ------------------
  |  Branch (543:10): [True: 353, False: 369]
  ------------------
  544|    353|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    353|#define SC_FILE_TYPE_DF			0x04
  ------------------
  545|    722|				}
  546|    830|				break;
  547|       |
  548|    880|			case 0x85:
  ------------------
  |  Branch (548:4): [True: 880, False: 20.3k]
  ------------------
  549|  1.34k|			case 0xA5:
  ------------------
  |  Branch (549:4): [True: 467, False: 20.7k]
  ------------------
  550|  1.34k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.34k|#define SC_SUCCESS				0
  ------------------
  |  Branch (550:9): [True: 0, False: 1.34k]
  ------------------
  551|      0|					sc_log(ctx, "Warning: Could not set proprietary file properties");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  552|      0|				}
  553|  1.34k|				break;
  554|       |
  555|  1.10k|			case 0x86:
  ------------------
  |  Branch (555:4): [True: 1.10k, False: 20.1k]
  ------------------
  556|  1.10k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.10k|#define SC_SUCCESS				0
  ------------------
  |  Branch (556:9): [True: 0, False: 1.10k]
  ------------------
  557|      0|					sc_log(ctx, "Warning: Could not set file security properties");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  558|      0|				}
  559|  1.10k|				break;
  560|       |
  561|    423|			case 0x88:
  ------------------
  |  Branch (561:4): [True: 423, False: 20.8k]
  ------------------
  562|    423|				if (length == 1) {
  ------------------
  |  Branch (562:9): [True: 68, False: 355]
  ------------------
  563|     68|					file->sid = *p;
  564|     68|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  565|     68|				}
  566|    423|				break;
  567|       |
  568|  1.51k|			case 0x8A:
  ------------------
  |  Branch (568:4): [True: 1.51k, False: 19.7k]
  ------------------
  569|  1.51k|				if (length == 1) {
  ------------------
  |  Branch (569:9): [True: 1.43k, False: 77]
  ------------------
  570|  1.43k|					switch (p[0]) {
  571|     67|						case 0:
  ------------------
  |  Branch (571:7): [True: 67, False: 1.37k]
  ------------------
  572|     67|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     67|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  573|     67|							break;
  574|     76|						case 1:
  ------------------
  |  Branch (574:7): [True: 76, False: 1.36k]
  ------------------
  575|     76|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     76|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  576|     76|							break;
  577|     67|						case 3:
  ------------------
  |  Branch (577:7): [True: 67, False: 1.37k]
  ------------------
  578|     67|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     67|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  579|     67|							break;
  580|     66|						case 4:
  ------------------
  |  Branch (580:7): [True: 66, False: 1.37k]
  ------------------
  581|    133|						case 6:
  ------------------
  |  Branch (581:7): [True: 67, False: 1.37k]
  ------------------
  582|    133|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    133|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  583|    133|							break;
  584|    382|						case 5:
  ------------------
  |  Branch (584:7): [True: 382, False: 1.05k]
  ------------------
  585|    449|						case 7:
  ------------------
  |  Branch (585:7): [True: 67, False: 1.37k]
  ------------------
  586|    449|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    449|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  587|    449|							break;
  588|     66|						case 12:
  ------------------
  |  Branch (588:7): [True: 66, False: 1.37k]
  ------------------
  589|    134|						case 13:
  ------------------
  |  Branch (589:7): [True: 68, False: 1.37k]
  ------------------
  590|    155|						case 14:
  ------------------
  |  Branch (590:7): [True: 21, False: 1.41k]
  ------------------
  591|    222|						case 15:
  ------------------
  |  Branch (591:7): [True: 67, False: 1.37k]
  ------------------
  592|    222|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    222|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  593|    222|							break;
  594|     67|						case 2:
  ------------------
  |  Branch (594:7): [True: 67, False: 1.37k]
  ------------------
  595|     67|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     67|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  596|     67|							break;
  597|     66|						case 8:
  ------------------
  |  Branch (597:7): [True: 66, False: 1.37k]
  ------------------
  598|     66|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     66|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  599|     66|							break;
  600|     66|						case 9:
  ------------------
  |  Branch (600:7): [True: 66, False: 1.37k]
  ------------------
  601|     66|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     66|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  602|     66|							break;
  603|     66|						case 10:
  ------------------
  |  Branch (603:7): [True: 66, False: 1.37k]
  ------------------
  604|     66|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     66|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  605|     66|							break;
  606|     66|						case 11:
  ------------------
  |  Branch (606:7): [True: 66, False: 1.37k]
  ------------------
  607|     66|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     66|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  608|     66|							break;
  609|     94|						default:
  ------------------
  |  Branch (609:7): [True: 94, False: 1.34k]
  ------------------
  610|     94|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|     94|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  611|  1.43k|					}
  612|  1.43k|				}
  613|  1.51k|				break;
  614|       |
  615|  1.51k|			case 0x62:
  ------------------
  |  Branch (615:4): [True: 871, False: 20.3k]
  ------------------
  616|  1.06k|			case 0x64:
  ------------------
  |  Branch (616:4): [True: 195, False: 21.0k]
  ------------------
  617|  1.17k|			case 0x6F:
  ------------------
  |  Branch (617:4): [True: 109, False: 21.1k]
  ------------------
  618|       |				/* allow nested FCP/FMD/FCI templates */
  619|  1.17k|				iso7816_process_fci(card, file, p, length);
  620|  21.2k|		}
  621|  21.2k|	}
  622|       |
  623|  9.94k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  9.94k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  624|       |
  625|  9.94k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.94k|#define SC_SUCCESS				0
  ------------------
  626|  9.94k|}
iso7816.c:iso7816_pin_cmd:
 1288|    692|{
 1289|    692|	struct sc_apdu local_apdu, *apdu;
 1290|    692|	int r;
 1291|    692|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1292|       |
 1293|    692|	data->pin1.tries_left = -1;
 1294|       |
 1295|       |	/* Many cards do support PIN status queries, but some cards don't and
 1296|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1297|       |	 * allow cards with this flag.  In future this may be reduced to a
 1298|       |	 * blocklist, subject to testing more cards. */
 1299|    692|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  425|  1.38k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1299:6): [True: 692, False: 0]
  ------------------
 1300|    692|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  560|    692|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1300:6): [True: 147, False: 545]
  ------------------
 1301|    147|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    147|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1302|    147|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    147|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1303|    147|	}
 1304|       |
 1305|       |	/* See if we've been called from another card driver, which is
 1306|       |	 * passing an APDU to us (this allows to write card drivers
 1307|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1308|       |	 * special circumstances.
 1309|       |	 */
 1310|    545|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1310:6): [True: 545, False: 0]
  ------------------
 1311|    545|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1312|    545|		if (r < 0)
  ------------------
  |  Branch (1312:7): [True: 17, False: 528]
  ------------------
 1313|     17|			return r;
 1314|    528|		data->apdu = &local_apdu;
 1315|    528|	}
 1316|    528|	apdu = data->apdu;
 1317|       |
 1318|    528|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  428|    528|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
              	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  425|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1318:6): [True: 528, False: 0]
  |  Branch (1318:48): [True: 0, False: 0]
  ------------------
 1319|       |		/* Transmit the APDU to the card */
 1320|    528|		r = sc_transmit_apdu(card, apdu);
 1321|       |
 1322|       |		/* Clear the buffer - it may contain pins */
 1323|    528|		sc_mem_clear(sbuf, sizeof(sbuf));
 1324|    528|	}
 1325|      0|	else {
 1326|       |		/* Call the reader driver to collect
 1327|       |		 * the PIN and pass on the APDU to the card */
 1328|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1328:7): [True: 0, False: 0]
  ------------------
 1329|      0|			sc_log(card->ctx, "Card driver didn't set PIN offset");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1330|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1331|      0|		}
 1332|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1332:7): [True: 0, False: 0]
  |  Branch (1332:23): [True: 0, False: 0]
  |  Branch (1332:44): [True: 0, False: 0]
  ------------------
 1333|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1334|       |			/* sw1/sw2 filled in by reader driver */
 1335|      0|		}
 1336|      0|		else {
 1337|      0|			sc_log(card->ctx, "Card reader driver does not support "
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1338|      0|					"PIN entry through reader key pad");
 1339|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1340|      0|		}
 1341|      0|	}
 1342|       |
 1343|       |	/* Don't pass references to local variables up to the caller. */
 1344|    528|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1344:6): [True: 528, False: 0]
  ------------------
 1345|    528|		data->apdu = NULL;
 1346|       |
 1347|    528|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    528|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    528|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    528|	int _ret = (r); \
  |  |  |  |  168|    528|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 510]
  |  |  |  |  ------------------
  |  |  |  |  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|    528|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 510]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1348|    510|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1349|       |
 1350|    510|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    510|#define SC_SUCCESS				0
  ------------------
  |  Branch (1350:6): [True: 354, False: 156]
  ------------------
 1351|    354|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|    354|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1352|    354|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|    156|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1352:13): [True: 10, False: 146]
  ------------------
 1353|     10|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1354|     10|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|     10|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1355|     10|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|     10|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1355:7): [True: 10, False: 0]
  ------------------
 1356|     10|			r = SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
 1357|    146|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|    146|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1357:13): [True: 1, False: 145]
  ------------------
 1358|      1|		data->pin1.tries_left = 0;
 1359|      1|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      1|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1360|      1|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|      1|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1360:7): [True: 1, False: 0]
  ------------------
 1361|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1362|      1|	}
 1363|       |
 1364|    510|	return r;
 1365|    528|}
iso7816.c:iso7816_get_data:
 1369|    230|{
 1370|    230|	int                             r, cse;
 1371|    230|	struct sc_apdu                  apdu;
 1372|       |
 1373|    230|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1374|       |
 1375|    230|	if (buf && len)
  ------------------
  |  Branch (1375:6): [True: 230, False: 0]
  |  Branch (1375:13): [True: 230, False: 0]
  ------------------
 1376|    230|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    230|#define SC_APDU_CASE_2			0x22
  ------------------
 1377|      0|	else
 1378|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1379|       |
 1380|    230|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1381|    230|	apdu.le = len;
 1382|    230|	apdu.resp = buf;
 1383|    230|	apdu.resplen = len;
 1384|    230|	r = sc_transmit_apdu(card, &apdu);
 1385|    230|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    230|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    230|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    230|	int _ret = (r); \
  |  |  |  |  168|    230|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 223]
  |  |  |  |  ------------------
  |  |  |  |  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|    230|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 223]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1386|       |
 1387|    223|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1388|    223|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|    223|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    223|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    223|	int _ret = (r); \
  |  |  |  |  168|    223|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 84, False: 139]
  |  |  |  |  ------------------
  |  |  |  |  169|     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
  |  |  |  |  ------------------
  |  |  |  |  170|     84|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     84|		return _ret; \
  |  |  |  |  172|     84|	} \
  |  |  |  |  173|    223|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 139]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1389|       |
 1390|    139|	if (apdu.resplen > len)
  ------------------
  |  Branch (1390:6): [True: 0, False: 139]
  ------------------
 1391|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1392|    139|	else
 1393|    139|		r = (int)apdu.resplen;
 1394|       |
 1395|    139|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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: 34, False: 105]
  |  |  |  |  ------------------
  |  |  |  |  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|    105|	} else { \
  |  |  |  |  159|    105|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    105|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    105|	} \
  |  |  |  |  162|    139|	return _ret; \
  |  |  |  |  163|    139|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1396|    139|}
iso7816.c:iso7816_read_binary:
  140|  48.7k|{
  141|  48.7k|	struct sc_context *ctx = card->ctx;
  142|  48.7k|	struct sc_apdu apdu;
  143|  48.7k|	int r;
  144|       |
  145|  48.7k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (145:6): [True: 16, False: 48.7k]
  ------------------
  146|     16|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  147|     16|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|     16|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  148|     16|	}
  149|       |
  150|  48.7k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  48.7k|#define SC_APDU_CASE_2			0x22
  ------------------
  151|  48.7k|	apdu.le = count;
  152|  48.7k|	apdu.resplen = count;
  153|  48.7k|	apdu.resp = buf;
  154|       |
  155|  48.7k|	iso7816_fixup_transceive_length(card, &apdu);
  156|  48.7k|	r = sc_transmit_apdu(card, &apdu);
  157|  48.7k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  48.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  48.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  48.7k|	int _ret = (r); \
  |  |  |  |  168|  48.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 333, False: 48.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|    333|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    333|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    333|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    333|		return _ret; \
  |  |  |  |  172|    333|	} \
  |  |  |  |  173|  48.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|       |
  159|  48.3k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  160|  48.3k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  96.7k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  48.2k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (160:6): [True: 150, False: 48.2k]
  |  Branch (160:40): [True: 45, False: 48.1k]
  ------------------
  161|  48.3k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    195|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    195|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    195|	int _ret = r; \
  |  |  |  |  155|    195|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 73, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  156|     73|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  157|     73|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    122|	} 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|    195|	return _ret; \
  |  |  |  |  163|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|  48.1k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  48.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  48.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  48.1k|	int _ret = (r); \
  |  |  |  |  168|  48.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.86k, False: 44.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.86k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.86k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.86k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.86k|		return _ret; \
  |  |  |  |  172|  3.86k|	} \
  |  |  |  |  173|  48.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|  44.3k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  44.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  44.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  44.3k|	int _ret = r; \
  |  |  |  |  155|  44.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 857, False: 43.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|    857|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 857]
  |  |  |  |  ------------------
  |  |  |  |  157|    857|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  43.4k|	} else { \
  |  |  |  |  159|  43.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  43.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  43.4k|	} \
  |  |  |  |  162|  44.3k|	return _ret; \
  |  |  |  |  163|  44.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|  44.3k|}

sc_do_log:
   58|  14.8M|{
   59|  14.8M|	va_list ap;
   60|       |
   61|  14.8M|	va_start(ap, format);
   62|  14.8M|	sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
   63|       |	va_end(ap);
   64|  14.8M|}
sc_do_log_color:
   67|  2.82M|{
   68|  2.82M|	va_list ap;
   69|       |
   70|  2.82M|	va_start(ap, format);
   71|  2.82M|	sc_do_log_va(ctx, level, file, line, func, color, format, ap);
   72|       |	va_end(ap);
   73|  2.82M|}
sc_do_log_openssl:
   77|    311|{
   78|    311|	BIO *bio = NULL;
   79|    311|	int length, rc;
   80|    311|	char *buffer = NULL;
   81|       |
   82|    311|	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
  ------------------
  |  Branch (82:6): [True: 0, False: 311]
  ------------------
   83|      0|		sc_do_log(ctx, level, file, line, func, "Cannot log OpenSSL error");
   84|      0|		goto end;
   85|      0|	}
   86|    311|	ERR_print_errors(bio);
   87|       |
   88|    311|	length = BIO_pending(bio);
   89|    311|	if (length <= 0) {
  ------------------
  |  Branch (89:6): [True: 0, False: 311]
  ------------------
   90|       |		/* no error? */
   91|      0|		goto end;
   92|      0|	}
   93|       |	/* trailing null byte */
   94|    311|	buffer = malloc(length + 1);
   95|    311|	if (buffer == NULL) {
  ------------------
  |  Branch (95:6): [True: 0, False: 311]
  ------------------
   96|      0|		sc_do_log(ctx, level, file, line, func, "No memory!");
   97|      0|		goto end;
   98|      0|	}
   99|    311|	rc = BIO_read(bio, buffer, length);
  100|    311|	buffer[length] = '\0';
  101|    311|	if (rc <= 0) {
  ------------------
  |  Branch (101:6): [True: 0, False: 311]
  ------------------
  102|      0|		sc_do_log(ctx, level, file, line, func, "Cannot read OpenSSL error");
  103|      0|		goto end;
  104|      0|	}
  105|       |
  106|    311|	sc_do_log(ctx, level, file, line, func, "OpenSSL error\n%s", buffer);
  107|    311|end:
  108|    311|	free(buffer);
  109|    311|	BIO_free(bio);
  110|    311|}
_sc_debug_hex:
  343|   417k|{
  344|   417k|	size_t blen = len * 5 + 128;
  345|   417k|	char *buf = malloc(blen);
  346|   417k|	if (buf == NULL)
  ------------------
  |  Branch (346:6): [True: 0, False: 417k]
  ------------------
  347|      0|		return;
  348|       |
  349|   417k|	sc_hex_dump(data, len, buf, blen);
  350|       |
  351|   417k|	if (label)
  ------------------
  |  Branch (351:6): [True: 417k, False: 0]
  ------------------
  352|   417k|		sc_do_log(ctx, type, file, line, func,
  353|   417k|			"\n%s (%"SC_FORMAT_LEN_SIZE_T"u byte%s):\n%s",
  354|   417k|			label, len, len==1?"":"s", buf);
  ------------------
  |  Branch (354:16): [True: 990, False: 416k]
  ------------------
  355|      0|	else
  356|      0|		sc_do_log(ctx, type, file, line, func,
  357|      0|			"%"SC_FORMAT_LEN_SIZE_T"u byte%s:\n%s",
  358|      0|			len, len==1?"":"s", buf);
  ------------------
  |  Branch (358:9): [True: 0, False: 0]
  ------------------
  359|       |
  360|   417k|	free(buf);
  361|   417k|}
sc_hex_dump:
  364|   417k|{
  365|   417k|	char *p = buf;
  366|   417k|	size_t p_len = len;
  367|   417k|	int lines = 0;
  368|       |
  369|   417k|	if (buf == NULL || (in == NULL && count != 0)) {
  ------------------
  |  Branch (369:6): [True: 0, False: 417k]
  |  Branch (369:22): [True: 414, False: 417k]
  |  Branch (369:36): [True: 0, False: 414]
  ------------------
  370|      0|		return;
  371|      0|	}
  372|   417k|	buf[0] = 0;
  373|   417k|	if ((count * 5) > len)
  ------------------
  |  Branch (373:6): [True: 0, False: 417k]
  ------------------
  374|      0|		return;
  375|  2.35M|	while (count) {
  ------------------
  |  Branch (375:9): [True: 1.93M, False: 417k]
  ------------------
  376|  1.93M|		char ascbuf[17];
  377|  1.93M|		size_t i;
  378|       |
  379|  30.5M|		for (i = 0; i < count && i < 16; i++) {
  ------------------
  |  Branch (379:15): [True: 30.1M, False: 336k]
  |  Branch (379:28): [True: 28.5M, False: 1.59M]
  ------------------
  380|  28.5M|			sprintf(p, "%02X ", *in);
  381|  28.5M|			if (isprint(*in))
  ------------------
  |  Branch (381:8): [True: 17.6M, False: 10.9M]
  ------------------
  382|  17.6M|				ascbuf[i] = *in;
  383|  10.9M|			else
  384|  10.9M|				ascbuf[i] = '.';
  385|  28.5M|			p += 3;
  386|  28.5M|			p_len -= 3;
  387|  28.5M|			in++;
  388|  28.5M|		}
  389|  1.93M|		count -= i;
  390|  1.93M|		ascbuf[i] = 0;
  391|  2.35M|		for (; i < 16 && lines; i++) {
  ------------------
  |  Branch (391:10): [True: 601k, False: 1.75M]
  |  Branch (391:20): [True: 423k, False: 178k]
  ------------------
  392|   423k|			strlcat(p, "   ", p_len);
  393|   423k|			p += 3;
  394|   423k|			p_len -= 3;
  395|   423k|		}
  396|  1.93M|		snprintf(p, p_len, "%s\n", ascbuf);
  397|  1.93M|		p += strlen(ascbuf) + 1;
  398|  1.93M|		p_len -= strlen(ascbuf) - 1;
  399|  1.93M|		lines++;
  400|  1.93M|	}
  401|   417k|}
sc_dump_hex:
  405|   190k|{
  406|   190k|	static char dump_buf[0x1000];
  407|   190k|	size_t ii, size = sizeof(dump_buf) - 0x10;
  408|   190k|	size_t offs = 0;
  409|       |
  410|   190k|	memset(dump_buf, 0, sizeof(dump_buf));
  411|   190k|	if (in == NULL)
  ------------------
  |  Branch (411:6): [True: 0, False: 190k]
  ------------------
  412|      0|		return dump_buf;
  413|       |
  414|   709k|	for (ii=0; ii<count; ii++) {
  ------------------
  |  Branch (414:13): [True: 519k, False: 190k]
  ------------------
  415|   519k|		if (ii && !(ii%16))   {
  ------------------
  |  Branch (415:7): [True: 452k, False: 66.8k]
  |  Branch (415:13): [True: 3.73k, False: 448k]
  ------------------
  416|  3.73k|			if (!(ii%48))
  ------------------
  |  Branch (416:8): [True: 1.13k, False: 2.60k]
  ------------------
  417|  1.13k|				snprintf(dump_buf + offs, size - offs, "\n");
  418|  2.60k|			else
  419|  2.60k|				snprintf(dump_buf + offs, size - offs, " ");
  420|  3.73k|			offs = strlen(dump_buf);
  421|  3.73k|		}
  422|       |
  423|   519k|		snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
  424|   519k|		offs += 2;
  425|       |
  426|   519k|		if (offs > size)
  ------------------
  |  Branch (426:7): [True: 0, False: 519k]
  ------------------
  427|      0|			break;
  428|   519k|	}
  429|       |
  430|   190k|	if (ii<count)
  ------------------
  |  Branch (430:6): [True: 0, False: 190k]
  ------------------
  431|      0|		snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
  432|       |
  433|   190k|	return dump_buf;
  434|   190k|}
sc_dump_oid:
  438|  3.84k|{
  439|  3.84k|	static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
  440|  3.84k|        size_t ii;
  441|       |
  442|  3.84k|	memset(dump_buf, 0, sizeof(dump_buf));
  443|  3.84k|	if (oid)
  ------------------
  |  Branch (443:6): [True: 3.84k, False: 0]
  ------------------
  444|  21.1k|		for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
  ------------------
  |  |   46|  42.2k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (444:14): [True: 21.1k, False: 0]
  |  Branch (444:44): [True: 17.2k, False: 3.84k]
  ------------------
  445|  17.2k|			snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
  ------------------
  |  Branch (445:88): [True: 13.4k, False: 3.84k]
  ------------------
  446|       |
  447|  3.84k|	return dump_buf;
  448|  3.84k|}
log.c:sc_do_log_va:
  124|  17.6M|{
  125|       |#ifdef _WIN32
  126|       |	SYSTEMTIME st;
  127|       |#else
  128|  17.6M|	struct tm *tm;
  129|  17.6M|	struct timeval tv;
  130|  17.6M|	char time_string[40];
  131|  17.6M|#endif
  132|       |
  133|  17.6M|	if (!ctx || ctx->debug < level)
  ------------------
  |  Branch (133:6): [True: 0, False: 17.6M]
  |  Branch (133:14): [True: 17.6M, False: 0]
  ------------------
  134|  17.6M|		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|    573|mscfs_t *mscfs_new(void) {
   46|    573|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   47|    573|	if (!fs)
  ------------------
  |  Branch (47:6): [True: 0, False: 573]
  ------------------
   48|      0|		return NULL;
   49|    573|	memset(fs, 0, sizeof(mscfs_t));
   50|    573|	memcpy(fs->currentPath, "\x3F\x00", 2);
   51|    573|	return fs;
   52|    573|}
mscfs_free:
   54|    573|void mscfs_free(mscfs_t *fs) {
   55|    573|	mscfs_clear_cache(fs);
   56|    573|	free(fs);
   57|    573|}
mscfs_clear_cache:
   59|  1.88k|void mscfs_clear_cache(mscfs_t* fs) {
   60|  1.88k|	if(!fs->cache.array) {
  ------------------
  |  Branch (60:5): [True: 1.47k, False: 412]
  ------------------
   61|  1.47k|		return;
   62|  1.47k|	}
   63|    412|	free(fs->cache.array);
   64|       |	fs->cache.array = NULL;
   65|    412|	fs->cache.totalSize = 0;
   66|    412|	fs->cache.size = 0;
   67|    412|}
mscfs_push_file:
   83|  34.8k|{
   84|  34.8k|	mscfs_cache_t *cache = &fs->cache;
   85|  34.8k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   81|  34.8k|#define MAX_FILES 10000
  ------------------
  |  Branch (85:6): [True: 1, False: 34.8k]
  ------------------
   86|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
   87|  34.8k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (87:5): [True: 412, False: 34.3k]
  |  Branch (87:22): [True: 261, False: 34.1k]
  ------------------
   88|    673|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   35|    673|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   89|    673|		mscfs_file_t *oldArray;
   90|    673|		cache->totalSize = length;
   91|    673|		oldArray = cache->array;
   92|    673|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   93|    673|		if(!cache->array)
  ------------------
  |  Branch (93:6): [True: 0, False: 673]
  ------------------
   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|    673|		if(oldArray) {
  ------------------
  |  Branch (95:6): [True: 261, False: 412]
  ------------------
   96|    261|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   97|    261|			free(oldArray);
   98|    261|		}
   99|    673|	}
  100|  34.8k|	cache->array[cache->size] = *file;
  101|  34.8k|	cache->size++;
  102|  34.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  34.8k|#define SC_SUCCESS				0
  ------------------
  103|  34.8k|}
mscfs_update_cache:
  105|  1.31k|int mscfs_update_cache(mscfs_t* fs) {
  106|  1.31k|	mscfs_file_t file;
  107|  1.31k|	int r;
  108|  1.31k|	mscfs_clear_cache(fs);
  109|  1.31k|	r = fs->listFile(&file, 1, fs->udata);
  110|  1.31k|	if(r == 0)
  ------------------
  |  Branch (110:5): [True: 83, False: 1.23k]
  ------------------
  111|     83|		return 0;
  112|  1.23k|	else if(r < 0)
  ------------------
  |  Branch (112:10): [True: 787, False: 445]
  ------------------
  113|    787|		return r;
  114|  34.9k|	while(1) {
  ------------------
  |  Branch (114:8): [True: 34.9k, Folded]
  ------------------
  115|  34.9k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (115:6): [True: 34.8k, False: 113]
  ------------------
  116|       |			/* Check if its a directory in the root */
  117|  34.8k|			u8* oid = file.objectId.id;
  118|  34.8k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (118:7): [True: 9.35k, False: 25.4k]
  |  Branch (118:22): [True: 7.03k, False: 2.32k]
  ------------------
  119|  7.03k|				oid[2] = oid[0];
  120|  7.03k|				oid[3] = oid[1];
  121|  7.03k|				oid[0] = 0x3F;
  122|  7.03k|				oid[1] = 0x00;
  123|  7.03k|				file.ef = 0;
  124|  27.7k|			} else  {
  125|  27.7k|				file.ef = 1; /* File is a working elementary file */
  126|  27.7k|			}
  127|       |
  128|  34.8k|			r = mscfs_push_file(fs, &file);
  129|  34.8k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  34.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (129:8): [True: 1, False: 34.8k]
  ------------------
  130|      1|				return r;
  131|  34.8k|		}
  132|  34.9k|		r = fs->listFile(&file, 0, fs->udata);
  133|  34.9k|		if(r == 0)
  ------------------
  |  Branch (133:6): [True: 165, False: 34.7k]
  ------------------
  134|    165|			break;
  135|  34.7k|		else if(r < 0)
  ------------------
  |  Branch (135:11): [True: 279, False: 34.4k]
  ------------------
  136|    279|			return r;
  137|  34.9k|	}
  138|    165|	return fs->cache.size;
  139|    445|}
mscfs_check_cache:
  142|  3.78k|{
  143|  3.78k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.78k|#define SC_SUCCESS				0
  ------------------
  144|  3.78k|	if(!fs->cache.array) {
  ------------------
  |  Branch (144:5): [True: 1.31k, False: 2.47k]
  ------------------
  145|  1.31k|		r = mscfs_update_cache(fs);
  146|  1.31k|	}
  147|  3.78k|	return r;
  148|  3.78k|}
mscfs_lookup_path:
  151|  1.73k|{
  152|  1.73k|	u8* oid = objectId->id;
  153|  1.73k|	if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (153:6): [True: 721, False: 1.01k]
  ------------------
  154|    721|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|    721|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    721|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  155|  1.01k|	if(isDirectory) {
  ------------------
  |  Branch (155:5): [True: 0, False: 1.01k]
  ------------------
  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|  1.01k|	oid[0] = fs->currentPath[0];
  167|  1.01k|	oid[1] = fs->currentPath[1];
  168|       |	/* Chop off the root in the path */
  169|  1.01k|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (169:5): [True: 980, False: 36]
  |  Branch (169:20): [True: 956, False: 24]
  ------------------
  170|    956|		path += 2;
  171|    956|		pathlen -= 2;
  172|    956|		oid[0] = 0x3F;
  173|    956|		oid[1] = 0x00;
  174|    956|	}
  175|       |	/* Limit to a single directory */
  176|  1.01k|	if(pathlen > 4)
  ------------------
  |  Branch (176:5): [True: 6, False: 1.01k]
  ------------------
  177|      6|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|      6|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      6|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  178|       |	/* Reset to root */
  179|  1.01k|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (179:5): [True: 590, False: 420]
  |  Branch (179:21): [True: 5, False: 585]
  ------------------
  180|      5|		oid[0] = oid[2] = path[0];
  181|      5|		oid[1] = oid[3] = path[1];
  182|  1.00k|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (182:12): [True: 585, False: 420]
  ------------------
  183|    585|		oid[2] = path[0];
  184|    585|		oid[3] = path[1];
  185|    585|	} else if(pathlen == 4) {
  ------------------
  |  Branch (185:12): [True: 419, False: 1]
  ------------------
  186|    419|		oid[0] = path[0];
  187|    419|		oid[1] = path[1];
  188|    419|		oid[2] = path[2];
  189|    419|		oid[3] = path[3];
  190|    419|	}
  191|       |
  192|  1.01k|	return 0;
  193|  1.01k|}
mscfs_check_selection:
  207|    570|{
  208|    570|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (208:5): [True: 0, False: 570]
  |  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|    570|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (210:5): [True: 0, False: 570]
  |  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|    570|	return 0;
  213|    570|}
mscfs_loadFileInfo:
  216|  1.73k|{
  217|  1.73k|	msc_id fullPath = {{0, 0, 0, 0}};
  218|  1.73k|	int x, rc;
  219|  1.73k|	if (fs == NULL || path == NULL || file_data == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 1.73k]
  |  Branch (219:20): [True: 0, False: 1.73k]
  |  Branch (219:36): [True: 0, False: 1.73k]
  ------------------
  220|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  221|  1.73k|	rc = mscfs_lookup_path(fs, path, pathlen, &fullPath, 0);
  222|  1.73k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  1.73k|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:6): [True: 727, False: 1.01k]
  ------------------
  223|    727|		return rc;
  224|    727|	}
  225|       |
  226|       |	/* Obtain file information while checking if it exists */
  227|  1.01k|	rc = mscfs_check_cache(fs);
  228|  1.01k|	if (rc < 0)
  ------------------
  |  Branch (228:6): [True: 27, False: 983]
  ------------------
  229|     27|		return rc;
  230|    983|	if(idx) *idx = -1;
  ------------------
  |  Branch (230:5): [True: 983, False: 0]
  ------------------
  231|  67.8k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (231:13): [True: 67.3k, False: 565]
  ------------------
  232|  67.3k|		*file_data = &fs->cache.array[x];
  233|  67.3k|		if (*file_data) {
  ------------------
  |  Branch (233:7): [True: 67.3k, False: 0]
  ------------------
  234|  67.3k|			msc_id objectId;
  235|  67.3k|			objectId = (*file_data)->objectId;
  236|  67.3k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (236:7): [True: 418, False: 66.8k]
  ------------------
  237|    418|				if (idx)
  ------------------
  |  Branch (237:9): [True: 418, False: 0]
  ------------------
  238|    418|					*idx = x;
  239|    418|				break;
  240|    418|			}
  241|  66.8k|			*file_data = NULL;
  242|  66.8k|		}
  243|  67.3k|	}
  244|    983|	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: 565, False: 418]
  |  Branch (244:28): [True: 9, False: 556]
  |  Branch (244:79): [True: 324, False: 232]
  |  Branch (244:131): [True: 5, False: 227]
  ------------------
  245|    338|		static mscfs_file_t ROOT_FILE;
  246|    338|		ROOT_FILE.ef = 0;
  247|    338|		ROOT_FILE.size = 0;
  248|       |		/* Faked Root ID */
  249|    338|		ROOT_FILE.objectId = rootId;
  250|       |
  251|    338|		ROOT_FILE.read = 0;
  252|    338|		ROOT_FILE.write = 0x02; /* User Pin access */
  253|    338|		ROOT_FILE.delete = 0x02;
  254|       |
  255|    338|		*file_data = &ROOT_FILE;
  256|    338|		if(idx) *idx = -2;
  ------------------
  |  Branch (256:6): [True: 338, False: 0]
  ------------------
  257|    645|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (257:12): [True: 227, False: 418]
  ------------------
  258|    227|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   34|    227|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    227|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  259|    227|	}
  260|       |
  261|    756|	return 0;
  262|    983|}
muscle-filesystem.c:mscfs_is_ignored:
   70|  34.9k|{
   71|  34.9k|	int ignored = 0;
   72|  34.9k|	const u8** ptr = ignoredFiles;
   73|   104k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (73:8): [True: 104k, False: 0]
  |  Branch (73:15): [True: 69.8k, False: 34.9k]
  |  Branch (73:23): [True: 69.8k, False: 3]
  ------------------
   74|  69.8k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (74:6): [True: 113, False: 69.7k]
  ------------------
   75|    113|			ignored = 1;
   76|  69.8k|		ptr++;
   77|  69.8k|	}
   78|  34.9k|	return ignored;
   79|  34.9k|}

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

sc_asn1_decode_algorithm_id:
  510|    628|{
  511|    628|	struct sc_asn1_pkcs15_algorithm_info *alg_info = NULL;
  512|    628|	struct sc_asn1_entry asn1_alg_id[3];
  513|    628|	int r;
  514|       |
  515|    628|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    628|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    628|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    628|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    628|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 628]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|    628|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  517|    628|	sc_format_asn1_entry(asn1_alg_id + 0, &id->oid, NULL, 0);
  518|       |
  519|    628|	memset(id, 0, sizeof(*id));
  520|    628|	r = _sc_asn1_decode(ctx, asn1_alg_id, in, len, &in, &len, 0, depth + 1);
  521|    628|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of algo ID failed");
  ------------------
  |  |  174|    628|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    628|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    628|	int _ret = (r); \
  |  |  |  |  168|    628|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 612]
  |  |  |  |  ------------------
  |  |  |  |  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|    628|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 612]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  522|       |
  523|    612|        sc_log(ctx, "decoded OID '%s'", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|    612|#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|    612|	id->algorithm = (unsigned int ) -1;
  528|    612|	alg_info = sc_asn1_get_algorithm_info(id);
  529|    612|	if (alg_info != NULL) {
  ------------------
  |  Branch (529:6): [True: 382, False: 230]
  ------------------
  530|    382|		id->algorithm = alg_info->id;
  531|    382|		if (alg_info->decode) {
  ------------------
  |  Branch (531:7): [True: 239, False: 143]
  ------------------
  532|    239|			if (asn1_alg_id[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    239|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (532:8): [True: 10, False: 229]
  ------------------
  533|     10|				sc_log(ctx, "SC_ASN1_PRESENT was set, so invalid");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  534|     10|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|     10|			}
  536|    229|			r = alg_info->decode(ctx, &id->params, in, len, depth);
  537|    229|		}
  538|    382|	}
  539|       |
  540|    602|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    602|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    602|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    602|	int _ret = r; \
  |  |  |  |  155|    602|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 602, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    602|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 45, False: 557]
  |  |  |  |  ------------------
  |  |  |  |  157|    602|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    602|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    602|	return _ret; \
  |  |  |  |  163|    602|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  541|    602|}
sc_asn1_encode_algorithm_id:
  547|    138|{
  548|    138|	struct sc_asn1_pkcs15_algorithm_info *alg_info;
  549|    138|	struct sc_algorithm_id temp_id;
  550|    138|	struct sc_asn1_entry asn1_alg_id[3];
  551|    138|	u8 *obj = NULL;
  552|    138|	size_t obj_len = 0;
  553|    138|	int r;
  554|    138|	u8 *tmp;
  555|       |
  556|    138|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    138|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    138|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    138|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    138|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 138]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  557|    138|        sc_log(ctx, "type of algorithm to encode: %lu", id->algorithm);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  558|    138|	alg_info = sc_asn1_get_algorithm_info(id);
  559|    138|	if (alg_info == NULL) {
  ------------------
  |  Branch (559:6): [True: 0, False: 138]
  ------------------
  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|    138|	if (!sc_valid_oid(&id->oid)) {
  ------------------
  |  Branch (565:6): [True: 20, False: 118]
  ------------------
  566|     20|		temp_id = *id;
  567|     20|		temp_id.oid = alg_info->oid;
  568|     20|		id = &temp_id;
  569|     20|	}
  570|       |
  571|    138|        sc_log(ctx, "encode algo %s", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  572|    138|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  573|    138|	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|    138|	if (id->algorithm != SC_ALGORITHM_EDDSA &&
  ------------------
  |  |   81|    276|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (579:6): [True: 138, False: 0]
  ------------------
  580|    138|	    id->algorithm != SC_ALGORITHM_XEDDSA &&
  ------------------
  |  |   82|    276|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (580:6): [True: 138, False: 0]
  ------------------
  581|    138|	    (!id->params || !alg_info->encode))
  ------------------
  |  Branch (581:7): [True: 65, False: 73]
  |  Branch (581:22): [True: 0, False: 73]
  ------------------
  582|     65|		asn1_alg_id[1].flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|     65|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  583|       |
  584|    138|	r = _sc_asn1_encode(ctx, asn1_alg_id, buf, len, depth + 1);
  585|    138|	LOG_TEST_RET(ctx, r, "ASN.1 encode of algorithm failed");
  ------------------
  |  |  174|    138|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    138|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    138|	int _ret = (r); \
  |  |  |  |  168|    138|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    138|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 138]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  586|       |
  587|       |	/* Encode any parameters */
  588|    138|	if (id->params && alg_info->encode) {
  ------------------
  |  Branch (588:6): [True: 73, False: 65]
  |  Branch (588:20): [True: 73, False: 0]
  ------------------
  589|     73|		r = alg_info->encode(ctx, id->params, &obj, &obj_len, depth+1);
  590|     73|		if (r < 0) {
  ------------------
  |  Branch (590:7): [True: 0, False: 73]
  ------------------
  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|     73|	}
  596|       |
  597|    138|	if (obj_len) {
  ------------------
  |  Branch (597:6): [True: 73, False: 65]
  ------------------
  598|     73|		tmp = (u8 *) realloc(*buf, *len + obj_len);
  599|     73|		if (!tmp) {
  ------------------
  |  Branch (599:7): [True: 0, False: 73]
  ------------------
  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|     73|		*buf = tmp;
  606|     73|		memcpy(*buf + *len, obj, obj_len);
  607|     73|		*len += obj_len;
  608|     73|		free(obj);
  609|     73|	}
  610|       |
  611|    138|	sc_log(ctx, "return encoded algorithm ID: %s", sc_dump_hex(*buf, *len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  612|    138|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    138|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    138|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    138|	int _ret = r; \
  |  |  |  |  155|    138|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 138, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    138|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  157|    138|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    138|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    138|	return _ret; \
  |  |  |  |  163|    138|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  613|    138|}
sc_asn1_clear_algorithm_id:
  617|  1.02k|{
  618|  1.02k|	struct sc_asn1_pkcs15_algorithm_info *aip;
  619|       |
  620|  1.02k|	if (id->params && (aip = sc_asn1_get_algorithm_info(id)) && aip->free) {
  ------------------
  |  Branch (620:6): [True: 254, False: 767]
  |  Branch (620:20): [True: 254, False: 0]
  |  Branch (620:62): [True: 254, False: 0]
  ------------------
  621|    254|		aip->free(id->params);
  622|       |		id->params = NULL;
  623|    254|	}
  624|  1.02k|}
pkcs15-algo.c:sc_asn1_get_algorithm_info:
  486|  1.00k|{
  487|  1.00k|	struct sc_asn1_pkcs15_algorithm_info *aip = NULL;
  488|       |
  489|  12.9k|	for (aip = algorithm_table; aip->id >= 0; aip++)   {
  ------------------
  |  Branch (489:30): [True: 12.7k, False: 230]
  ------------------
  490|  12.7k|		if ((int) id->algorithm < 0 && sc_compare_oid(&id->oid, &aip->oid))
  ------------------
  |  Branch (490:7): [True: 8.15k, False: 4.58k]
  |  Branch (490:34): [True: 382, False: 7.76k]
  ------------------
  491|    382|			return aip;
  492|       |
  493|  12.3k|		if (aip->id == (int)id->algorithm)
  ------------------
  |  Branch (493:7): [True: 392, False: 11.9k]
  ------------------
  494|    392|			return aip;
  495|  12.3k|	}
  496|       |
  497|    230|	return NULL;
  498|  1.00k|}
pkcs15-algo.c:asn1_decode_pbkdf2_params:
  144|     10|{
  145|     10|	struct sc_pbkdf2_params info;
  146|     10|	struct sc_asn1_entry asn1_pbkdf2_params[5];
  147|     10|	int r;
  148|       |
  149|     10|	sc_copy_asn1_entry(c_asn1_pbkdf2_params, asn1_pbkdf2_params);
  150|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 0,
  151|     10|			info.salt, &info.salt_len, 0);
  152|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 1,
  153|     10|			&info.iterations, NULL, 0);
  154|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 2,
  155|     10|			&info.key_length, NULL, 0);
  156|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 3,
  157|     10|			&info.hash_alg, NULL, 0);
  158|       |
  159|     10|	memset(&info, 0, sizeof(info));
  160|     10|	info.salt_len = sizeof(info.salt);
  161|     10|	info.hash_alg.algorithm = SC_ALGORITHM_SHA1;
  ------------------
  |  |   93|     10|#define SC_ALGORITHM_SHA1		129
  ------------------
  162|       |
  163|     10|	r = _sc_asn1_decode(ctx, asn1_pbkdf2_params, buf, buflen, NULL, NULL, 0, depth + 1);
  164|     10|	if (r < 0)
  ------------------
  |  Branch (164:6): [True: 10, False: 0]
  ------------------
  165|     10|		return r;
  166|       |
  167|      0|	*paramp = malloc(sizeof(info));
  168|      0|	if (!*paramp)
  ------------------
  |  Branch (168:6): [True: 0, False: 0]
  ------------------
  169|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  170|      0|	memcpy(*paramp, &info, sizeof(info));
  171|      0|	return 0;
  172|      0|}
pkcs15-algo.c:asn1_decode_pbes2_params:
  207|     23|{
  208|     23|	struct sc_asn1_entry asn1_pbes2_params[3];
  209|     23|	struct sc_pbes2_params info;
  210|     23|	int r;
  211|       |
  212|     23|	sc_copy_asn1_entry(c_asn1_pbes2_params, asn1_pbes2_params);
  213|     23|	sc_format_asn1_entry(asn1_pbes2_params + 0,
  214|     23|				&info.derivation_alg, NULL, 0);
  215|     23|	sc_format_asn1_entry(asn1_pbes2_params + 1,
  216|     23|				&info.key_encr_alg, NULL, 0);
  217|     23|	memset(&info, 0, sizeof(info));
  218|       |
  219|     23|	r = _sc_asn1_decode(ctx, asn1_pbes2_params, buf, buflen, NULL, NULL, 0, depth + 1);
  220|     23|	if (r < 0)
  ------------------
  |  Branch (220:6): [True: 23, False: 0]
  ------------------
  221|     23|		return r;
  222|      0|	*paramp = malloc(sizeof(info));
  223|      0|	if (!*paramp)
  ------------------
  |  Branch (223:6): [True: 0, False: 0]
  ------------------
  224|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  225|      0|	memcpy(*paramp, &info, sizeof(info));
  226|      0|	return 0;
  227|      0|}
pkcs15-algo.c:asn1_decode_ec_params:
  265|    196|{
  266|    196|	int r;
  267|    196|	struct sc_object_id curve;
  268|    196|	struct sc_asn1_entry asn1_ec_params[4];
  269|    196|	struct sc_ec_parameters *ecp;
  270|       |
  271|    196|	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|    196|	sc_copy_asn1_entry(c_asn1_ec_params, asn1_ec_params);
  277|    196|	sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
  278|       |
  279|       |	/* Some signature algorithms will not have any data */
  280|    196|	if (buflen == 0 || buf == NULL)
  ------------------
  |  Branch (280:6): [True: 3, False: 193]
  |  Branch (280:21): [True: 0, False: 193]
  ------------------
  281|      3|		return 0;
  282|       |
  283|    193|	r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
  284|       |	/* r = index in asn1_ec_params */
  285|    193|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_decode_ec_params r=%d", r);
  ------------------
  |  |   70|    193|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  286|    193|	if (r < 0)
  ------------------
  |  Branch (286:6): [True: 12, False: 181]
  ------------------
  287|     12|		return r;
  288|       |
  289|    181|	ecp = calloc(1, sizeof(struct sc_ec_parameters));
  290|    181|	if (ecp == NULL)
  ------------------
  |  Branch (290:6): [True: 0, False: 181]
  ------------------
  291|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  292|       |
  293|    181|	if (r <= 1) {
  ------------------
  |  Branch (293:6): [True: 181, False: 0]
  ------------------
  294|    181|		ecp->der.value = malloc(buflen);
  295|    181|		if (ecp->der.value == NULL) {
  ------------------
  |  Branch (295:7): [True: 0, False: 181]
  ------------------
  296|      0|			free(ecp);
  297|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  298|      0|		}
  299|    181|		ecp->der.len = buflen;
  300|    181|		memcpy(ecp->der.value, buf, buflen);
  301|    181|	}
  302|      0|	else    {
  303|      0|		r = 0;
  304|      0|	}
  305|       |
  306|    181|	ecp->type = r; /* but 0 = ecparams if any, 1=named curve */
  307|    181|	*paramp = ecp;
  308|    181|	return SC_SUCCESS;
  ------------------
  |  |   28|    181|#define SC_SUCCESS				0
  ------------------
  309|    181|};
pkcs15-algo.c:asn1_encode_ec_params:
  314|     73|{
  315|     73|	 struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  316|       |
  317|       |	/* Only handle named curves. They may be absent too */
  318|     73|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_encode_ec_params() called");
  ------------------
  |  |   70|     73|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  319|     73|	*buf = NULL;
  320|     73|	*buflen = 0;
  321|     73|	if (ecp && ecp->type == 1 && ecp->der.value) { /* named curve */
  ------------------
  |  Branch (321:6): [True: 73, False: 0]
  |  Branch (321:13): [True: 73, False: 0]
  |  Branch (321:31): [True: 73, False: 0]
  ------------------
  322|     73|		*buf = malloc(ecp->der.len);
  323|     73|		if (*buf == NULL)
  ------------------
  |  Branch (323:7): [True: 0, False: 73]
  ------------------
  324|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  325|       |
  326|     73|		memcpy(*buf, ecp->der.value, ecp->der.len);
  327|     73|		*buflen = ecp->der.len;
  328|     73|	}
  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|     73|	return 0;
  334|     73|}
pkcs15-algo.c:asn1_free_ec_params:
  338|    254|{
  339|    254|	struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  340|       |
  341|    254|	if (ecp) {
  ------------------
  |  Branch (341:6): [True: 254, False: 0]
  ------------------
  342|    254|		if (ecp->der.value)
  ------------------
  |  Branch (342:7): [True: 254, False: 0]
  ------------------
  343|    254|			free(ecp->der.value);
  344|    254|		if (ecp->named_curve)
  ------------------
  |  Branch (344:7): [True: 0, False: 254]
  ------------------
  345|      0|			free(ecp->named_curve);
  346|    254|		free(ecp);
  347|    254|	}
  348|    254|}

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

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

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

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

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

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

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

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

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

sc_pkcs15emu_eoi_init_ex:
   35|  7.75k|{
   36|  7.75k|	struct sc_card *card = p15card->card;
   37|  7.75k|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
   38|  7.75k|	struct sc_pkcs15_search_key sk;
   39|  7.75k|	struct sc_pkcs15_object *objs[MAX_OBJECTS];
   40|  7.75k|	int i, j, len;
   41|       |
   42|  7.75k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.75k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.75k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.75k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.75k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.75k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   43|       |
   44|  7.75k|	if (card->type != SC_CARD_TYPE_EOI && card->type != SC_CARD_TYPE_EOI_CONTACTLESS)
  ------------------
  |  Branch (44:6): [True: 7.74k, False: 6]
  |  Branch (44:40): [True: 7.74k, False: 0]
  ------------------
   45|  7.75k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  7.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.74k|	int _ret = r; \
  |  |  |  |  155|  7.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.74k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.74k|	return _ret; \
  |  |  |  |  163|  7.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   46|       |
   47|      6|	if (!privdata)
  ------------------
  |  Branch (47:6): [True: 0, False: 6]
  ------------------
   48|      6|		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|      6|	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: 6]
  |  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|      6|	LOG_TEST_RET(card->ctx, sc_pkcs15_bind_internal(p15card, aid),
  ------------------
  |  |  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: 5, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|      6|} 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|  9.60k|{
   80|  9.60k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.60k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.60k]
  |  |  ------------------
  ------------------
   81|       |
   82|  9.60k|	if (entersafe_detect_card(p15card))
  ------------------
  |  Branch (82:6): [True: 9.46k, False: 145]
  ------------------
   83|  9.46k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.46k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   84|    145|	return sc_pkcs15emu_entersafe_init(p15card);
   85|  9.60k|}
pkcs15-esinit.c:entersafe_detect_card:
   33|  9.60k|{
   34|  9.60k|	sc_card_t *card = p15card->card;
   35|       |
   36|  9.60k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.60k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.60k]
  |  |  ------------------
  ------------------
   37|       |
   38|       |	/* check if we have the correct card OS */
   39|  9.60k|	if (strcmp(card->name, "entersafe"))
  ------------------
  |  Branch (39:6): [True: 9.46k, False: 145]
  ------------------
   40|  9.46k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.46k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   41|       |
   42|    145|    return SC_SUCCESS;
  ------------------
  |  |   28|    145|#define SC_SUCCESS				0
  ------------------
   43|  9.60k|}
pkcs15-esinit.c:sc_pkcs15emu_entersafe_init:
   46|    145|{
   47|    145|	int    r;
   48|    145|	char   buf[256];
   49|    145|	sc_card_t *card = p15card->card;
   50|    145|	sc_serial_number_t serial;
   51|       |
   52|    145|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    145|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    145|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    145|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 145]
  |  |  ------------------
  ------------------
   53|       |
   54|       |	/* get serial number */
   55|    145|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   56|    145|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    145|#define SC_SUCCESS				0
  ------------------
  |  Branch (56:6): [True: 142, False: 3]
  ------------------
   57|    142|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    142|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|      3|	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
   59|      3|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (59:6): [True: 0, False: 3]
  ------------------
   60|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   61|       |
   62|      3|	set_string(&p15card->tokeninfo->serial_number, buf);
   63|      3|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (63:6): [True: 0, False: 3]
  ------------------
   64|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   65|       |
   66|       |	/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
   67|      3|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   30|      3|#define MANU_ID		"entersafe"
  ------------------
   68|      3|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (68:6): [True: 0, False: 3]
  ------------------
   69|      0|		free(p15card->tokeninfo->serial_number);
   70|      0|		p15card->tokeninfo->serial_number = NULL;
   71|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   72|      0|	}
   73|       |
   74|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
   75|      3|}

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

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

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

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

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

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

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

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

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

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

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

sc_pkcs15emu_openpgp_init_ex:
  695|  11.6k|{
  696|  11.6k|	if (openpgp_detect_card(p15card))
  ------------------
  |  Branch (696:6): [True: 11.0k, False: 633]
  ------------------
  697|  11.0k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.0k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  698|    633|	return sc_pkcs15emu_openpgp_init(p15card);
  699|  11.6k|}
pkcs15-openpgp.c:openpgp_detect_card:
  683|  11.6k|{
  684|  11.6k|	if (p15card->card->type == SC_CARD_TYPE_OPENPGP_BASE
  ------------------
  |  Branch (684:6): [True: 607, False: 11.0k]
  ------------------
  685|  11.0k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V1
  ------------------
  |  Branch (685:7): [True: 5, False: 11.0k]
  ------------------
  686|  11.0k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V2
  ------------------
  |  Branch (686:7): [True: 2, False: 11.0k]
  ------------------
  687|  11.0k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_GNUK
  ------------------
  |  Branch (687:7): [True: 17, False: 11.0k]
  ------------------
  688|  11.0k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V3)
  ------------------
  |  Branch (688:7): [True: 2, False: 11.0k]
  ------------------
  689|    633|		return SC_SUCCESS;
  ------------------
  |  |   28|    633|#define SC_SUCCESS				0
  ------------------
  690|  11.0k|	else
  691|  11.0k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.0k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  692|  11.6k|}
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: 5, False: 628]
  ------------------
  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: 464, False: 169]
  ------------------
  202|    464|		unsigned short manuf_id = bebytes2ushort(card->serialnr.value);
  203|    464|		int j;
  204|       |
  205|    464|		sc_bin_to_hex(card->serialnr.value, card->serialnr.len, string, sizeof(string), 0);
  206|    464|		set_string(&p15card->tokeninfo->serial_number, string);
  207|       |
  208|  11.1k|		for (j = 0; manuf_map[j].name != NULL; j++) {
  ------------------
  |  Branch (208:15): [True: 10.7k, False: 391]
  ------------------
  209|  10.7k|			if (manuf_id == manuf_map[j].id) {
  ------------------
  |  Branch (209:8): [True: 73, False: 10.7k]
  ------------------
  210|     73|				set_string(&p15card->tokeninfo->manufacturer_id, manuf_map[j].name);
  211|     73|				break;
  212|     73|			}
  213|  10.7k|		}
  214|    464|	}
  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: 594, False: 39]
  ------------------
  221|    594|		goto failed;
  222|     39|	string[r] = '\0';
  223|     39|	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|     39|	sc_log(ctx, "Reading PW status bytes");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     39|	if ((r = read_file(card, "006E:0073:00C4", c4data, sizeof(c4data))) < 0)
  ------------------
  |  Branch (232:6): [True: 19, False: 20]
  ------------------
  233|     19|		goto failed;
  234|     20|	if (r != 7) {
  ------------------
  |  Branch (234:6): [True: 17, False: 3]
  ------------------
  235|     17|		sc_log(ctx, "CHV status bytes have unexpected length (expected 7, got %d)\n", r);
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  236|     17|		r = SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|     17|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
  237|     17|		goto failed;
  238|     17|	}
  239|       |
  240|       |	/* Add PIN codes */
  241|     12|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (241:14): [True: 9, False: 3]
  ------------------
  242|      9|		sc_pkcs15_auth_info_t pin_info;
  243|      9|		sc_pkcs15_object_t   pin_obj;
  244|       |
  245|      9|		memset(&pin_info, 0, sizeof(pin_info));
  246|      9|		memset(&pin_obj,  0, sizeof(pin_obj));
  247|       |
  248|      9|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      9|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  249|      9|		pin_info.auth_id.len      = 1;
  250|      9|		pin_info.auth_id.value[0] = pin_cfg[i].reference;
  251|      9|		pin_info.attrs.pin.reference     = pin_cfg[i].reference;
  252|      9|		pin_info.attrs.pin.flags         = pin_cfg[i].flags;
  253|      9|		pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_UTF8;
  ------------------
  |  |   90|      9|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  254|      9|		pin_info.attrs.pin.min_length    = pin_cfg[i].min_length;
  255|      9|		pin_info.attrs.pin.stored_length = c4data[1 + pin_cfg[i].do_index];
  256|      9|		pin_info.attrs.pin.max_length    = c4data[1 + pin_cfg[i].do_index];
  257|      9|		pin_info.attrs.pin.pad_char      = '\0';
  258|      9|		pin_info.tries_left = c4data[4 + pin_cfg[i].do_index];
  259|      9|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      9|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  260|       |
  261|      9|		sc_format_path("3F00", &pin_info.path);
  262|       |
  263|      9|		strlcpy(pin_obj.label, pin_cfg[i].label, sizeof(pin_obj.label));
  ------------------
  |  |   43|      9|#define strlcpy _strlcpy
  ------------------
  264|      9|		pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|      9|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      9|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  265|      9|		if (i < 2) {
  ------------------
  |  Branch (265:7): [True: 6, False: 3]
  ------------------
  266|      6|			pin_obj.auth_id.len = 1;
  267|      6|			pin_obj.auth_id.value[0] = 3;
  268|      6|		}
  269|       |
  270|      9|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  271|      9|		if (r < 0) {
  ------------------
  |  Branch (271:7): [True: 0, False: 9]
  ------------------
  272|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  273|      0|			goto failed;
  274|      0|		}
  275|      9|	}
  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|      3|	sc_log(ctx, "Reading Fingerprints");
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  283|      3|	if ((r = read_file(card, "006E:0073:00C5", c5data, sizeof(c5data))) < 0)
  ------------------
  |  Branch (283:6): [True: 2, False: 1]
  ------------------
  284|      2|		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 ||
  ------------------
  |  |  870|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (334:8): [True: 0, False: 0]
  ------------------
  335|      0|				cxdata[0] == SC_OPENPGP_KEYALGO_ECDSA ||
  ------------------
  |  |  871|      0|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (335:5): [True: 0, False: 0]
  ------------------
  336|      0|				cxdata[0] == SC_OPENPGP_KEYALGO_EDDSA) {
  ------------------
  |  |  872|      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 ||
  ------------------
  |  |  879|      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)
  ------------------
  |  |  880|      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:
  ------------------
  |  |  870|      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:
  ------------------
  |  |  871|      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:
  ------------------
  |  |  872|      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:
  ------------------
  |  |  872|      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:
  ------------------
  |  |  870|      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:
  ------------------
  |  |  871|      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:
  ------------------
  |  |  869|      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 ||
  ------------------
  |  |  870|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (465:8): [True: 0, False: 0]
  ------------------
  466|      0|				cxdata[0] == SC_OPENPGP_KEYALGO_ECDSA ||
  ------------------
  |  |  871|      0|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (466:5): [True: 0, False: 0]
  ------------------
  467|      0|				cxdata[0] == SC_OPENPGP_KEYALGO_EDDSA) {
  ------------------
  |  |  872|      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 ||
  ------------------
  |  |  879|      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)
  ------------------
  |  |  880|      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:
  ------------------
  |  |  870|      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:
  ------------------
  |  |  871|      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:
  ------------------
  |  |  872|      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:
  ------------------
  |  |  872|      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:
  ------------------
  |  |  870|      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:
  ------------------
  |  |  871|      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:
  ------------------
  |  |  869|      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|    675|{
  164|    675|	sc_path_t	path;
  165|    675|	sc_file_t	*file;
  166|    675|	int		r;
  167|       |
  168|    675|	sc_format_path(path_name, &path);
  169|    675|	if ((r = sc_select_file(card, &path, &file)) < 0)
  ------------------
  |  Branch (169:6): [True: 615, False: 60]
  ------------------
  170|    615|		return r;
  171|       |
  172|     60|	if (file->size < len)
  ------------------
  |  Branch (172:6): [True: 46, False: 14]
  ------------------
  173|     46|		len = file->size;
  174|       |
  175|     60|	sc_file_free(file);
  176|       |
  177|     60|	return sc_read_binary(card, 0, (u8 *) buf, len, 0);
  178|    675|}

sc_pkcs15_decode_aodf_entry:
   86|    409|{
   87|    409|	sc_context_t *ctx = p15card->card->ctx;
   88|    409|	struct sc_pkcs15_auth_info info;
   89|    409|	int r;
   90|    409|	size_t flags_len = sizeof(info.attrs.pin.flags);
   91|    409|	size_t derived_len = sizeof(info.attrs.authkey.derived);
   92|    409|	size_t padchar_len = 1;
   93|    409|	struct sc_asn1_entry asn1_com_ao_attr[2];
   94|    409|	struct sc_asn1_entry asn1_pin_attr[10], asn1_type_pin_attr[2];
   95|    409|	struct sc_asn1_entry asn1_authkey_attr[3], asn1_type_authkey_attr[2];
   96|    409|	struct sc_asn1_entry asn1_auth_type[2];
   97|    409|	struct sc_asn1_entry asn1_auth_type_choice[4];
   98|    409|	struct sc_asn1_pkcs15_object pin_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_pin_attr };
   99|    409|	struct sc_asn1_pkcs15_object authkey_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_authkey_attr };
  100|       |
  101|    409|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|    409|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    409|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    409|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 409]
  |  |  ------------------
  ------------------
  102|       |
  103|    409|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  104|    409|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  105|       |
  106|    409|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  107|       |
  108|    409|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  109|    409|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  110|       |
  111|    409|	sc_copy_asn1_entry(c_asn1_type_authkey_attr, asn1_type_authkey_attr);
  112|    409|	sc_copy_asn1_entry(c_asn1_authkey_attr, asn1_authkey_attr);
  113|       |
  114|    409|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 0);
  115|    409|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 0);	/* 'pin' */
  116|    409|	sc_format_asn1_entry(asn1_auth_type_choice + 2, &authkey_obj, NULL, 0);	/* 'authKey' */
  117|       |
  118|       |	/* pinAttributes */
  119|    409|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 0);
  120|    409|	sc_format_asn1_entry(asn1_pin_attr + 0, &info.attrs.pin.flags, &flags_len, 0);
  121|    409|	sc_format_asn1_entry(asn1_pin_attr + 1, &info.attrs.pin.type, NULL, 0);
  122|    409|	sc_format_asn1_entry(asn1_pin_attr + 2, &info.attrs.pin.min_length, NULL, 0);
  123|    409|	sc_format_asn1_entry(asn1_pin_attr + 3, &info.attrs.pin.stored_length, NULL, 0);
  124|    409|	sc_format_asn1_entry(asn1_pin_attr + 4, &info.attrs.pin.max_length, NULL, 0);
  125|    409|	sc_format_asn1_entry(asn1_pin_attr + 5, &info.attrs.pin.reference, NULL, 0);
  126|    409|	sc_format_asn1_entry(asn1_pin_attr + 6, &info.attrs.pin.pad_char, &padchar_len, 0);
  127|       |
  128|       |	/* authKeyAttributes */
  129|    409|	sc_format_asn1_entry(asn1_type_authkey_attr + 0, asn1_authkey_attr, NULL, 0);
  130|    409|	sc_format_asn1_entry(asn1_authkey_attr + 0, &info.attrs.authkey.derived, &derived_len, 0);
  131|    409|	sc_format_asn1_entry(asn1_authkey_attr + 1, &info.attrs.authkey.skey_id, NULL, 0);
  132|       |
  133|       |	/* We don't support lastPinChange yet. */
  134|    409|	sc_format_asn1_entry(asn1_pin_attr + 8, &info.path, NULL, 0);
  135|       |
  136|    409|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info.auth_id, NULL, 0);
  137|       |
  138|       |	/* Fill in defaults */
  139|    409|	memset(&info, 0, sizeof(info));
  140|    409|	info.tries_left = -1;
  141|    409|	info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|    409|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  142|       |
  143|    409|	r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
  144|    409|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    409|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (144:6): [True: 38, False: 371]
  ------------------
  145|     38|		return r;
  146|    371|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|    371|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    371|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    371|	int _ret = (r); \
  |  |  |  |  168|    371|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 92, False: 279]
  |  |  |  |  ------------------
  |  |  |  |  169|     92|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     92|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     92|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     92|		return _ret; \
  |  |  |  |  172|     92|	} \
  |  |  |  |  173|    371|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 279]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|       |
  148|    279|	if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    279|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (148:6): [True: 275, False: 4]
  ------------------
  149|    275|		sc_log(ctx, "AuthType: PIN");
  ------------------
  |  |   71|    275|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  150|    275|		obj->type = SC_PKCS15_TYPE_AUTH_PIN;
  ------------------
  |  |  445|    275|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  151|    275|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    275|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  152|    275|		info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|    275|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  153|       |
  154|    275|		if (info.attrs.pin.max_length == 0) {
  ------------------
  |  Branch (154:7): [True: 275, False: 0]
  ------------------
  155|    275|			if (p15card->card->max_pin_len != 0)
  ------------------
  |  Branch (155:8): [True: 0, False: 275]
  ------------------
  156|      0|				info.attrs.pin.max_length = p15card->card->max_pin_len;
  157|    275|			else if (info.attrs.pin.stored_length != 0)
  ------------------
  |  Branch (157:13): [True: 132, False: 143]
  ------------------
  158|    132|				info.attrs.pin.max_length = info.attrs.pin.type != SC_PKCS15_PIN_TYPE_BCD ?
  ------------------
  |  |   88|    132|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (158:33): [True: 131, False: 1]
  ------------------
  159|    131|					info.attrs.pin.stored_length : 2 * info.attrs.pin.stored_length;
  160|    143|			else
  161|    143|				info.attrs.pin.max_length = 8; /* shouldn't happen */
  162|    275|		}
  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|    275|		if (info.attrs.pin.reference < 0)
  ------------------
  |  Branch (169:7): [True: 0, False: 275]
  ------------------
  170|      0|			info.attrs.pin.reference += 256;
  171|       |
  172|    275|		if (info.attrs.pin.flags & SC_PKCS15_PIN_FLAG_LOCAL)   {
  ------------------
  |  |   55|    275|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  |  Branch (172:7): [True: 6, False: 269]
  ------------------
  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|      6|			if (!info.path.len)   {
  ------------------
  |  Branch (175:8): [True: 6, False: 0]
  ------------------
  176|       |				/* Give priority to AID defined in the application DDO */
  177|      6|				if (p15card->app && p15card->app->ddo.aid.len)
  ------------------
  |  Branch (177:9): [True: 0, False: 6]
  |  Branch (177:25): [True: 0, False: 0]
  ------------------
  178|      0|					info.path.aid = p15card->app->ddo.aid;
  179|      6|				else if (p15card->file_app && p15card->file_app->path.len)
  ------------------
  |  Branch (179:14): [True: 6, False: 0]
  |  Branch (179:35): [True: 6, False: 0]
  ------------------
  180|      6|					info.path = p15card->file_app->path;
  181|      0|				else
  182|      0|					return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  183|      6|			}
  184|      6|		}
  185|    275|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoded PIN(ref:%X,path:%s)", info.attrs.pin.reference, sc_print_path(&info.path));
  ------------------
  |  |   70|    275|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  186|    275|	}
  187|      4|	else if (asn1_auth_type_choice[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      4|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (187:11): [True: 4, False: 0]
  ------------------
  188|      4|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet supported");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|      4|	}
  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|    275|	obj->data = malloc(sizeof(info));
  203|    275|	if (obj->data == NULL)
  ------------------
  |  Branch (203:6): [True: 0, False: 275]
  ------------------
  204|    275|		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|    275|	memcpy(obj->data, &info, sizeof(info));
  206|       |
  207|    275|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_SUCCESS);
  ------------------
  |  |  153|    275|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    275|	int _ret = r; \
  |  |  155|    275|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 275, False: 0]
  |  |  ------------------
  |  |  156|    275|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 275]
  |  |  ------------------
  |  |  157|    275|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    275|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    275|	return _ret; \
  |  |  163|    275|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  208|    275|}
sc_pkcs15_encode_aodf_entry:
  213|  3.67k|{
  214|  3.67k|	struct sc_asn1_entry asn1_com_ao_attr[2], asn1_pin_attr[10], asn1_type_pin_attr[2];
  215|  3.67k|	struct sc_asn1_entry asn1_auth_type[2];
  216|  3.67k|	struct sc_asn1_entry asn1_auth_type_choice[4];
  217|  3.67k|	struct sc_pkcs15_auth_info *info = (struct sc_pkcs15_auth_info *) obj->data;
  218|  3.67k|	struct sc_asn1_pkcs15_object pin_obj = { (struct sc_pkcs15_object *) obj,
  219|  3.67k|						 asn1_com_ao_attr, NULL, asn1_type_pin_attr };
  220|  3.67k|	int r;
  221|  3.67k|	size_t flags_len;
  222|  3.67k|	size_t padchar_len = 1;
  223|       |
  224|  3.67k|	if (info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  3.67k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (224:6): [True: 0, False: 3.67k]
  ------------------
  225|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  226|       |
  227|  3.67k|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  228|  3.67k|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  229|  3.67k|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  230|  3.67k|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  231|  3.67k|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  232|       |
  233|  3.67k|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 1);
  234|  3.67k|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 1);
  235|       |
  236|  3.67k|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 1);
  237|       |
  238|  3.67k|	flags_len = sizeof(info->attrs.pin.flags);
  239|  3.67k|	sc_format_asn1_entry(asn1_pin_attr + 0, &info->attrs.pin.flags, &flags_len, 1);
  240|  3.67k|	sc_format_asn1_entry(asn1_pin_attr + 1, &info->attrs.pin.type, NULL, 1);
  241|  3.67k|	sc_format_asn1_entry(asn1_pin_attr + 2, &info->attrs.pin.min_length, NULL, 1);
  242|  3.67k|	sc_format_asn1_entry(asn1_pin_attr + 3, &info->attrs.pin.stored_length, NULL, 1);
  243|  3.67k|	if (info->attrs.pin.max_length > 0)
  ------------------
  |  Branch (243:6): [True: 3.67k, False: 0]
  ------------------
  244|  3.67k|		sc_format_asn1_entry(asn1_pin_attr + 4, &info->attrs.pin.max_length, NULL, 1);
  245|  3.67k|	if (info->attrs.pin.reference >= 0)
  ------------------
  |  Branch (245:6): [True: 3.67k, False: 0]
  ------------------
  246|  3.67k|		sc_format_asn1_entry(asn1_pin_attr + 5, &info->attrs.pin.reference, NULL, 1);
  247|       |	/* FIXME: check if pad_char present */
  248|  3.67k|	sc_format_asn1_entry(asn1_pin_attr + 6, &info->attrs.pin.pad_char, &padchar_len, 1);
  249|  3.67k|	sc_format_asn1_entry(asn1_pin_attr + 8, &info->path, NULL, info->path.len ? 1 : 0);
  ------------------
  |  Branch (249:61): [True: 26, False: 3.64k]
  ------------------
  250|       |
  251|  3.67k|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info->auth_id, NULL, 1);
  252|       |
  253|  3.67k|	r = sc_asn1_encode(ctx, asn1_auth_type, buf, buflen);
  254|       |
  255|  3.67k|	return r;
  256|  3.67k|}
sc_pkcs15_free_auth_info:
  737|  4.13k|{
  738|  4.13k|	free(auth_info);
  739|  4.13k|}

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

sc_pkcs15_decode_prkdf_entry:
  157|     75|{
  158|     75|	sc_context_t *ctx = p15card->card->ctx;
  159|     75|	struct sc_pkcs15_prkey_info info;
  160|     75|	int r, i, gostr3410_params[3];
  161|     75|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  162|     75|	size_t usage_len = sizeof(info.usage);
  163|     75|	size_t af_len = sizeof(info.access_flags);
  164|     75|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  165|     75|	struct sc_asn1_entry asn1_com_prkey_attr[C_ASN1_COM_PRKEY_ATTR_SIZE];
  166|     75|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  167|     75|	struct sc_asn1_entry asn1_prk_rsa_attr[C_ASN1_PRK_RSA_ATTR_SIZE];
  168|     75|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOSTR3410KEY_ATTR_SIZE];
  169|     75|	struct sc_asn1_entry asn1_prk_gostr3410_attr[C_ASN1_PRK_GOSTR3410_ATTR_SIZE];
  170|     75|	struct sc_asn1_entry asn1_ecckey_attr[C_ASN1_ECCKEY_ATTR];
  171|     75|	struct sc_asn1_entry asn1_prk_ecc_attr[C_ASN1_PRK_ECC_ATTR];
  172|     75|	struct sc_asn1_entry asn1_prkey[C_ASN1_PRKEY_SIZE];
  173|     75|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  174|     75|	struct sc_asn1_pkcs15_object rsa_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_rsa_attr};
  175|     75|	struct sc_asn1_pkcs15_object gostr3410_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_gostr3410_attr};
  176|     75|	struct sc_asn1_pkcs15_object ecc_prkey_obj = { obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_ecc_attr };
  177|     75|	u8 ec_domain[32];
  178|     75|	size_t ec_domain_len = sizeof(ec_domain);
  179|       |
  180|     75|	sc_copy_asn1_entry(c_asn1_prkey, asn1_prkey);
  181|     75|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  182|       |
  183|     75|	sc_copy_asn1_entry(c_asn1_prk_rsa_attr, asn1_prk_rsa_attr);
  184|     75|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  185|     75|	sc_copy_asn1_entry(c_asn1_prk_gostr3410_attr, asn1_prk_gostr3410_attr);
  186|     75|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  187|     75|	sc_copy_asn1_entry(c_asn1_prk_ecc_attr, asn1_prk_ecc_attr);
  188|     75|	sc_copy_asn1_entry(c_asn1_ecckey_attr, asn1_ecckey_attr);
  189|       |
  190|     75|	sc_copy_asn1_entry(c_asn1_com_prkey_attr, asn1_com_prkey_attr);
  191|     75|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  192|       |
  193|     75|	sc_format_asn1_entry(asn1_prkey + 0, &rsa_prkey_obj, NULL, 0);
  194|     75|	sc_format_asn1_entry(asn1_prkey + 1, &ecc_prkey_obj, NULL, 0);
  195|     75|	sc_format_asn1_entry(asn1_prkey + 2, &gostr3410_prkey_obj, NULL, 0);
  196|       |
  197|     75|	sc_format_asn1_entry(asn1_prk_rsa_attr + 0, asn1_rsakey_attr, NULL, 0);
  198|     75|	sc_format_asn1_entry(asn1_prk_gostr3410_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  199|     75|	sc_format_asn1_entry(asn1_prk_ecc_attr + 0, asn1_ecckey_attr, NULL, 0);
  200|       |
  201|     75|	sc_format_asn1_entry(asn1_rsakey_attr + 0, &info.path, NULL, 0);
  202|     75|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info.modulus_length, NULL, 0);
  203|       |
  204|     75|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info.path, NULL, 0);
  205|     75|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  206|     75|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  207|     75|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  208|       |
  209|     75|	sc_format_asn1_entry(asn1_ecckey_attr + 0, &info.path, NULL, 0);
  210|     75|	sc_format_asn1_entry(asn1_ecckey_attr + 1, &info.field_length, NULL, 0);
  211|     75|	sc_format_asn1_entry(asn1_ecckey_attr + 3, ec_domain, &ec_domain_len, 0);
  212|       |
  213|     75|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info.id, NULL, 0);
  214|     75|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info.usage, &usage_len, 0);
  215|     75|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info.native, NULL, 0);
  216|     75|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info.access_flags, &af_len, 0);
  217|     75|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info.key_reference, NULL, 0);
  218|       |
  219|  1.27k|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && (asn1_supported_algorithms + i)->name; i++)
  ------------------
  |  |   61|  2.55k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (219:12): [True: 1.20k, False: 75]
  |  Branch (219:45): [True: 1.20k, False: 0]
  ------------------
  220|  1.20k|		sc_format_asn1_entry(asn1_supported_algorithms + i, &info.algo_refs[i], NULL, 0);
  221|     75|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, 0);
  222|       |
  223|     75|	sc_format_asn1_entry(asn1_com_prkey_attr + 0, &info.subject.value, &info.subject.len, 0);
  224|       |
  225|       |	/* Fill in defaults */
  226|     75|	memset(&info, 0, sizeof(info));
  227|     75|	info.key_reference = -1;
  228|     75|	info.native = 1;
  229|     75|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  230|       |
  231|     75|	r = sc_asn1_decode_choice(ctx, asn1_prkey, *buf, *buflen, buf, buflen);
  232|     75|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     75|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (232:6): [True: 31, False: 44]
  ------------------
  233|     31|		goto err;
  234|     44|	LOG_TEST_GOTO_ERR(ctx, r, "PrKey DF ASN.1 decoding failed");
  ------------------
  |  |  184|     44|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     44|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     44|	int _ret = (r); \
  |  |  |  |  178|     44|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 33, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     33|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     33|		goto err; \
  |  |  |  |  182|     33|	} \
  |  |  |  |  183|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|     11|	if (asn1_prkey[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     11|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (235:6): [True: 0, False: 11]
  ------------------
  236|      0|		obj->type = SC_PKCS15_TYPE_PRKEY_RSA;
  ------------------
  |  |  419|      0|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  237|      0|	}
  238|     11|	else if (asn1_prkey[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     11|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (238:11): [True: 0, False: 11]
  ------------------
  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|     11|	else if (asn1_prkey[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     11|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (273:11): [True: 0, False: 11]
  ------------------
  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|     11|	else {
  295|     11|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     11|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  296|     11|		LOG_TEST_GOTO_ERR(ctx, r, "Neither RSA or GOSTR3410 or ECC key in PrKDF entry.");
  ------------------
  |  |  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: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     11|		goto err; \
  |  |  |  |  182|     11|	} \
  |  |  |  |  183|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|     11|	}
  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|     75|err:
  360|     75|	if (r < 0) {
  ------------------
  |  Branch (360:6): [True: 75, False: 0]
  ------------------
  361|       |		/* This might have allocated something. If so, clear it now */
  362|     75|		free(info.subject.value);
  363|     75|		sc_pkcs15_free_key_params(&info.params);
  364|     75|	}
  365|       |
  366|     75|	return r;
  367|      0|}
sc_pkcs15_encode_prkdf_entry:
  371|  1.68k|{
  372|  1.68k|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  373|  1.68k|	struct sc_asn1_entry asn1_com_prkey_attr[C_ASN1_COM_PRKEY_ATTR_SIZE];
  374|  1.68k|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  375|  1.68k|	struct sc_asn1_entry asn1_prk_rsa_attr[C_ASN1_PRK_RSA_ATTR_SIZE];
  376|  1.68k|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOSTR3410KEY_ATTR_SIZE];
  377|  1.68k|	struct sc_asn1_entry asn1_prk_gostr3410_attr[C_ASN1_PRK_GOSTR3410_ATTR_SIZE];
  378|  1.68k|	struct sc_asn1_entry asn1_ecckey_attr[C_ASN1_ECCKEY_ATTR];
  379|  1.68k|	struct sc_asn1_entry asn1_prk_ecc_attr[C_ASN1_PRK_ECC_ATTR];
  380|  1.68k|	struct sc_asn1_entry asn1_prkey[C_ASN1_PRKEY_SIZE];
  381|  1.68k|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  382|  1.68k|	struct sc_asn1_pkcs15_object rsa_prkey_obj = {
  383|  1.68k|		(struct sc_pkcs15_object *) obj, asn1_com_key_attr,
  384|  1.68k|		asn1_com_prkey_attr, asn1_prk_rsa_attr
  385|  1.68k|	};
  386|  1.68k|	struct sc_asn1_pkcs15_object gostr3410_prkey_obj = {
  387|  1.68k|		(struct sc_pkcs15_object *) obj,
  388|  1.68k|		asn1_com_key_attr, asn1_com_prkey_attr,
  389|  1.68k|		asn1_prk_gostr3410_attr
  390|  1.68k|	};
  391|  1.68k|	struct sc_asn1_pkcs15_object ecc_prkey_obj = {
  392|  1.68k|		(struct sc_pkcs15_object *) obj,
  393|  1.68k|		asn1_com_key_attr, asn1_com_prkey_attr,
  394|  1.68k|		asn1_prk_ecc_attr
  395|  1.68k|	};
  396|  1.68k|	struct sc_pkcs15_prkey_info *prkey = (struct sc_pkcs15_prkey_info *) obj->data;
  397|  1.68k|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  398|  1.68k|	int r, i;
  399|  1.68k|	size_t af_len, usage_len;
  400|       |
  401|  1.68k|	sc_copy_asn1_entry(c_asn1_prkey, asn1_prkey);
  402|  1.68k|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  403|       |
  404|  1.68k|	sc_copy_asn1_entry(c_asn1_prk_rsa_attr, asn1_prk_rsa_attr);
  405|  1.68k|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  406|  1.68k|	sc_copy_asn1_entry(c_asn1_prk_gostr3410_attr, asn1_prk_gostr3410_attr);
  407|  1.68k|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  408|  1.68k|	sc_copy_asn1_entry(c_asn1_prk_ecc_attr, asn1_prk_ecc_attr);
  409|  1.68k|	sc_copy_asn1_entry(c_asn1_ecckey_attr, asn1_ecckey_attr);
  410|       |
  411|  1.68k|	sc_copy_asn1_entry(c_asn1_com_prkey_attr, asn1_com_prkey_attr);
  412|  1.68k|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  413|       |
  414|  1.68k|	switch (obj->type) {
  415|  1.61k|	case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  1.61k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (415:2): [True: 1.61k, False: 73]
  ------------------
  416|  1.61k|		sc_format_asn1_entry(asn1_prkey + 0, &rsa_prkey_obj, NULL, 1);
  417|  1.61k|		sc_format_asn1_entry(asn1_prk_rsa_attr + 0, asn1_rsakey_attr, NULL, 1);
  418|  1.61k|		sc_format_asn1_entry(asn1_rsakey_attr + 0, &prkey->path, NULL, 1);
  419|  1.61k|		sc_format_asn1_entry(asn1_rsakey_attr + 1, &prkey->modulus_length, NULL, 1);
  420|  1.61k|		break;
  421|     73|	case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     73|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (421:2): [True: 73, False: 1.61k]
  ------------------
  422|     73|		sc_format_asn1_entry(asn1_prkey + 1, &ecc_prkey_obj, NULL, 1);
  423|     73|		sc_format_asn1_entry(asn1_prk_ecc_attr + 0, asn1_ecckey_attr, NULL, 1);
  424|     73|		sc_format_asn1_entry(asn1_ecckey_attr + 0, &prkey->path, NULL, 1);
  425|     73|		sc_format_asn1_entry(asn1_ecckey_attr + 1, &prkey->field_length, NULL, 1);
  426|     73|		break;
  427|      0|	case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (427:2): [True: 0, False: 1.68k]
  ------------------
  428|      0|		sc_format_asn1_entry(asn1_prkey + 2, &gostr3410_prkey_obj, NULL, 1);
  429|      0|		sc_format_asn1_entry(asn1_prk_gostr3410_attr + 0, asn1_gostr3410key_attr, NULL, 1);
  430|      0|		sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &prkey->path, NULL, 1);
  431|      0|		if (prkey->params.len == sizeof(*keyinfo_gostparams))   {
  ------------------
  |  Branch (431:7): [True: 0, False: 0]
  ------------------
  432|      0|			keyinfo_gostparams = prkey->params.data;
  433|      0|			sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &keyinfo_gostparams->gostr3410, NULL, 1);
  434|      0|			sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &keyinfo_gostparams->gostr3411, NULL, 1);
  435|      0|			sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &keyinfo_gostparams->gost28147, NULL, 1);
  436|      0|		}
  437|      0|		break;
  438|      0|	default:
  ------------------
  |  Branch (438:2): [True: 0, False: 1.68k]
  ------------------
  439|      0|		sc_log(ctx, "Invalid private key type: %X", 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__
  |  |  ------------------
  ------------------
  440|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  441|      0|		break;
  442|  1.68k|	}
  443|  1.68k|	sc_format_asn1_entry(asn1_com_key_attr + 0, &prkey->id, NULL, 1);
  444|  1.68k|	usage_len = sizeof(prkey->usage);
  445|  1.68k|	sc_format_asn1_entry(asn1_com_key_attr + 1, &prkey->usage, &usage_len, 1);
  446|  1.68k|	if (prkey->native == 0)
  ------------------
  |  Branch (446:6): [True: 0, False: 1.68k]
  ------------------
  447|      0|		sc_format_asn1_entry(asn1_com_key_attr + 2, &prkey->native, NULL, 1);
  448|  1.68k|	if (prkey->access_flags) {
  ------------------
  |  Branch (448:6): [True: 1.26k, False: 419]
  ------------------
  449|  1.26k|		af_len = sizeof(prkey->access_flags);
  450|  1.26k|		sc_format_asn1_entry(asn1_com_key_attr + 3, &prkey->access_flags, &af_len, 1);
  451|  1.26k|	}
  452|  1.68k|	if (prkey->key_reference >= 0)
  ------------------
  |  Branch (452:6): [True: 1.52k, False: 162]
  ------------------
  453|  1.52k|		sc_format_asn1_entry(asn1_com_key_attr + 4, &prkey->key_reference, NULL, 1);
  454|       |
  455|  1.68k|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && prkey->algo_refs[i]; i++)   {
  ------------------
  |  |   61|  3.37k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (455:12): [True: 1.68k, False: 0]
  |  Branch (455:45): [True: 0, False: 1.68k]
  ------------------
  456|      0|		sc_log(ctx, "Encode algorithm(%i) %i", i, prkey->algo_refs[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__
  |  |  ------------------
  ------------------
  457|      0|		sc_format_asn1_entry(asn1_supported_algorithms + i, &prkey->algo_refs[i], NULL, 1);
  458|      0|	}
  459|  1.68k|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, prkey->algo_refs[0] != 0);
  460|       |
  461|  1.68k|	if (prkey->subject.value && prkey->subject.len)
  ------------------
  |  Branch (461:6): [True: 0, False: 1.68k]
  |  Branch (461:30): [True: 0, False: 0]
  ------------------
  462|      0|		sc_format_asn1_entry(asn1_com_prkey_attr + 0, prkey->subject.value, &prkey->subject.len, 1);
  463|  1.68k|	else
  464|  1.68k|		memset(asn1_com_prkey_attr, 0, sizeof(asn1_com_prkey_attr));
  465|       |
  466|  1.68k|	r = sc_asn1_encode(ctx, asn1_prkey, buf, buflen);
  467|       |
  468|  1.68k|	sc_log(ctx, "Key path %s", sc_print_path(&prkey->path));
  ------------------
  |  |   71|  1.68k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  469|  1.68k|	return r;
  470|  1.68k|}
sc_pkcs15_prkey_attrs_from_cert:
  475|    539|{
  476|    539|	struct sc_context *ctx = p15card->card->ctx;
  477|    539|#ifdef ENABLE_OPENSSL
  478|    539|	struct sc_pkcs15_object *key_object = NULL;
  479|    539|	struct sc_pkcs15_prkey_info *key_info = NULL;
  480|    539|	X509 *x = NULL;
  481|    539|	BIO *mem = NULL;
  482|    539|	unsigned char *buff = NULL, *ptr = NULL;
  483|    539|	int rv;
  484|       |
  485|    539|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    539|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    539|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    539|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    539|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 539]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  486|    539|	if (out_key_object)
  ------------------
  |  Branch (486:6): [True: 539, False: 0]
  ------------------
  487|    539|		*out_key_object = NULL;
  488|       |
  489|    539|	rv = sc_pkcs15_find_prkey_by_id(p15card, &((struct sc_pkcs15_cert_info *)cert_object->data)->id, &key_object);
  490|    539|	if (rv == SC_ERROR_OBJECT_NOT_FOUND)
  ------------------
  |  |   88|    539|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (490:6): [True: 243, False: 296]
  ------------------
  491|    539|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    243|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    243|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    243|	int _ret = r; \
  |  |  |  |  155|    243|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 243, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    243|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 243]
  |  |  |  |  ------------------
  |  |  |  |  157|    243|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    243|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    243|	return _ret; \
  |  |  |  |  163|    243|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  492|    296|	LOG_TEST_RET(ctx, rv, "Find private key error");
  ------------------
  |  |  174|    296|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    296|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    296|	int _ret = (r); \
  |  |  |  |  168|    296|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 296]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    296|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 296]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  493|       |
  494|    296|	key_info = (struct sc_pkcs15_prkey_info *) key_object->data;
  495|       |
  496|    296|	sc_log(ctx, "CertValue(%"SC_FORMAT_LEN_SIZE_T"u) %p",
  ------------------
  |  |   71|    296|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  497|    296|	       cert_object->content.len, cert_object->content.value);
  498|    296|	mem = BIO_new_mem_buf(cert_object->content.value, (int)cert_object->content.len);
  499|    296|	if (!mem) {
  ------------------
  |  Branch (499:6): [True: 296, False: 0]
  ------------------
  500|    296|		sc_log_openssl(ctx);
  ------------------
  |  |   72|    296|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  501|    296|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "MEM buffer allocation error");
  ------------------
  |  |  174|    296|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    296|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    296|	int _ret = (r); \
  |  |  |  |  168|    296|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 296, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    296|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    296|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    296|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    296|		return _ret; \
  |  |  |  |  172|    296|	} \
  |  |  |  |  173|    296|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  502|    296|	}
  503|       |
  504|      0|	x = d2i_X509_bio(mem, NULL);
  505|      0|	if (!x) {
  ------------------
  |  Branch (505:6): [True: 0, False: 0]
  ------------------
  506|      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__
  |  |  ------------------
  ------------------
  507|      0|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  508|      0|	}
  509|      0|	buff = OPENSSL_malloc(i2d_X509(x,NULL) + EVP_MAX_MD_SIZE);
  510|      0|	if (!buff) {
  ------------------
  |  Branch (510:6): [True: 0, False: 0]
  ------------------
  511|      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__
  |  |  ------------------
  ------------------
  512|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "OpenSSL 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|      0|	}
  514|       |
  515|      0|	ptr = buff;
  516|      0|	rv = i2d_X509_NAME(X509_get_subject_name(x), &ptr);
  517|      0|	if (rv <= 0) {
  ------------------
  |  Branch (517:6): [True: 0, False: 0]
  ------------------
  518|      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__
  |  |  ------------------
  ------------------
  519|      0|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "Get subject name 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|      0|	}
  521|       |
  522|      0|	key_info->subject.value = malloc(rv);
  523|      0|	if (!key_info->subject.value)
  ------------------
  |  Branch (523:6): [True: 0, False: 0]
  ------------------
  524|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Subject 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|       |
  526|      0|	memcpy(key_info->subject.value, buff, rv);
  527|      0|	key_info->subject.len = rv;
  528|       |
  529|      0|	strlcpy(key_object->label, cert_object->label, sizeof(key_object->label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  530|       |
  531|      0|	rv = 0;
  532|       |
  533|      0|	if (x)
  ------------------
  |  Branch (533:6): [True: 0, False: 0]
  ------------------
  534|      0|		X509_free(x);
  535|      0|	if (mem)
  ------------------
  |  Branch (535:6): [True: 0, False: 0]
  ------------------
  536|      0|		BIO_free(mem);
  537|      0|	if (buff)
  ------------------
  |  Branch (537:6): [True: 0, False: 0]
  ------------------
  538|      0|		OPENSSL_free(buff);
  539|       |
  540|      0|	ERR_clear_error();
  541|       |
  542|      0|	if (out_key_object)
  ------------------
  |  Branch (542:6): [True: 0, False: 0]
  ------------------
  543|      0|		*out_key_object = key_object;
  544|       |
  545|      0|	sc_log(ctx, "Subject %s", sc_dump_hex(key_info->subject.value, key_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__
  |  |  ------------------
  ------------------
  546|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  547|       |#else
  548|       |	LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  549|       |#endif
  550|      0|}
sc_pkcs15_free_prkey_info:
  594|  1.78k|{
  595|  1.78k|	if (!key)
  ------------------
  |  Branch (595:6): [True: 0, False: 1.78k]
  ------------------
  596|      0|		return;
  597|       |
  598|  1.78k|	if (key->subject.value)
  ------------------
  |  Branch (598:6): [True: 0, False: 1.78k]
  ------------------
  599|      0|		free(key->subject.value);
  600|       |
  601|  1.78k|	sc_pkcs15_free_key_params(&key->params);
  602|       |
  603|  1.78k|	sc_aux_data_free(&key->aux_data);
  604|       |
  605|  1.78k|	free(key);
  606|  1.78k|}

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

sc_pkcs15_decode_pukdf_entry:
  202|    112|{
  203|    112|	struct sc_context *ctx = p15card->card->ctx;
  204|    112|	struct sc_pkcs15_pubkey_info *info;
  205|    112|	int r, gostr3410_params[3];
  206|    112|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  207|    112|	size_t usage_len, af_len;
  208|    112|	struct sc_pkcs15_der *der = &obj->content;
  209|    112|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  210|    112|	struct sc_asn1_entry asn1_com_pubkey_attr[C_ASN1_COM_PUBKEY_ATTR_SIZE];
  211|    112|	struct sc_asn1_entry asn1_rsakey_value_choice[C_ASN1_RSAKEY_VALUE_CHOICE_SIZE];
  212|    112|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  213|    112|	struct sc_asn1_entry asn1_rsa_type_attr[C_ASN1_RSA_TYPE_ATTR_SIZE];
  214|    112|	struct sc_asn1_entry asn1_eckey_value_choice[C_ASN1_ECKEY_VALUE_CHOICE_SIZE];
  215|    112|	struct sc_asn1_entry asn1_eckey_attr[C_ASN1_ECKEY_ATTR_SIZE];
  216|    112|	struct sc_asn1_entry asn1_ec_type_attr[C_ASN1_EC_TYPE_ATTR_SIZE];
  217|    112|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOST3410KEY_ATTR_SIZE];
  218|    112|	struct sc_asn1_entry asn1_gostr3410_type_attr[C_ASN1_GOST3410_TYPE_ATTR_SIZE];
  219|    112|	struct sc_asn1_entry asn1_pubkey_choice[C_ASN1_PUBKEY_CHOICE_SIZE];
  220|    112|	struct sc_asn1_entry asn1_pubkey[C_ASN1_PUBKEY_SIZE];
  221|    112|	struct sc_asn1_pkcs15_object rsakey_obj = { obj, asn1_com_key_attr,
  222|    112|			asn1_com_pubkey_attr, asn1_rsa_type_attr };
  223|    112|	struct sc_asn1_pkcs15_object eckey_obj = { obj, asn1_com_key_attr,
  224|    112|			asn1_com_pubkey_attr, asn1_ec_type_attr };
  225|    112|	struct sc_asn1_pkcs15_object gostr3410key_obj =  { obj, asn1_com_key_attr,
  226|    112|			asn1_com_pubkey_attr, asn1_gostr3410_type_attr };
  227|       |
  228|    112|	info = calloc(1, sizeof *info);
  229|    112|	if (info == NULL) {
  ------------------
  |  Branch (229:6): [True: 0, False: 112]
  ------------------
  230|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  231|      0|		goto err;
  232|      0|	}
  233|    112|	usage_len = sizeof(info->usage);
  234|    112|	af_len = sizeof(info->access_flags);
  235|       |
  236|    112|	sc_copy_asn1_entry(c_asn1_pubkey, asn1_pubkey);
  237|    112|	sc_copy_asn1_entry(c_asn1_pubkey_choice, asn1_pubkey_choice);
  238|    112|	sc_copy_asn1_entry(c_asn1_rsa_type_attr, asn1_rsa_type_attr);
  239|    112|	sc_copy_asn1_entry(c_asn1_rsakey_value_choice, asn1_rsakey_value_choice);
  240|    112|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  241|    112|	sc_copy_asn1_entry(c_asn1_ec_type_attr, asn1_ec_type_attr);
  242|    112|	sc_copy_asn1_entry(c_asn1_eckey_value_choice, asn1_eckey_value_choice);
  243|    112|	sc_copy_asn1_entry(c_asn1_eckey_attr, asn1_eckey_attr);
  244|    112|	sc_copy_asn1_entry(c_asn1_gostr3410_type_attr, asn1_gostr3410_type_attr);
  245|    112|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  246|    112|	sc_copy_asn1_entry(c_asn1_com_pubkey_attr, asn1_com_pubkey_attr);
  247|    112|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  248|       |
  249|    112|	sc_format_asn1_entry(asn1_com_pubkey_attr + 0, &info->subject.value, &info->subject.len, 0);
  250|       |
  251|    112|	sc_format_asn1_entry(asn1_pubkey_choice + 0, &rsakey_obj, NULL, 0);
  252|    112|	sc_format_asn1_entry(asn1_pubkey_choice + 1, &gostr3410key_obj, NULL, 0);
  253|    112|	sc_format_asn1_entry(asn1_pubkey_choice + 2, &eckey_obj, NULL, 0);
  254|       |
  255|    112|	sc_format_asn1_entry(asn1_rsa_type_attr + 0, asn1_rsakey_attr, NULL, 0);
  256|       |
  257|    112|	sc_format_asn1_entry(asn1_rsakey_value_choice + 0, &info->path, NULL, 0);
  258|    112|	sc_format_asn1_entry(asn1_rsakey_value_choice + 1, &der->value, &der->len, 0);
  259|       |
  260|    112|	sc_format_asn1_entry(asn1_rsakey_attr + 0, asn1_rsakey_value_choice, NULL, 0);
  261|    112|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info->modulus_length, NULL, 0);
  262|       |
  263|    112|	sc_format_asn1_entry(asn1_ec_type_attr + 0, asn1_eckey_attr, NULL, 0);
  264|       |
  265|    112|	sc_format_asn1_entry(asn1_eckey_value_choice + 0, &info->path, NULL, 0);
  266|    112|	sc_format_asn1_entry(asn1_eckey_value_choice + 1, &der->value, &der->len, 0);
  267|       |
  268|    112|	sc_format_asn1_entry(asn1_eckey_attr + 0, asn1_eckey_value_choice, NULL, 0);
  269|       |
  270|    112|	sc_format_asn1_entry(asn1_gostr3410_type_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  271|       |
  272|    112|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info->path, NULL, 0);
  273|    112|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  274|    112|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  275|    112|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  276|       |
  277|    112|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info->id, NULL, 0);
  278|    112|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info->usage, &usage_len, 0);
  279|    112|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info->native, NULL, 0);
  280|    112|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info->access_flags, &af_len, 0);
  281|    112|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info->key_reference, NULL, 0);
  282|       |
  283|    112|	sc_format_asn1_entry(asn1_pubkey + 0, asn1_pubkey_choice, NULL, 0);
  284|       |
  285|       |	/* Fill in defaults */
  286|    112|	info->key_reference = -1;
  287|    112|	info->native = 1;
  288|    112|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  289|       |
  290|    112|	r = sc_asn1_decode(ctx, asn1_pubkey, *buf, *buflen, buf, buflen);
  291|    112|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    112|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (291:6): [True: 40, False: 72]
  ------------------
  292|     40|		goto err;
  293|     72|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  184|     72|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     72|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     72|	int _ret = (r); \
  |  |  |  |  178|     72|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 72, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     72|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     72|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     72|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     72|		goto err; \
  |  |  |  |  182|     72|	} \
  |  |  |  |  183|     72|} 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|    112|err:
  355|    112|	if (r < 0) {
  ------------------
  |  Branch (355:6): [True: 112, False: 0]
  ------------------
  356|    112|		sc_pkcs15_free_pubkey_info(info);
  357|    112|		if (der->len) {
  ------------------
  |  Branch (357:7): [True: 0, False: 112]
  ------------------
  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|    112|	}
  364|       |
  365|    112|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    112|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    112|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    112|	int _ret = r; \
  |  |  |  |  155|    112|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 112, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    112|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    112|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 112, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    112|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    112|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    112|	return _ret; \
  |  |  |  |  163|    112|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  366|    112|}
sc_pkcs15_encode_pukdf_entry:
  372|    208|{
  373|    208|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  374|    208|	struct sc_asn1_entry asn1_com_pubkey_attr[C_ASN1_COM_PUBKEY_ATTR_SIZE];
  375|    208|	struct sc_asn1_entry asn1_rsakey_value_choice[C_ASN1_RSAKEY_VALUE_CHOICE_SIZE];
  376|    208|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  377|    208|	struct sc_asn1_entry asn1_rsa_type_attr[C_ASN1_RSA_TYPE_ATTR_SIZE];
  378|    208|	struct sc_asn1_entry asn1_eckey_value_choice[C_ASN1_ECKEY_VALUE_CHOICE_SIZE];
  379|    208|	struct sc_asn1_entry asn1_eckey_attr[C_ASN1_ECKEY_ATTR_SIZE];
  380|    208|	struct sc_asn1_entry asn1_ec_type_attr[C_ASN1_EC_TYPE_ATTR_SIZE];
  381|    208|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOST3410KEY_ATTR_SIZE];
  382|    208|	struct sc_asn1_entry asn1_gostr3410_type_attr[C_ASN1_GOST3410_TYPE_ATTR_SIZE];
  383|    208|	struct sc_asn1_entry asn1_pubkey_choice[C_ASN1_PUBKEY_CHOICE_SIZE];
  384|    208|	struct sc_asn1_entry asn1_pubkey[C_ASN1_PUBKEY_SIZE];
  385|       |
  386|    208|	struct sc_pkcs15_pubkey_info *pubkey = (struct sc_pkcs15_pubkey_info *) obj->data;
  387|    208|	struct sc_asn1_pkcs15_object rsakey_obj = {
  388|    208|		(struct sc_pkcs15_object *) obj, asn1_com_key_attr, asn1_com_pubkey_attr, asn1_rsa_type_attr
  389|    208|	};
  390|    208|	struct sc_asn1_pkcs15_object eckey_obj = { (struct sc_pkcs15_object *) obj,
  391|    208|			asn1_com_key_attr,
  392|    208|			asn1_com_pubkey_attr, asn1_ec_type_attr };
  393|    208|	struct sc_asn1_pkcs15_object gostr3410key_obj =  { (struct sc_pkcs15_object *) obj,
  394|    208|			asn1_com_key_attr,
  395|    208|			asn1_com_pubkey_attr, asn1_gostr3410_type_attr };
  396|    208|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  397|    208|	int r;
  398|    208|	size_t af_len, usage_len;
  399|    208|	unsigned char *spki_value = NULL;
  400|       |
  401|    208|	sc_copy_asn1_entry(c_asn1_pubkey, asn1_pubkey);
  402|    208|	sc_copy_asn1_entry(c_asn1_pubkey_choice, asn1_pubkey_choice);
  403|    208|	sc_copy_asn1_entry(c_asn1_rsa_type_attr, asn1_rsa_type_attr);
  404|    208|	sc_copy_asn1_entry(c_asn1_rsakey_value_choice, asn1_rsakey_value_choice);
  405|    208|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  406|    208|	sc_copy_asn1_entry(c_asn1_ec_type_attr, asn1_ec_type_attr);
  407|    208|	sc_copy_asn1_entry(c_asn1_eckey_value_choice, asn1_eckey_value_choice);
  408|    208|	sc_copy_asn1_entry(c_asn1_eckey_attr, asn1_eckey_attr);
  409|    208|	sc_copy_asn1_entry(c_asn1_gostr3410_type_attr, asn1_gostr3410_type_attr);
  410|    208|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  411|    208|	sc_copy_asn1_entry(c_asn1_com_pubkey_attr, asn1_com_pubkey_attr);
  412|    208|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  413|       |
  414|    208|	switch (obj->type) {
  415|    136|	case SC_PKCS15_TYPE_PUBKEY_RSA:
  ------------------
  |  |  426|    136|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  |  Branch (415:2): [True: 136, False: 72]
  ------------------
  416|    136|		sc_format_asn1_entry(asn1_pubkey_choice + 0, &rsakey_obj, NULL, 1);
  417|       |
  418|    136|		sc_format_asn1_entry(asn1_rsa_type_attr + 0, asn1_rsakey_attr, NULL, 1);
  419|    136|		if (pubkey->path.len)   {
  ------------------
  |  Branch (419:7): [True: 99, False: 37]
  ------------------
  420|     99|			sc_format_asn1_entry(asn1_rsakey_value_choice + 0, &pubkey->path, NULL, 1);
  421|     99|		}
  422|     37|		else  if (pubkey->direct.raw.value && pubkey->direct.raw.len)   {
  ------------------
  |  Branch (422:13): [True: 0, False: 37]
  |  Branch (422:41): [True: 0, False: 0]
  ------------------
  423|       |			/* In RSAPublicKeyChoice 'raw' value keep it's SEQUENCE tag */
  424|      0|			sc_log(ctx,  "Encode 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__
  |  |  ------------------
  ------------------
  425|      0|			sc_format_asn1_entry(asn1_rsakey_value_choice + 1, pubkey->direct.raw.value, (void *)&pubkey->direct.raw.len, 1);
  426|      0|		}
  427|     37|		else  if (pubkey->direct.spki.value && pubkey->direct.spki.len)   {
  ------------------
  |  Branch (427:13): [True: 37, False: 0]
  |  Branch (427:42): [True: 37, False: 0]
  ------------------
  428|       |			/* In RSAPublicKeyChoice 'spki' value changes initial SEQUENCE tag for
  429|       |			 * CONTEXT [1] constructed SEQUENCE */
  430|     37|			sc_log(ctx,  "Encode direct 'SPKI' value");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  431|     37|			spki_value = malloc(pubkey->direct.spki.len);
  432|     37|			if (!spki_value)
  ------------------
  |  Branch (432:8): [True: 0, False: 37]
  ------------------
  433|     37|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  434|     37|			memcpy(spki_value, pubkey->direct.spki.value, pubkey->direct.spki.len);
  435|     37|			*spki_value = (SC_ASN1_TAG_CONTEXT | SC_ASN1_TAG_CONSTRUCTED | 0x01);
  ------------------
  |  |  187|     37|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
              			*spki_value = (SC_ASN1_TAG_CONTEXT | SC_ASN1_TAG_CONSTRUCTED | 0x01);
  ------------------
  |  |  190|     37|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  436|       |
  437|     37|			sc_format_asn1_entry(asn1_rsakey_value_choice + 1, spki_value, (void *)&pubkey->direct.spki.len, 1);
  438|     37|		}
  439|      0|		else if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (439:12): [True: 0, False: 0]
  |  Branch (439:34): [True: 0, False: 0]
  ------------------
  440|      0|			sc_log(ctx,  "Encode 'RAW' 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__
  |  |  ------------------
  ------------------
  441|      0|			sc_format_asn1_entry(asn1_rsakey_value_choice + 1, obj->content.value, (void *)&obj->content.len, 1);
  442|      0|		}
  443|      0|		else   {
  444|      0|			sc_log(ctx,  "Use empty 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__
  |  |  ------------------
  ------------------
  445|      0|			sc_format_asn1_entry(asn1_rsakey_value_choice + 0, &pubkey->path, NULL, 1);
  446|      0|		}
  447|       |
  448|    136|		sc_format_asn1_entry(asn1_rsakey_attr + 0, asn1_rsakey_value_choice, NULL, 1);
  449|    136|		sc_format_asn1_entry(asn1_rsakey_attr + 1, &pubkey->modulus_length, NULL, 1);
  450|    136|		break;
  451|      0|	case SC_PKCS15_TYPE_PUBKEY_GOSTR3410:
  ------------------
  |  |  427|      0|#define SC_PKCS15_TYPE_PUBKEY_GOSTR3410		0x203
  ------------------
  |  Branch (451:2): [True: 0, False: 208]
  ------------------
  452|      0|		sc_format_asn1_entry(asn1_pubkey_choice + 1, &gostr3410key_obj, NULL, 1);
  453|       |
  454|      0|		sc_format_asn1_entry(asn1_gostr3410_type_attr + 0, asn1_gostr3410key_attr, NULL, 1);
  455|       |
  456|      0|		sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &pubkey->path, NULL, 1);
  457|      0|		if (pubkey->params.len == sizeof(*keyinfo_gostparams))   {
  ------------------
  |  Branch (457:7): [True: 0, False: 0]
  ------------------
  458|      0|			keyinfo_gostparams = pubkey->params.data;
  459|      0|			sc_format_asn1_entry(asn1_gostr3410key_attr + 1,
  460|      0|					&keyinfo_gostparams->gostr3410, NULL, 1);
  461|      0|			sc_format_asn1_entry(asn1_gostr3410key_attr + 2,
  462|      0|					&keyinfo_gostparams->gostr3411, NULL, 1);
  463|      0|			sc_format_asn1_entry(asn1_gostr3410key_attr + 3,
  464|      0|					&keyinfo_gostparams->gost28147, NULL, 1);
  465|      0|		}
  466|      0|		break;
  467|     72|	case SC_PKCS15_TYPE_PUBKEY_EC:
  ------------------
  |  |  428|     72|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  |  Branch (467:2): [True: 72, False: 136]
  ------------------
  468|     72|		sc_format_asn1_entry(asn1_pubkey_choice + 2, &eckey_obj, NULL, 1);
  469|       |
  470|     72|		sc_format_asn1_entry(asn1_ec_type_attr + 0, asn1_eckey_attr, NULL, 1);
  471|       |
  472|     72|		if (pubkey->path.len)   {
  ------------------
  |  Branch (472:7): [True: 0, False: 72]
  ------------------
  473|      0|			sc_format_asn1_entry(asn1_eckey_value_choice + 0, &pubkey->path, NULL, 1);
  474|      0|		}
  475|     72|		else  if (pubkey->direct.spki.value)   {
  ------------------
  |  Branch (475:13): [True: 72, False: 0]
  ------------------
  476|     72|			sc_format_asn1_entry(asn1_eckey_value_choice + 1, pubkey->direct.spki.value, (void *)&pubkey->direct.spki.len, 1);
  477|     72|		}
  478|      0|		else  if (pubkey->direct.raw.value)   {
  ------------------
  |  Branch (478:13): [True: 0, False: 0]
  ------------------
  479|      0|			sc_format_asn1_entry(asn1_eckey_value_choice + 1, pubkey->direct.raw.value, (void *)&pubkey->direct.raw.len, 1);
  480|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "Needs KeyInfo with reference to algorithm in TokenInfo");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|      0|		}
  482|      0|		else  if (obj->content.value)   {
  ------------------
  |  Branch (482:13): [True: 0, False: 0]
  ------------------
  483|      0|			sc_format_asn1_entry(asn1_eckey_value_choice + 1, obj->content.value, (void *)&obj->content.len, 1);
  484|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "Needs KeyInfo with reference to algorithm in TokenInfo");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  485|      0|		}
  486|       |
  487|     72|		sc_format_asn1_entry(asn1_eckey_attr + 0, asn1_eckey_value_choice, NULL, 1);
  488|       |
  489|     72|		break;
  490|      0|	default:
  ------------------
  |  Branch (490:2): [True: 0, False: 208]
  ------------------
  491|      0|		sc_log(ctx,  "Unsupported public key type: %X", 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__
  |  |  ------------------
  ------------------
  492|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  493|      0|		break;
  494|    208|	}
  495|       |
  496|    208|	sc_format_asn1_entry(asn1_com_key_attr + 0, &pubkey->id, NULL, 1);
  497|    208|	usage_len = sizeof(pubkey->usage);
  498|    208|	sc_format_asn1_entry(asn1_com_key_attr + 1, &pubkey->usage, &usage_len, 1);
  499|    208|	if (pubkey->native == 0)
  ------------------
  |  Branch (499:6): [True: 0, False: 208]
  ------------------
  500|      0|		sc_format_asn1_entry(asn1_com_key_attr + 2, &pubkey->native, NULL, 1);
  501|    208|	if (pubkey->access_flags) {
  ------------------
  |  Branch (501:6): [True: 186, False: 22]
  ------------------
  502|    186|		af_len = sizeof(pubkey->access_flags);
  503|    186|		sc_format_asn1_entry(asn1_com_key_attr + 3, &pubkey->access_flags, &af_len, 1);
  504|    186|	}
  505|    208|	if (pubkey->key_reference >= 0)
  ------------------
  |  Branch (505:6): [True: 191, False: 17]
  ------------------
  506|    191|		sc_format_asn1_entry(asn1_com_key_attr + 4, &pubkey->key_reference, NULL, 1);
  507|    208|	sc_format_asn1_entry(asn1_pubkey + 0, asn1_pubkey_choice, NULL, 1);
  508|       |
  509|    208|	if (pubkey->subject.value && pubkey->subject.len)
  ------------------
  |  Branch (509:6): [True: 0, False: 208]
  |  Branch (509:31): [True: 0, False: 0]
  ------------------
  510|      0|		sc_format_asn1_entry(asn1_com_pubkey_attr + 0, pubkey->subject.value, &pubkey->subject.len, 1);
  511|    208|	else
  512|    208|		memset(asn1_com_pubkey_attr, 0, sizeof(asn1_com_pubkey_attr));
  513|       |
  514|    208|	r = sc_asn1_encode(ctx, asn1_pubkey, buf, buflen);
  515|       |
  516|    208|	sc_log(ctx, "Key path %s", sc_print_path(&pubkey->path));
  ------------------
  |  |   71|    208|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  517|       |
  518|    208|	free(spki_value);
  519|    208|	return r;
  520|    208|}
sc_pkcs15_decode_pubkey_rsa:
  563|    155|{
  564|    155|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  565|    155|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  566|    155|	int r;
  567|       |
  568|    155|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    155|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    155|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    155|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    155|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 155]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|    155|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  570|    155|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 0);
  571|       |
  572|    155|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  573|    155|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, &key->modulus.data, &key->modulus.len, 0);
  574|    155|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, &key->exponent.data, &key->exponent.len, 0);
  575|       |
  576|    155|	r = sc_asn1_decode(ctx, asn1_public_key, buf, buflen, NULL, NULL);
  577|    155|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of public key failed");
  ------------------
  |  |  174|    155|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    155|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    155|	int _ret = (r); \
  |  |  |  |  168|    155|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  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|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|       |
  579|    127|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    127|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    127|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    127|	int _ret = r; \
  |  |  |  |  155|    127|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 127, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    127|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  157|    127|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    127|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    127|	return _ret; \
  |  |  |  |  163|    127|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|    127|}
sc_pkcs15_encode_pubkey_rsa:
  586|    189|{
  587|    189|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  588|    189|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  589|    189|	int r;
  590|       |
  591|    189|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    189|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    189|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    189|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    189|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 189]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|    189|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  593|    189|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 1);
  594|       |
  595|    189|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  596|    189|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, key->modulus.data, &key->modulus.len, 1);
  597|    189|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, key->exponent.data, &key->exponent.len, 1);
  598|       |
  599|    189|	r = sc_asn1_encode(ctx, asn1_public_key, buf, buflen);
  600|    189|	LOG_TEST_RET(ctx, r, "ASN.1 encoding failed");
  ------------------
  |  |  174|    189|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    189|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    189|	int _ret = (r); \
  |  |  |  |  168|    189|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 160]
  |  |  |  |  ------------------
  |  |  |  |  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|    189|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 160]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  601|       |
  602|    160|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    160|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    160|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    160|	int _ret = r; \
  |  |  |  |  155|    160|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 160, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    160|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 160]
  |  |  |  |  ------------------
  |  |  |  |  157|    160|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    160|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    160|	return _ret; \
  |  |  |  |  163|    160|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  603|    160|}
sc_pkcs15_encode_pubkey:
  769|     87|{
  770|     87|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   78|     87|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (770:6): [True: 87, False: 0]
  ------------------
  771|     87|		return sc_pkcs15_encode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
  772|      0|	if (key->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (772:6): [True: 0, False: 0]
  ------------------
  773|      0|		return sc_pkcs15_encode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
  774|      0|	if (key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (774:6): [True: 0, False: 0]
  ------------------
  775|      0|		return sc_pkcs15_encode_pubkey_ec(ctx, &key->u.ec, buf, len);
  776|      0|	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   81|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
              	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (776:6): [True: 0, False: 0]
  |  Branch (776:46): [True: 0, False: 0]
  ------------------
  777|      0|		return sc_pkcs15_encode_pubkey_eddsa(ctx, &key->u.ec, buf, len);
  778|       |
  779|      0|	sc_log(ctx, "Encoding of public key type %lu not supported", key->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  780|      0|	LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  781|      0|}
sc_pkcs15_encode_pubkey_as_spki:
  801|    161|{
  802|    161|	int r = 0;
  803|    161|	struct sc_asn1_entry  asn1_spki_key[2], asn1_spki_key_items[3];
  804|    161|	struct sc_pkcs15_u8 pkey;
  805|    161|	size_t key_len;
  806|       |
  807|    161|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    161|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    161|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    161|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    161|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 161]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  808|    161|	pkey.value =  NULL;
  809|    161|	pkey.len = 0;
  810|       |
  811|    161|	sc_log(ctx, "Encoding public key with algorithm %lu", pubkey->algorithm);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  812|    161|	if (!pubkey->alg_id)   {
  ------------------
  |  Branch (812:6): [True: 31, False: 130]
  ------------------
  813|     31|		pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
  814|     31|		if (!pubkey->alg_id)
  ------------------
  |  Branch (814:7): [True: 0, False: 31]
  ------------------
  815|     31|			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|     31|		sc_init_oid(&pubkey->alg_id->oid);
  818|     31|		pubkey->alg_id->algorithm = pubkey->algorithm;
  819|     31|	}
  820|       |
  821|    161|	switch (pubkey->algorithm) {
  822|     74|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|     74|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (822:2): [True: 74, False: 87]
  ------------------
  823|     74|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|     74|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (823:2): [True: 0, False: 161]
  ------------------
  824|     74|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|     74|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (824:2): [True: 0, False: 161]
  ------------------
  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|     74|		key_len = pubkey->u.ec.ecpointQ.len * 8;
  831|     74|		pkey.value = pubkey->u.ec.ecpointQ.value;
  832|     74|		pkey.len = 0; /* flag as do not delete */
  833|       |
  834|     74|		if (pubkey->u.ec.params.named_curve || pubkey->u.ec.params.der.value)   {
  ------------------
  |  Branch (834:7): [True: 73, False: 1]
  |  Branch (834:42): [True: 0, False: 1]
  ------------------
  835|     73|			struct sc_ec_parameters *ec_params = NULL;
  836|       |
  837|     73|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
  838|     73|			LOG_TEST_RET(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  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: 0, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     73|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 73]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|       |			/* EDDSA and XEDDSA only have algo and no param in SPKI */
  841|     73|			if (pubkey->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|     73|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (841:8): [True: 73, False: 0]
  ------------------
  842|     73|				ec_params = calloc(1, sizeof(struct sc_ec_parameters));
  843|     73|				if (!ec_params)
  ------------------
  |  Branch (843:9): [True: 0, False: 73]
  ------------------
  844|     73|					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|     73|				ec_params->type = 1;
  846|     73|				ec_params->der.value = calloc(1, pubkey->u.ec.params.der.len);
  847|     73|				if (!ec_params->der.value) {
  ------------------
  |  Branch (847:9): [True: 0, False: 73]
  ------------------
  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|     73|				memcpy(ec_params->der.value, pubkey->u.ec.params.der.value, pubkey->u.ec.params.der.len);
  852|     73|				ec_params->der.len = pubkey->u.ec.params.der.len;
  853|     73|			}
  854|       |			/* This could have been already allocated: avoid memory leak */
  855|     73|			sc_asn1_clear_algorithm_id(pubkey->alg_id);
  856|     73|			pubkey->alg_id->params = ec_params; /* NULL for EDDSA and XEDDSA */
  857|     73|		}
  858|     74|		break;
  859|     74|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (859:2): [True: 0, False: 161]
  ------------------
  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|     87|	default:
  ------------------
  |  Branch (865:2): [True: 87, False: 74]
  ------------------
  866|     87|		r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
  867|     87|		key_len = pkey.len * 8;
  868|     87|		break;
  869|    161|	}
  870|       |
  871|    161|	if (r == 0) {
  ------------------
  |  Branch (871:6): [True: 138, False: 23]
  ------------------
  872|    138|		sc_copy_asn1_entry(c_asn1_spki_key, asn1_spki_key);
  873|    138|		sc_copy_asn1_entry(c_asn1_spki_key_items, asn1_spki_key_items);
  874|    138|		sc_format_asn1_entry(asn1_spki_key + 0, asn1_spki_key_items, NULL, 1);
  875|    138|		sc_format_asn1_entry(asn1_spki_key_items + 0, pubkey->alg_id, NULL, 1);
  876|    138|		sc_format_asn1_entry(asn1_spki_key_items + 1, pkey.value, &key_len, 1);
  877|       |
  878|    138|		r =  sc_asn1_encode(ctx, asn1_spki_key, buf, len);
  879|    138|	}
  880|       |
  881|       |	/*  pkey.len == 0 is flag to not delete */
  882|    161|	if (pkey.len && pkey.value)
  ------------------
  |  Branch (882:6): [True: 64, False: 97]
  |  Branch (882:18): [True: 64, False: 0]
  ------------------
  883|     64|		free(pkey.value);
  884|       |
  885|    161|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    161|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    161|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    161|	int _ret = r; \
  |  |  |  |  155|    161|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 161, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    161|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  157|    161|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    161|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    161|	return _ret; \
  |  |  |  |  163|    161|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|    161|}
sc_pkcs15_decode_pubkey:
  892|    171|{
  893|    171|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   78|    171|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (893:6): [True: 155, False: 16]
  ------------------
  894|    155|		return sc_pkcs15_decode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
  895|     16|	if (key->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   80|     16|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (895:6): [True: 0, False: 16]
  ------------------
  896|      0|		return sc_pkcs15_decode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
  897|     16|	if (key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   79|     16|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (897:6): [True: 0, False: 16]
  ------------------
  898|      0|		return sc_pkcs15_decode_pubkey_ec(ctx, &key->u.ec, buf, len);
  899|     16|	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   81|     32|#define SC_ALGORITHM_EDDSA		4
  ------------------
              	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|     16|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (899:6): [True: 0, False: 16]
  |  Branch (899:46): [True: 0, False: 16]
  ------------------
  900|      0|		return sc_pkcs15_decode_pubkey_eddsa(ctx, &key->u.ec, buf, len);
  901|       |
  902|     16|	sc_log(ctx, "Decoding of public key type %lu not supported", key->algorithm);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  903|     16|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     16|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  904|     16|}
sc_pkcs15_read_pubkey:
  913|    208|{
  914|    208|	struct sc_context *ctx;
  915|    208|	const struct sc_pkcs15_pubkey_info *info = NULL;
  916|    208|	struct sc_pkcs15_pubkey *pubkey = NULL;
  917|    208|	unsigned char *data = NULL;
  918|    208|	size_t	len;
  919|    208|	int	algorithm, r;
  920|    208|	int	private_obj;
  921|       |
  922|    208|	if (p15card == NULL || p15card->card == NULL || p15card->card->ops == NULL
  ------------------
  |  Branch (922:6): [True: 0, False: 208]
  |  Branch (922:25): [True: 0, False: 208]
  |  Branch (922:50): [True: 0, False: 208]
  ------------------
  923|    208|			|| obj == NULL || out == NULL) {
  ------------------
  |  Branch (923:7): [True: 0, False: 208]
  |  Branch (923:22): [True: 0, False: 208]
  ------------------
  924|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  925|      0|	}
  926|    208|	ctx = p15card->card->ctx;
  927|       |
  928|    208|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    208|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    208|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    208|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    208|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 208]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  929|    208|	sc_log(ctx, "Public key type 0x%X", obj->type);
  ------------------
  |  |   71|    208|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  930|       |
  931|    208|	switch (obj->type) {
  932|    136|	case SC_PKCS15_TYPE_PUBKEY_RSA:
  ------------------
  |  |  426|    136|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  |  Branch (932:2): [True: 136, False: 72]
  ------------------
  933|    136|		algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   78|    136|#define SC_ALGORITHM_RSA		0
  ------------------
  934|    136|		break;
  935|      0|	case SC_PKCS15_TYPE_PUBKEY_GOSTR3410:
  ------------------
  |  |  427|      0|#define SC_PKCS15_TYPE_PUBKEY_GOSTR3410		0x203
  ------------------
  |  Branch (935:2): [True: 0, False: 208]
  ------------------
  936|      0|		algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  937|      0|		break;
  938|     72|	case SC_PKCS15_TYPE_PUBKEY_EC:
  ------------------
  |  |  428|     72|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  |  Branch (938:2): [True: 72, False: 136]
  ------------------
  939|     72|		algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   79|     72|#define SC_ALGORITHM_EC		2
  ------------------
  940|     72|		break;
  941|      0|	case SC_PKCS15_TYPE_PUBKEY_EDDSA:
  ------------------
  |  |  429|      0|#define SC_PKCS15_TYPE_PUBKEY_EDDSA		0x205
  ------------------
  |  Branch (941:2): [True: 0, False: 208]
  ------------------
  942|      0|		algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   81|      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: 208]
  ------------------
  945|      0|		algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  946|      0|		break;
  947|      0|	default:
  ------------------
  |  Branch (947:2): [True: 0, False: 208]
  ------------------
  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|    208|	}
  950|    208|	info = (const struct sc_pkcs15_pubkey_info *) obj->data;
  951|       |
  952|    208|	pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey));
  953|    208|	if (pubkey == NULL) {
  ------------------
  |  Branch (953:6): [True: 0, False: 208]
  ------------------
  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|    208|	pubkey->algorithm = algorithm;
  957|       |
  958|       |	/* starting from SPKI direct value
  959|       |	   in a compact form it presents complete public key data */
  960|    208|	if (info->direct.spki.value && info->direct.spki.len)   {
  ------------------
  |  Branch (960:6): [True: 131, False: 77]
  |  Branch (960:33): [True: 131, False: 0]
  ------------------
  961|    131|		sc_log(ctx, "Using direct SPKI value,  tag 0x%X", *(info->direct.spki.value));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  962|    131|		r = sc_pkcs15_pubkey_from_spki_sequence(ctx, info->direct.spki.value, info->direct.spki.len, &pubkey);
  963|    131|		LOG_TEST_GOTO_ERR(ctx, r, "Failed to decode 'SPKI' direct value");
  ------------------
  |  |  184|    131|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    131|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    131|	int _ret = (r); \
  |  |  |  |  178|    131|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  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|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  964|    131|	}
  965|     77|	else if (info->direct.raw.value && info->direct.raw.len)   {
  ------------------
  |  Branch (965:11): [True: 0, False: 77]
  |  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|     77|	else if (obj->content.value && obj->content.len)   {
  ------------------
  |  Branch (971:11): [True: 0, False: 77]
  |  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|     77|	else if (p15card->card->ops->read_public_key)   {
  ------------------
  |  Branch (977:11): [True: 0, False: 77]
  ------------------
  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|     77|	else if (info->path.len)   {
  ------------------
  |  Branch (987:11): [True: 77, False: 0]
  ------------------
  988|     77|		sc_log(ctx, "Read from EF and decode");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  989|     77|		private_obj = obj->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     77|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  990|     77|		r = sc_pkcs15_read_file(p15card, &info->path, &data, &len, private_obj);
  991|     77|		LOG_TEST_GOTO_ERR(ctx, r, "Failed to read public key file.");
  ------------------
  |  |  184|     77|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     77|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     77|	int _ret = (r); \
  |  |  |  |  178|     77|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 56, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     56|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     56|		goto err; \
  |  |  |  |  182|     56|	} \
  |  |  |  |  183|     77|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 21]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  992|       |
  993|     21|		if ((algorithm == SC_ALGORITHM_EC || algorithm == SC_ALGORITHM_EDDSA || algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   79|     42|#define SC_ALGORITHM_EC		2
  ------------------
              		if ((algorithm == SC_ALGORITHM_EC || algorithm == SC_ALGORITHM_EDDSA || algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   81|     42|#define SC_ALGORITHM_EDDSA		4
  ------------------
              		if ((algorithm == SC_ALGORITHM_EC || algorithm == SC_ALGORITHM_EDDSA || algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|     21|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (993:8): [True: 0, False: 21]
  |  Branch (993:40): [True: 0, False: 21]
  |  Branch (993:75): [True: 0, False: 21]
  ------------------
  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|     21|		else
  997|     21|			r = sc_pkcs15_decode_pubkey(ctx, pubkey, data, len);
  998|     21|		LOG_TEST_GOTO_ERR(ctx, r, "Decode public key error");
  ------------------
  |  |  184|     21|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     21|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     21|	int _ret = (r); \
  |  |  |  |  178|     21|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 18, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  179|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     18|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     18|		goto err; \
  |  |  |  |  182|     18|	} \
  |  |  |  |  183|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  999|     21|	}
 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|    208|err:
 1006|    208|	if (r) {
  ------------------
  |  Branch (1006:6): [True: 75, False: 133]
  ------------------
 1007|     75|		sc_pkcs15_free_pubkey(pubkey);
 1008|     75|	} else
 1009|    133|		*out = pubkey;
 1010|    208|	free(data);
 1011|       |
 1012|    208|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    208|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    208|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    208|	int _ret = r; \
  |  |  |  |  155|    208|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 208, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    208|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     75|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 75, False: 133]
  |  |  |  |  ------------------
  |  |  |  |  157|    208|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    208|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    208|	return _ret; \
  |  |  |  |  163|    208|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1013|    208|}
sc_pkcs15_erase_pubkey:
 1187|  1.79k|{
 1188|  1.79k|	if (key == NULL) {
  ------------------
  |  Branch (1188:6): [True: 0, False: 1.79k]
  ------------------
 1189|      0|		return;
 1190|      0|	}
 1191|  1.79k|	if (key->alg_id) {
  ------------------
  |  Branch (1191:6): [True: 392, False: 1.39k]
  ------------------
 1192|    392|		sc_asn1_clear_algorithm_id(key->alg_id);
 1193|    392|		free(key->alg_id);
 1194|    392|	}
 1195|  1.79k|	switch (key->algorithm) {
  ------------------
  |  Branch (1195:10): [True: 1.74k, False: 51]
  ------------------
 1196|  1.56k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|  1.56k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1196:2): [True: 1.56k, False: 229]
  ------------------
 1197|  1.56k|		free(key->u.rsa.modulus.data);
 1198|  1.56k|		free(key->u.rsa.exponent.data);
 1199|  1.56k|		break;
 1200|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (1200:2): [True: 0, False: 1.79k]
  ------------------
 1201|      0|		free(key->u.gostr3410.xy.data);
 1202|      0|		break;
 1203|    178|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|    178|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1203:2): [True: 178, False: 1.61k]
  ------------------
 1204|    178|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|    178|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1204:2): [True: 0, False: 1.79k]
  ------------------
 1205|    178|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|    178|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1205:2): [True: 0, False: 1.79k]
  ------------------
 1206|    178|		free(key->u.ec.params.der.value);
 1207|    178|		free(key->u.ec.params.named_curve);
 1208|    178|		free(key->u.ec.ecpointQ.value);
 1209|    178|		break;
 1210|  1.79k|	}
 1211|  1.79k|	sc_mem_clear(key, sizeof(*key));
 1212|  1.79k|}
sc_pkcs15_free_pubkey:
 1217|  3.59k|{
 1218|  3.59k|	if (!key)
  ------------------
  |  Branch (1218:6): [True: 1.80k, False: 1.79k]
  ------------------
 1219|  1.80k|		return;
 1220|  1.79k|	sc_pkcs15_erase_pubkey(key);
 1221|  1.79k|	free(key);
 1222|  1.79k|}
sc_pkcs15_free_pubkey_info:
 1227|    370|{
 1228|    370|	if (info) {
  ------------------
  |  Branch (1228:6): [True: 370, False: 0]
  ------------------
 1229|    370|		free(info->subject.value);
 1230|    370|		free(info->direct.spki.value);
 1231|    370|		free(info->direct.raw.value);
 1232|    370|		sc_pkcs15_free_key_params(&info->params);
 1233|    370|		free(info);
 1234|    370|	}
 1235|    370|}
sc_pkcs15_pubkey_from_spki_fields:
 1326|    488|{
 1327|       |
 1328|    488|	struct sc_pkcs15_pubkey *pubkey = NULL;
 1329|    488|	struct sc_pkcs15_der pk = { NULL, 0 };
 1330|    488|	struct sc_algorithm_id pk_alg;
 1331|    488|	struct sc_asn1_entry asn1_pkinfo[C_ASN1_PKINFO_ATTR_SIZE];
 1332|    488|	unsigned char *tmp_buf = NULL;
 1333|    488|	int r;
 1334|       |
 1335|    488|	sc_log(ctx,
  ------------------
  |  |   71|    488|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1336|    488|	       "sc_pkcs15_pubkey_from_spki_fields() called: %p:%"SC_FORMAT_LEN_SIZE_T"u\n%s",
 1337|    488|	       buf, buflen, sc_dump_hex(buf, buflen));
 1338|       |
 1339|    488|	if (buflen < 1) {
  ------------------
  |  Branch (1339:6): [True: 10, False: 478]
  ------------------
 1340|     10|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "subjectPublicKeyInfo can not be empty");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|     10|	}
 1342|       |
 1343|    478|	tmp_buf = malloc(buflen);
 1344|    478|	if (!tmp_buf) {
  ------------------
  |  Branch (1344:6): [True: 0, False: 478]
  ------------------
 1345|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1346|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1347|      0|	}
 1348|    478|	memcpy(tmp_buf, buf, buflen);
 1349|       |
 1350|    478|	if (buflen > 0 && (*tmp_buf & SC_ASN1_TAG_CONTEXT))
  ------------------
  |  |  187|    478|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (1350:6): [True: 478, False: 0]
  |  Branch (1350:20): [True: 34, False: 444]
  ------------------
 1351|     34|		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  190|     34|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
              		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  206|     34|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
 1352|       |
 1353|    478|	memset(&pk_alg, 0, sizeof(pk_alg));
 1354|    478|	pubkey = calloc(1, sizeof(sc_pkcs15_pubkey_t));
 1355|    478|	if (pubkey == NULL) {
  ------------------
  |  Branch (1355:6): [True: 0, False: 478]
  ------------------
 1356|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1357|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1358|      0|	}
 1359|       |
 1360|    478|	sc_copy_asn1_entry(c_asn1_pkinfo, asn1_pkinfo);
 1361|       |
 1362|    478|	sc_format_asn1_entry(asn1_pkinfo + 0, &pk_alg, NULL, 0);
 1363|    478|	sc_format_asn1_entry(asn1_pkinfo + 1, &pk.value, &pk.len, 0);
 1364|       |
 1365|    478|	r = sc_asn1_decode(ctx, asn1_pkinfo, tmp_buf, buflen, NULL, NULL);
 1366|    478|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    478|#define SC_SUCCESS				0
  ------------------
  |  Branch (1366:6): [True: 117, False: 361]
  ------------------
 1367|    117|		sc_asn1_clear_algorithm_id(&pk_alg);
 1368|    117|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|    117|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    117|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    117|	int _ret = (r); \
  |  |  |  |  178|    117|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 117, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    117|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    117|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    117|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    117|		goto err; \
  |  |  |  |  182|    117|	} \
  |  |  |  |  183|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1369|    117|	}
 1370|       |
 1371|    361|	pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
 1372|    361|	if (pubkey->alg_id == NULL) {
  ------------------
  |  Branch (1372:6): [True: 0, False: 361]
  ------------------
 1373|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1374|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1375|      0|	}
 1376|       |
 1377|    361|	memcpy(pubkey->alg_id, &pk_alg, sizeof(struct sc_algorithm_id));
 1378|    361|	pubkey->algorithm = pk_alg.algorithm;
 1379|    361|	pk_alg.params = NULL;
 1380|    361|	sc_log(ctx, "DEE pk_alg.algorithm=%lu", pk_alg.algorithm);
  ------------------
  |  |   71|    361|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1381|       |
 1382|    361|	if (pk.len == 0)
  ------------------
  |  Branch (1382:6): [True: 35, False: 326]
  ------------------
 1383|    361|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INTERNAL, "Incorrect length of key");
  ------------------
  |  |  184|     35|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     35|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     35|	int _ret = (r); \
  |  |  |  |  178|     35|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 35, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     35|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     35|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     35|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     35|		goto err; \
  |  |  |  |  182|     35|	} \
  |  |  |  |  183|     35|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1384|    326|	pk.len = BYTES4BITS(pk.len); /* convert number of bits to bytes */
  ------------------
  |  |  146|    326|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 1385|       |
 1386|    326|	if (pk_alg.algorithm == SC_ALGORITHM_EC)   {
  ------------------
  |  |   79|    326|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1386:6): [True: 176, False: 150]
  ------------------
 1387|       |		/* EC public key is not encapsulated into BIT STRING -- it's a BIT STRING */
 1388|       |		/*
 1389|       |		 * sc_pkcs15_fix_ec_parameters below will set field_length from curve.
 1390|       |		 * if no alg_id->params, assume field_length is multiple of 8
 1391|       |		 */
 1392|    176|		pubkey->u.ec.params.field_length = (pk.len - 1) / 2 * 8;
 1393|       |
 1394|    176|		if (pubkey->alg_id->params) {
  ------------------
  |  Branch (1394:7): [True: 174, False: 2]
  ------------------
 1395|    174|			struct sc_ec_parameters *ecp = (struct sc_ec_parameters *)pubkey->alg_id->params;
 1396|       |
 1397|    174|			pubkey->u.ec.params.der.value = malloc(ecp->der.len);
 1398|    174|			if (pubkey->u.ec.params.der.value == NULL) {
  ------------------
  |  Branch (1398:8): [True: 0, False: 174]
  ------------------
 1399|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1400|      0|				LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1401|      0|			}
 1402|       |
 1403|    174|			memcpy(pubkey->u.ec.params.der.value, ecp->der.value, ecp->der.len);
 1404|    174|			pubkey->u.ec.params.der.len = ecp->der.len;
 1405|    174|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1406|    174|			LOG_TEST_GOTO_ERR(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  184|    174|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    174|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    174|	int _ret = (r); \
  |  |  |  |  178|    174|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 22, False: 152]
  |  |  |  |  ------------------
  |  |  |  |  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|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 152]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1407|    174|		}
 1408|       |
 1409|    154|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1410|    154|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1410:7): [True: 0, False: 154]
  ------------------
 1411|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1412|      0|			LOG_TEST_GOTO_ERR(ctx, r, "failed to malloc() memory");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1413|      0|		}
 1414|    154|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1415|    154|		pubkey->u.ec.ecpointQ.len = pk.len;
 1416|    154|	} else if (pk_alg.algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|    300|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1416:13): [True: 0, False: 150]
  ------------------
 1417|    150|		   pk_alg.algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|    150|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1417:6): [True: 0, False: 150]
  ------------------
 1418|       |		/*
 1419|       |		 * SPKI will have OID, EDDSA can have ED25519 or ED448 with different sizes
 1420|       |		 * EDDSA/XEDDSA public key is not encapsulated into BIT STRING -- it's a BIT STRING
 1421|       |		 * no params, but oid is the params.
 1422|       |		 */
 1423|      0|		r = sc_encode_oid(ctx, &pk_alg.oid, &pubkey->u.ec.params.der.value, &pubkey->u.ec.params.der.len);
 1424|      0|		LOG_TEST_GOTO_ERR(ctx, r, "failed to encode (X)EDDSA oid");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|      0|		r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1426|      0|		LOG_TEST_GOTO_ERR(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1427|       |
 1428|      0|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1429|      0|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1429:7): [True: 0, False: 0]
  ------------------
 1430|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1431|      0|			LOG_TEST_GOTO_ERR(ctx, r, "failed to malloc() memory");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1432|      0|		}
 1433|       |
 1434|      0|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1435|      0|		pubkey->u.ec.ecpointQ.len = pk.len;
 1436|    150|	} else {
 1437|       |		/* Public key is expected to be encapsulated into BIT STRING */
 1438|    150|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, pk.value, pk.len);
 1439|    150|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|    150|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    150|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    150|	int _ret = (r); \
  |  |  |  |  178|    150|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 26, False: 124]
  |  |  |  |  ------------------
  |  |  |  |  179|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     26|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     26|		goto err; \
  |  |  |  |  182|     26|	} \
  |  |  |  |  183|    150|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 124]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1440|    150|	}
 1441|       |
 1442|    278|	*outpubkey = pubkey;
 1443|    278|	pubkey = NULL;
 1444|       |
 1445|    478|err:
 1446|    478|	sc_pkcs15_free_pubkey(pubkey);
 1447|    478|	free(pk.value);
 1448|    478|	free(tmp_buf);
 1449|       |
 1450|    478|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    478|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    478|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    478|	int _ret = r; \
  |  |  |  |  155|    478|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 478, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    478|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 313]
  |  |  |  |  ------------------
  |  |  |  |  157|    478|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    478|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    478|	return _ret; \
  |  |  |  |  163|    478|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1451|    478|}
sc_pkcs15_pubkey_from_spki_sequence:
 1457|    131|{
 1458|    131|	struct sc_pkcs15_pubkey * pubkey = NULL;
 1459|    131|	struct sc_asn1_entry asn1_spki[] = {
 1460|    131|			{ "subjectPublicKeyInfo", SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields, &pubkey},
  ------------------
  |  |  181|    131|#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|    131|#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|    131|#define SC_ASN1_CONS			0x20000000
  ------------------
 1461|    131|			{ NULL, 0, 0, 0, NULL, NULL } };
 1462|    131|	int r;
 1463|       |
 1464|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1465|       |
 1466|    131|	r = sc_asn1_decode(ctx, asn1_spki, buf, buflen, NULL, NULL);
 1467|    131|	LOG_TEST_RET(ctx, r, "ASN.1 cannot parse subjectPublicKeyInfo");
  ------------------
  |  |  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: 1, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1468|       |
 1469|    130|	if(outpubkey) {
  ------------------
  |  Branch (1469:5): [True: 130, False: 0]
  ------------------
 1470|    130|		free(*outpubkey);
 1471|    130|		*outpubkey = pubkey;
 1472|    130|	} else
 1473|      0|		free(pubkey);
 1474|       |
 1475|    130|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    130|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    130|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    130|	int _ret = r; \
  |  |  |  |  155|    130|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 130, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    130|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  157|    130|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    130|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    130|	return _ret; \
  |  |  |  |  163|    130|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1476|    130|}
sc_pkcs15_fix_ec_parameters:
 1565|  5.08k|{
 1566|  5.08k|	int rv, ii;
 1567|  5.08k|	int mapped_string = 0; /* der is printable string that can be replaced with der of OID */
 1568|       |
 1569|  5.08k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.08k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.08k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.08k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.08k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1570|       |
 1571|       |	/* In PKCS#11 EC parameters arrives in DER encoded form */
 1572|  5.08k|	if (ecparams->der.value && ecparams->der.len && ecparams->der.len > 2) {
  ------------------
  |  Branch (1572:6): [True: 5.08k, False: 0]
  |  Branch (1572:29): [True: 5.08k, False: 0]
  |  Branch (1572:50): [True: 5.08k, False: 0]
  ------------------
 1573|       |
 1574|  5.08k|		switch (ecparams->der.value[0]) {
 1575|  5.07k|		case 0x06: /* der.value is an OID */
  ------------------
  |  Branch (1575:3): [True: 5.07k, False: 10]
  ------------------
 1576|   123k|			for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1576:17): [True: 123k, False: 12]
  ------------------
 1577|   123k|				size_t len = ec_curve_infos[ii].oid_der.len;
 1578|       |
 1579|   123k|				if (ecparams->der.len == len &&
  ------------------
  |  Branch (1579:9): [True: 12.0k, False: 111k]
  ------------------
 1580|  12.0k|						memcmp(ecparams->der.value, ec_curve_infos[ii].oid_der.value, len) == 0)
  ------------------
  |  Branch (1580:7): [True: 5.06k, False: 6.95k]
  ------------------
 1581|  5.06k|					break; /* found ec_curve_infos[ii] */
 1582|   123k|			}
 1583|  5.07k|			break;
 1584|       |
 1585|      0|		case 0x13:
  ------------------
  |  Branch (1585:3): [True: 0, False: 5.08k]
  ------------------
 1586|       |			/* printable string as per PKCS11 V 3.0 for experimental curves */
 1587|      0|			{
 1588|      0|				int r_tag;
 1589|      0|				const u8 *body = ecparams->der.value;
 1590|      0|				size_t len = ecparams->der.len;
 1591|      0|				unsigned int cla_out, tag_out;
 1592|      0|				size_t bodylen;
 1593|       |
 1594|      0|				r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 1595|      0|				if (r_tag != SC_SUCCESS || tag_out != 0x13) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1595:9): [True: 0, False: 0]
  |  Branch (1595:32): [True: 0, False: 0]
  ------------------
 1596|      0|					sc_log(ctx, "Invalid printable string");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1597|      0|					LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1598|      0|				}
 1599|      0|				for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1599:18): [True: 0, False: 0]
  ------------------
 1600|      0|					size_t len = strlen(ec_curve_infos[ii].name);
 1601|      0|					if (bodylen != len || memcmp(ec_curve_infos[ii].name, body, len) != 0)
  ------------------
  |  Branch (1601:10): [True: 0, False: 0]
  |  Branch (1601:28): [True: 0, False: 0]
  ------------------
 1602|      0|						continue;
 1603|       |					/* found replacement of printable string to OID */
 1604|      0|					mapped_string = 1;
 1605|      0|					break;
 1606|      0|				}
 1607|      0|			}
 1608|      0|			break;
 1609|       |
 1610|     10|		default:
  ------------------
  |  Branch (1610:3): [True: 10, False: 5.07k]
  ------------------
 1611|     10|			sc_log(ctx, "Unsupported ec params");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1612|     10|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1613|  5.08k|		}
 1614|       |
 1615|  5.07k|		if (ec_curve_infos[ii].name == NULL) /* end of ec_curve_info */
  ------------------
  |  Branch (1615:7): [True: 12, False: 5.06k]
  ------------------
 1616|  5.07k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported named curve");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1617|       |
 1618|       |		/* ii points to entry with matching oid_der or a mapped entry with replacement oid_der */
 1619|  5.06k|		sc_log(ctx, "Found known curve '%s'", ec_curve_infos[ii].name);
  ------------------
  |  |   71|  5.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1620|  5.06k|		if (mapped_string) { /* free previous name if any replace below with new name */
  ------------------
  |  Branch (1620:7): [True: 0, False: 5.06k]
  ------------------
 1621|      0|			free(ecparams->named_curve);
 1622|      0|			ecparams->named_curve = NULL;
 1623|      0|		}
 1624|       |
 1625|  5.06k|		if (!ecparams->named_curve) { /* if present,keep the name as some curves have multiple names */
  ------------------
  |  Branch (1625:7): [True: 4.99k, False: 73]
  ------------------
 1626|  4.99k|			ecparams->named_curve = strdup(ec_curve_infos[ii].name);
 1627|  4.99k|			if (!ecparams->named_curve)
  ------------------
  |  Branch (1627:8): [True: 0, False: 4.99k]
  ------------------
 1628|  4.99k|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1629|       |
 1630|  4.99k|			sc_log(ctx, "Curve name: '%s'", ecparams->named_curve);
  ------------------
  |  |   71|  4.99k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1631|  4.99k|		}
 1632|       |
 1633|       |		/* fill in object_id based on oid_der */
 1634|  5.06k|		sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1635|       |
 1636|  5.06k|		ecparams->field_length = ec_curve_infos[ii].size;
 1637|  5.06k|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1638|  5.06k|		sc_log(ctx, "Curve length %" SC_FORMAT_LEN_SIZE_T "u key_type %d",
  ------------------
  |  |   71|  5.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1639|  5.06k|				ecparams->field_length, ecparams->key_type);
 1640|  5.06k|		if (mapped_string) {
  ------------------
  |  Branch (1640:7): [True: 0, False: 5.06k]
  ------------------
 1641|       |			/* replace the printable string version with the oid */
 1642|      0|			if (ecparams->der.value)
  ------------------
  |  Branch (1642:8): [True: 0, False: 0]
  ------------------
 1643|      0|				free(ecparams->der.value);
 1644|      0|			ecparams->der.len = ec_curve_infos[ii].oid_der.len;
 1645|      0|			ecparams->der.value = malloc(ecparams->der.len);
 1646|      0|			if (ecparams->der.value == NULL) {
  ------------------
  |  Branch (1646:8): [True: 0, False: 0]
  ------------------
 1647|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1648|      0|			}
 1649|      0|			memcpy(ecparams->der.value, ec_curve_infos[ii].oid_der.value, ecparams->der.len);
 1650|      0|		}
 1651|  5.06k|	} else if (ecparams->named_curve) { /* it can be name of curve or OID in ASCII form */
  ------------------
  |  Branch (1651:13): [True: 0, False: 0]
  ------------------
 1652|       |		/* caller did not provide an OID, look for a name or oid_string */
 1653|      0|		for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1653:16): [True: 0, False: 0]
  ------------------
 1654|      0|			if (!strcmp(ec_curve_infos[ii].name, ecparams->named_curve))
  ------------------
  |  Branch (1654:8): [True: 0, False: 0]
  ------------------
 1655|      0|				break;
 1656|      0|			if (!strcmp(ec_curve_infos[ii].oid_str, ecparams->named_curve))
  ------------------
  |  Branch (1656:8): [True: 0, False: 0]
  ------------------
 1657|      0|				break;
 1658|      0|		}
 1659|      0|		if (!ec_curve_infos[ii].name) {
  ------------------
  |  Branch (1659:7): [True: 0, False: 0]
  ------------------
 1660|      0|			sc_log(ctx, "Named curve '%s' not supported", ecparams->named_curve);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1661|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|      0|		}
 1663|       |
 1664|      0|		rv = sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1665|      0|		LOG_TEST_RET(ctx, rv, "Invalid OID format");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1666|       |
 1667|      0|		ecparams->field_length = ec_curve_infos[ii].size;
 1668|      0|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1669|      0|		sc_log(ctx, "Curve length %" SC_FORMAT_LEN_SIZE_T "u key_type %d",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1670|      0|				ecparams->field_length, ecparams->key_type);
 1671|       |
 1672|      0|		if (ecparams->der.value == NULL || ecparams->der.len == 0) {
  ------------------
  |  Branch (1672:7): [True: 0, False: 0]
  |  Branch (1672:38): [True: 0, False: 0]
  ------------------
 1673|      0|			free(ecparams->der.value); /* just in case */
 1674|      0|			ecparams->der.value = NULL;
 1675|      0|			ecparams->der.len = 0;
 1676|       |			/* if caller did not provide valid der OID, fill in */
 1677|      0|			rv = sc_encode_oid (ctx, &ecparams->id, &ecparams->der.value, &ecparams->der.len);
 1678|      0|			LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|      0|		}
 1680|      0|	} else
 1681|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "EC parameters has to be presented as a named curve or explicit data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1682|       |
 1683|  5.06k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  5.06k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.06k|	int _ret = r; \
  |  |  |  |  155|  5.06k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5.06k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.06k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.06k|	return _ret; \
  |  |  |  |  163|  5.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1684|  5.06k|}

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

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

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

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

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

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

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

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

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

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

sc_get_version:
   59|  15.0k|{
   60|  15.0k|    return sc_version;
   61|  15.0k|}
sc_hex_to_bin:
   64|   307k|{
   65|   307k|	const char *sc_hex_to_bin_separators = " :";
   66|   307k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (66:6): [True: 0, False: 307k]
  |  Branch (66:20): [True: 0, False: 307k]
  |  Branch (66:35): [True: 0, False: 307k]
  ------------------
   67|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   68|      0|	}
   69|       |
   70|   307k|	int byte_needs_nibble = 0;
   71|   307k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   307k|#define SC_SUCCESS				0
  ------------------
   72|   307k|	size_t left = *outlen;
   73|   307k|	u8 byte = 0;
   74|  5.69M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (74:9): [True: 5.38M, False: 307k]
  |  Branch (74:24): [True: 5.38M, False: 0]
  ------------------
   75|  5.38M|		char c = *in++;
   76|  5.38M|		u8 nibble;
   77|  5.38M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (77:12): [True: 5.38M, False: 0]
  |  Branch (77:24): [True: 2.77M, False: 2.60M]
  ------------------
   78|  2.77M|			nibble = c - '0';
   79|  2.60M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (79:12): [True: 506k, False: 2.10M]
  |  Branch (79:24): [True: 506k, False: 0]
  ------------------
   80|   506k|			nibble = c - 'a' + 10;
   81|  2.10M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (81:12): [True: 714k, False: 1.38M]
  |  Branch (81:24): [True: 714k, False: 0]
  ------------------
   82|   714k|			nibble = c - 'A' + 10;
   83|  1.38M|		else {
   84|  1.38M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (84:8): [True: 1.38M, False: 0]
  ------------------
   85|  1.38M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (85:9): [True: 0, False: 1.38M]
  ------------------
   86|      0|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   87|      0|					goto err;
   88|      0|				}
   89|  1.38M|				continue;
   90|  1.38M|			}
   91|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|      0|			goto err;
   93|  1.38M|		}
   94|       |
   95|  3.99M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (95:7): [True: 1.99M, False: 2.00M]
  ------------------
   96|  1.99M|			byte |= nibble;
   97|  1.99M|			*out++ = (u8) byte;
   98|  1.99M|			left--;
   99|  1.99M|			byte_needs_nibble = 0;
  100|  2.00M|		} else {
  101|  2.00M|			byte  = nibble << 4;
  102|  2.00M|			byte_needs_nibble = 1;
  103|  2.00M|		}
  104|  3.99M|	}
  105|       |
  106|   307k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (106:6): [True: 8.41k, False: 299k]
  |  Branch (106:25): [True: 5.08k, False: 3.32k]
  |  Branch (106:51): [True: 5.08k, False: 0]
  ------------------
  107|       |		/* no output written so far, but we have a valid nibble in the upper
  108|       |		 * bits. Allow this special case. */
  109|  5.08k|		*out = (u8) byte>>4;
  110|  5.08k|		left--;
  111|  5.08k|		byte_needs_nibble = 0;
  112|  5.08k|	}
  113|       |
  114|       |	/* for ease of implementation we only accept completely hexed bytes. */
  115|   307k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (115:6): [True: 0, False: 307k]
  ------------------
  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|   307k|	while (*in != '\0') {
  ------------------
  |  Branch (121:9): [True: 0, False: 307k]
  ------------------
  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|   307k|	if (*in != '\0') {
  ------------------
  |  Branch (126:6): [True: 0, False: 307k]
  ------------------
  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|   307k|err:
  132|   307k|	*outlen -= left;
  133|   307k|	return r;
  134|   307k|}
sc_bin_to_hex:
  138|   311k|{
  139|   311k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (139:6): [True: 0, False: 311k]
  |  Branch (139:20): [True: 0, False: 311k]
  ------------------
  140|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  141|      0|	}
  142|       |
  143|   311k|	if (in_sep > 0) {
  ------------------
  |  Branch (143:6): [True: 308k, False: 3.16k]
  ------------------
  144|   308k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (144:7): [True: 0, False: 308k]
  |  Branch (144:29): [True: 0, False: 308k]
  ------------------
  145|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  146|   308k|	} else {
  147|  3.16k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (147:7): [True: 11, False: 3.15k]
  ------------------
  148|     11|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     11|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  149|  3.16k|	}
  150|       |
  151|   311k|	const char hex[] = "0123456789abcdef";
  152|  3.47M|	while (in_len) {
  ------------------
  |  Branch (152:9): [True: 3.16M, False: 311k]
  ------------------
  153|  3.16M|		unsigned char value = *in++;
  154|  3.16M|		*out++ = hex[(value >> 4) & 0xF];
  155|  3.16M|		*out++ = hex[ value       & 0xF];
  156|  3.16M|		in_len--;
  157|  3.16M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (157:7): [True: 2.96M, False: 195k]
  |  Branch (157:17): [True: 2.95M, False: 14.4k]
  ------------------
  158|  2.95M|			*out++ = (char)in_sep;
  159|  3.16M|	}
  160|   311k|	*out = '\0';
  161|       |
  162|   311k|	return SC_SUCCESS;
  ------------------
  |  |   28|   311k|#define SC_SUCCESS				0
  ------------------
  163|   311k|}
ulong2bebytes:
  189|  75.5k|{
  190|  75.5k|	if (buf != NULL) {
  ------------------
  |  Branch (190:6): [True: 75.5k, False: 0]
  ------------------
  191|  75.5k|		buf[3] = (u8) (x & 0xff);
  192|  75.5k|		buf[2] = (u8) ((x >> 8) & 0xff);
  193|  75.5k|		buf[1] = (u8) ((x >> 16) & 0xff);
  194|  75.5k|		buf[0] = (u8) ((x >> 24) & 0xff);
  195|  75.5k|	}
  196|  75.5k|	return buf;
  197|  75.5k|}
bebytes2ulong:
  209|   167k|{
  210|   167k|	if (buf == NULL)
  ------------------
  |  Branch (210:6): [True: 0, False: 167k]
  ------------------
  211|      0|		return 0UL;
  212|   167k|	return (unsigned long)buf[0] << 24
  213|   167k|		| (unsigned long)buf[1] << 16
  214|   167k|		| (unsigned long)buf[2] << 8
  215|   167k|		| (unsigned long)buf[3];
  216|   167k|}
bebytes2ushort:
  219|   214k|{
  220|   214k|	if (buf == NULL)
  ------------------
  |  Branch (220:6): [True: 0, False: 214k]
  ------------------
  221|      0|		return 0U;
  222|   214k|	return (unsigned short)buf[0] << 8
  223|   214k|		| (unsigned short)buf[1];
  224|   214k|}
lebytes2ushort:
  227|  10.0k|{
  228|  10.0k|	if (buf == NULL)
  ------------------
  |  Branch (228:6): [True: 0, False: 10.0k]
  ------------------
  229|      0|		return 0U;
  230|  10.0k|	return (unsigned short)buf[1] << 8
  231|  10.0k|		| (unsigned short)buf[0];
  232|  10.0k|}
lebytes2ulong:
  235|    602|{
  236|    602|	if (buf == NULL)
  ------------------
  |  Branch (236:6): [True: 0, False: 602]
  ------------------
  237|      0|		return 0UL;
  238|    602|	return (unsigned long)buf[3] << 24
  239|    602|		| (unsigned long)buf[2] << 16
  240|    602|		| (unsigned long)buf[1] << 8
  241|    602|		| (unsigned long)buf[0];
  242|    602|}
set_string:
  245|  12.8k|{
  246|  12.8k|	if (strp == NULL) {
  ------------------
  |  Branch (246:6): [True: 0, False: 12.8k]
  ------------------
  247|      0|		return;
  248|      0|	}
  249|       |
  250|  12.8k|	free(*strp);
  251|  12.8k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (251:10): [True: 12.8k, False: 0]
  ------------------
  252|  12.8k|}
sc_init_oid:
  255|  49.4k|{
  256|  49.4k|	int ii;
  257|       |
  258|  49.4k|	if (!oid)
  ------------------
  |  Branch (258:6): [True: 0, False: 49.4k]
  ------------------
  259|      0|		return;
  260|   840k|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|   840k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (260:13): [True: 791k, False: 49.4k]
  ------------------
  261|   791k|		oid->value[ii] = -1;
  262|  49.4k|}
sc_format_oid:
  265|  16.1k|{
  266|  16.1k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  16.1k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  267|  16.1k|	const char *p;
  268|  16.1k|	char       *q;
  269|       |
  270|  16.1k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (270:6): [True: 0, False: 16.1k]
  |  Branch (270:21): [True: 0, False: 16.1k]
  ------------------
  271|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  272|       |
  273|  16.1k|	sc_init_oid(oid);
  274|       |
  275|  16.1k|	p = in;
  276|   135k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   135k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (276:13): [True: 135k, False: 0]
  ------------------
  277|   135k|		oid->value[ii] = (int)strtol(p, &q, 10);
  278|   135k|		if (!*q)
  ------------------
  |  Branch (278:7): [True: 16.1k, False: 119k]
  ------------------
  279|  16.1k|			break;
  280|       |
  281|   119k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (281:9): [True: 119k, False: 0]
  |  Branch (281:24): [True: 119k, False: 0]
  ------------------
  282|      0|			goto out;
  283|       |
  284|   119k|		p = q + 1;
  285|   119k|	}
  286|       |
  287|  16.1k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (287:6): [True: 0, False: 16.1k]
  ------------------
  288|      0|		goto out;
  289|       |
  290|  16.1k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  291|  16.1k|out:
  292|  16.1k|	if (ret)
  ------------------
  |  Branch (292:6): [True: 0, False: 16.1k]
  ------------------
  293|      0|		sc_init_oid(oid);
  294|       |
  295|  16.1k|	return ret;
  296|  16.1k|}
sc_compare_oid:
  299|  33.8k|{
  300|  33.8k|	int i;
  301|       |
  302|  33.8k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (302:6): [True: 0, False: 33.8k]
  |  Branch (302:22): [True: 0, False: 33.8k]
  ------------------
  303|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  304|      0|	}
  305|       |
  306|   100k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|   100k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (306:14): [True: 100k, False: 0]
  ------------------
  307|   100k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (307:7): [True: 27.9k, False: 72.1k]
  ------------------
  308|  27.9k|			return 0;
  309|  72.1k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (309:7): [True: 5.85k, False: 66.3k]
  ------------------
  310|  5.85k|			break;
  311|  72.1k|	}
  312|       |
  313|  5.85k|	return 1;
  314|  33.8k|}
sc_valid_oid:
  318|  33.8k|{
  319|  33.8k|	int ii;
  320|       |
  321|  33.8k|	if (!oid)
  ------------------
  |  Branch (321:6): [True: 0, False: 33.8k]
  ------------------
  322|      0|		return 0;
  323|  33.8k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (323:6): [True: 20, False: 33.8k]
  |  Branch (323:29): [True: 0, False: 33.8k]
  ------------------
  324|     20|		return 0;
  325|  33.8k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (325:6): [True: 0, False: 33.8k]
  |  Branch (325:27): [True: 5, False: 33.8k]
  ------------------
  326|      5|		return 0;
  327|   142k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|   142k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (327:12): [True: 135k, False: 6.79k]
  ------------------
  328|   135k|		if (oid->value[ii])
  ------------------
  |  Branch (328:7): [True: 27.0k, False: 108k]
  ------------------
  329|  27.0k|			break;
  330|  33.8k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  33.8k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (330:6): [True: 6.79k, False: 27.0k]
  ------------------
  331|  6.79k|		return 0;
  332|  27.0k|	return 1;
  333|  33.8k|}
sc_path_set:
  355|  22.3k|{
  356|  22.3k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  22.3k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (356:6): [True: 0, False: 22.3k]
  |  Branch (356:22): [True: 0, False: 22.3k]
  |  Branch (356:36): [True: 0, False: 22.3k]
  |  Branch (356:51): [True: 0, False: 22.3k]
  ------------------
  357|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  358|       |
  359|  22.3k|	memset(path, 0, sizeof(*path));
  360|  22.3k|	memcpy(path->value, id, id_len);
  361|  22.3k|	path->len   = id_len;
  362|  22.3k|	path->type  = type;
  363|  22.3k|	path->index = idx;
  364|  22.3k|	path->count = count;
  365|       |
  366|  22.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  22.3k|#define SC_SUCCESS				0
  ------------------
  367|  22.3k|}
sc_format_path:
  370|   137k|{
  371|   137k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   137k|#define SC_PATH_TYPE_PATH		2
  ------------------
  372|       |
  373|   137k|	if (path) {
  ------------------
  |  Branch (373:6): [True: 137k, False: 0]
  ------------------
  374|   137k|		memset(path, 0, sizeof(*path));
  375|   137k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (375:7): [True: 0, False: 137k]
  |  Branch (375:22): [True: 0, False: 137k]
  ------------------
  376|      0|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  377|      0|			str++;
  378|      0|		}
  379|   137k|		path->len = sizeof(path->value);
  380|   137k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (380:7): [True: 137k, False: 0]
  ------------------
  381|   137k|			path->type = type;
  382|   137k|		}
  383|   137k|		path->count = -1;
  384|   137k|	}
  385|   137k|}
sc_append_path_id:
  393|  39.3k|{
  394|  39.3k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  39.3k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (394:6): [True: 0, False: 39.3k]
  ------------------
  395|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  396|  39.3k|	memcpy(dest->value + dest->len, id, idlen);
  397|  39.3k|	dest->len += idlen;
  398|  39.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  39.3k|#define SC_SUCCESS				0
  ------------------
  399|  39.3k|}
sc_append_file_id:
  402|  39.3k|{
  403|  39.3k|	u8 id[2] = { fid >> 8, fid & 0xff };
  404|       |
  405|  39.3k|	return sc_append_path_id(dest, id, 2);
  406|  39.3k|}
sc_concatenate_path:
  409|  17.5k|{
  410|  17.5k|	sc_path_t tpath;
  411|       |
  412|  17.5k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (412:6): [True: 0, False: 17.5k]
  |  Branch (412:19): [True: 0, False: 17.5k]
  |  Branch (412:33): [True: 0, False: 17.5k]
  ------------------
  413|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  414|       |
  415|  17.5k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  35.1k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  17.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (415:6): [True: 0, False: 17.5k]
  |  Branch (415:42): [True: 0, False: 17.5k]
  ------------------
  416|       |		/* we do not support concatenation of AIDs at the moment */
  417|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  418|       |
  419|  17.5k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  17.5k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (419:6): [True: 5, False: 17.5k]
  ------------------
  420|      5|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      5|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  421|       |
  422|  17.5k|	memset(&tpath, 0, sizeof(sc_path_t));
  423|  17.5k|	memcpy(tpath.value, p1->value, p1->len);
  424|  17.5k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  425|  17.5k|	tpath.len  = p1->len + p2->len;
  426|  17.5k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  17.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  427|       |	/* use 'index' and 'count' entry of the second path object */
  428|  17.5k|	tpath.index = p2->index;
  429|  17.5k|	tpath.count = p2->count;
  430|       |	/* the result is currently always as path */
  431|  17.5k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  17.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  432|       |
  433|  17.5k|	*d = tpath;
  434|       |
  435|  17.5k|	return SC_SUCCESS;
  ------------------
  |  |   28|  17.5k|#define SC_SUCCESS				0
  ------------------
  436|  17.5k|}
sc_print_path:
  439|   224k|{
  440|   224k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  441|       |
  442|   224k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   224k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 0, False: 224k]
  ------------------
  443|      0|		buffer[0] = '\0';
  444|       |
  445|   224k|	return buffer;
  446|   224k|}
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: 67, False: 314k]
  ------------------
  456|     67|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     67|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  457|       |
  458|   314k|	buf[0] = '\0';
  459|   314k|	if (path->aid.len)   {
  ------------------
  |  Branch (459:6): [True: 132k, False: 181k]
  ------------------
  460|  1.05M|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (460:15): [True: 926k, False: 132k]
  ------------------
  461|   926k|			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.27M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (465:14): [True: 958k, False: 314k]
  ------------------
  466|   958k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  467|   314k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   181k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (467:6): [True: 181k, False: 132k]
  |  Branch (467:24): [True: 26.7k, False: 154k]
  ------------------
  468|  26.7k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  469|       |
  470|   314k|	return SC_SUCCESS;
  ------------------
  |  |   28|   314k|#define SC_SUCCESS				0
  ------------------
  471|   314k|}
sc_compare_path:
  474|  24.0k|{
  475|  24.0k|	return path1->len == path2->len
  ------------------
  |  Branch (475:9): [True: 23.3k, False: 683]
  ------------------
  476|  23.3k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (476:6): [True: 6.33k, False: 17.0k]
  ------------------
  477|  24.0k|}
sc_compare_path_prefix:
  480|  17.2k|{
  481|  17.2k|	sc_path_t tpath;
  482|       |
  483|  17.2k|	if (prefix->len > path->len)
  ------------------
  |  Branch (483:6): [True: 70, False: 17.1k]
  ------------------
  484|     70|		return 0;
  485|       |
  486|  17.1k|	tpath     = *path;
  487|  17.1k|	tpath.len = prefix->len;
  488|       |
  489|  17.1k|	return sc_compare_path(&tpath, prefix);
  490|  17.2k|}
sc_get_mf_path:
  493|  21.2k|{
  494|  21.2k|	static const sc_path_t mf_path = {
  495|  21.2k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  496|  21.2k|		0,
  497|  21.2k|		0,
  498|  21.2k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  21.2k|#define SC_PATH_TYPE_PATH		2
  ------------------
  499|  21.2k|		{{0},0}
  500|  21.2k|	};
  501|  21.2k|	return &mf_path;
  502|  21.2k|}
sc_file_add_acl_entry:
  506|   149k|{
  507|   149k|	sc_acl_entry_t *p, *_new;
  508|       |
  509|   149k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   149k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (509:6): [True: 0, False: 149k]
  |  Branch (509:22): [True: 0, False: 149k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|      0|	}
  512|       |
  513|   149k|	switch (method) {
  514|  41.8k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  41.8k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (514:2): [True: 41.8k, False: 107k]
  ------------------
  515|  41.8k|		sc_file_clear_acl_entries(file, operation);
  516|  41.8k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  517|  41.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  41.8k|#define SC_SUCCESS				0
  ------------------
  518|  7.87k|	case SC_AC_NONE:
  ------------------
  |  |  150|  7.87k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (518:2): [True: 7.87k, False: 141k]
  ------------------
  519|  7.87k|		sc_file_clear_acl_entries(file, operation);
  520|  7.87k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  521|  7.87k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.87k|#define SC_SUCCESS				0
  ------------------
  522|  2.02k|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|  2.02k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (522:2): [True: 2.02k, False: 147k]
  ------------------
  523|  2.02k|		sc_file_clear_acl_entries(file, operation);
  524|  2.02k|		file->acl[operation] = (sc_acl_entry_t *) 3;
  525|  2.02k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.02k|#define SC_SUCCESS				0
  ------------------
  526|  97.7k|	default:
  ------------------
  |  Branch (526:2): [True: 97.7k, False: 51.7k]
  ------------------
  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|  97.7k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (530:7): [True: 10, False: 97.7k]
  ------------------
  531|     10|			return SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  532|  97.7k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (532:7): [True: 1.61k, False: 96.0k]
  ------------------
  533|  96.0k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (533:7): [True: 7, False: 96.0k]
  ------------------
  534|  1.62k|			file->acl[operation] = NULL;
  535|   149k|	}
  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|   134k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (539:33): [True: 39.1k, False: 94.9k]
  ------------------
  540|  39.1k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (540:7): [True: 36.6k, False: 2.48k]
  |  Branch (540:32): [True: 2.77k, False: 33.8k]
  ------------------
  541|  2.77k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.77k|#define SC_SUCCESS				0
  ------------------
  542|  39.1k|	}
  543|       |
  544|  94.9k|	_new = malloc(sizeof(sc_acl_entry_t));
  545|  94.9k|	if (_new == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 94.9k]
  ------------------
  546|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  547|  94.9k|	_new->method = method;
  548|  94.9k|	_new->key_ref = (unsigned)key_ref;
  549|  94.9k|	_new->next = NULL;
  550|       |
  551|  94.9k|	p = file->acl[operation];
  552|  94.9k|	if (p == NULL) {
  ------------------
  |  Branch (552:6): [True: 87.0k, False: 7.84k]
  ------------------
  553|  87.0k|		file->acl[operation] = _new;
  554|  87.0k|		return SC_SUCCESS;
  ------------------
  |  |   28|  87.0k|#define SC_SUCCESS				0
  ------------------
  555|  87.0k|	}
  556|  34.3k|	while (p->next != NULL)
  ------------------
  |  Branch (556:9): [True: 26.5k, False: 7.84k]
  ------------------
  557|  26.5k|		p = p->next;
  558|  7.84k|	p->next = _new;
  559|       |
  560|  7.84k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.84k|#define SC_SUCCESS				0
  ------------------
  561|  94.9k|}
sc_file_get_acl_entry:
  565|   227k|{
  566|   227k|	sc_acl_entry_t *p;
  567|   227k|	static const sc_acl_entry_t e_never = {
  568|   227k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   227k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   227k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  569|   227k|	};
  570|   227k|	static const sc_acl_entry_t e_none = {
  571|   227k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   227k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   227k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  572|   227k|	};
  573|   227k|	static const sc_acl_entry_t e_unknown = {
  574|   227k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   227k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   227k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  575|   227k|	};
  576|       |
  577|   227k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   227k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (577:6): [True: 0, False: 227k]
  |  Branch (577:22): [True: 0, False: 227k]
  ------------------
  578|      0|		return NULL;
  579|      0|	}
  580|       |
  581|   227k|	p = file->acl[operation];
  582|   227k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (582:6): [True: 1.23k, False: 225k]
  ------------------
  583|  1.23k|		return &e_never;
  584|   225k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (584:6): [True: 1.14k, False: 224k]
  ------------------
  585|  1.14k|		return &e_none;
  586|   224k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (586:6): [True: 851, False: 223k]
  ------------------
  587|    851|		return &e_unknown;
  588|       |
  589|   223k|	return file->acl[operation];
  590|   224k|}
sc_file_clear_acl_entries:
  593|  2.60M|{
  594|  2.60M|	sc_acl_entry_t *e;
  595|       |
  596|  2.60M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  2.60M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (596:6): [True: 0, False: 2.60M]
  |  Branch (596:22): [True: 0, False: 2.60M]
  ------------------
  597|      0|		return;
  598|      0|	}
  599|       |
  600|  2.60M|	e = file->acl[operation];
  601|  2.60M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (601:6): [True: 41.6k, False: 2.56M]
  ------------------
  602|  2.56M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (602:6): [True: 6.16k, False: 2.56M]
  ------------------
  603|  2.56M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (603:6): [True: 2.01k, False: 2.55M]
  ------------------
  604|  49.8k|		file->acl[operation] = NULL;
  605|  49.8k|		return;
  606|  49.8k|	}
  607|       |
  608|  2.65M|	while (e != NULL) {
  ------------------
  |  Branch (608:9): [True: 94.9k, False: 2.55M]
  ------------------
  609|  94.9k|		sc_acl_entry_t *tmp = e->next;
  610|  94.9k|		free(e);
  611|  94.9k|		e = tmp;
  612|  94.9k|	}
  613|       |	file->acl[operation] = NULL;
  614|  2.55M|}
sc_file_new:
  617|  82.5k|{
  618|  82.5k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  619|  82.5k|	if (file == NULL)
  ------------------
  |  Branch (619:6): [True: 0, False: 82.5k]
  ------------------
  620|      0|		return NULL;
  621|       |
  622|  82.5k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  82.5k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  623|  82.5k|	return file;
  624|  82.5k|}
sc_file_free:
  627|   235k|{
  628|   235k|	unsigned int i;
  629|   235k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (629:6): [True: 152k, False: 82.4k]
  |  Branch (629:22): [True: 0, False: 82.4k]
  ------------------
  630|   152k|		return;
  631|  82.4k|	file->magic = 0;
  632|  2.63M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  2.63M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (632:14): [True: 2.55M, False: 82.4k]
  ------------------
  633|  2.55M|		sc_file_clear_acl_entries(file, i);
  634|  82.4k|	if (file->sec_attr)
  ------------------
  |  Branch (634:6): [True: 848, False: 81.6k]
  ------------------
  635|    848|		free(file->sec_attr);
  636|  82.4k|	if (file->prop_attr)
  ------------------
  |  Branch (636:6): [True: 623, False: 81.8k]
  ------------------
  637|    623|		free(file->prop_attr);
  638|  82.4k|	if (file->type_attr)
  ------------------
  |  Branch (638:6): [True: 3.71k, False: 78.7k]
  ------------------
  639|  3.71k|		free(file->type_attr);
  640|  82.4k|	if (file->encoded_content)
  ------------------
  |  Branch (640:6): [True: 0, False: 82.4k]
  ------------------
  641|      0|		free(file->encoded_content);
  642|  82.4k|	free(file);
  643|  82.4k|}
sc_file_dup:
  646|  7.31k|{
  647|  7.31k|	sc_file_t *newf;
  648|  7.31k|	const sc_acl_entry_t *e;
  649|  7.31k|	unsigned int op;
  650|       |
  651|  7.31k|	*dest = NULL;
  652|  7.31k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (652:6): [True: 0, False: 7.31k]
  ------------------
  653|      0|		return;
  654|  7.31k|	newf = sc_file_new();
  655|  7.31k|	if (newf == NULL)
  ------------------
  |  Branch (655:6): [True: 0, False: 7.31k]
  ------------------
  656|      0|		return;
  657|  7.31k|	*dest = newf;
  658|       |
  659|  7.31k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  660|  7.31k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  661|  7.31k|	newf->namelen = src->namelen;
  662|  7.31k|	newf->type    = src->type;
  663|  7.31k|	newf->shareable    = src->shareable;
  664|  7.31k|	newf->ef_structure = src->ef_structure;
  665|  7.31k|	newf->size    = src->size;
  666|  7.31k|	newf->id      = src->id;
  667|  7.31k|	newf->status  = src->status;
  668|   234k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   234k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (668:15): [True: 226k, False: 7.31k]
  ------------------
  669|   226k|		newf->acl[op] = NULL;
  670|   226k|		e = sc_file_get_acl_entry(src, op);
  671|   226k|		if (e != NULL) {
  ------------------
  |  Branch (671:7): [True: 4.90k, False: 221k]
  ------------------
  672|  4.90k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (672:8): [True: 0, False: 4.90k]
  ------------------
  673|      0|				goto err;
  674|  4.90k|		}
  675|   226k|	}
  676|  7.31k|	newf->record_length = src->record_length;
  677|  7.31k|	newf->record_count  = src->record_count;
  678|       |
  679|  7.31k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (679:6): [True: 0, False: 7.31k]
  ------------------
  680|      0|		goto err;
  681|  7.31k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (681:6): [True: 0, False: 7.31k]
  ------------------
  682|      0|		goto err;
  683|  7.31k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (683:6): [True: 0, False: 7.31k]
  ------------------
  684|      0|		goto err;
  685|  7.31k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (685:6): [True: 0, False: 7.31k]
  ------------------
  686|      0|		goto err;
  687|  7.31k|	return;
  688|  7.31k|err:
  689|      0|	sc_file_free(newf);
  690|       |	*dest = NULL;
  691|      0|}
sc_file_set_sec_attr:
  695|  8.53k|{
  696|  8.53k|	u8 *tmp;
  697|  8.53k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (697:6): [True: 0, False: 8.53k]
  ------------------
  698|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  699|      0|	}
  700|       |
  701|  8.53k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (701:6): [True: 7.30k, False: 1.23k]
  |  Branch (701:26): [True: 309, False: 923]
  ------------------
  702|  7.61k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (702:7): [True: 66, False: 7.54k]
  ------------------
  703|     66|			free(file->sec_attr);
  704|  7.61k|		file->sec_attr = NULL;
  705|  7.61k|		file->sec_attr_len = 0;
  706|  7.61k|		return 0;
  707|  7.61k|	 }
  708|    923|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  709|    923|	if (!tmp) {
  ------------------
  |  Branch (709:6): [True: 0, False: 923]
  ------------------
  710|      0|		if (file->sec_attr)
  ------------------
  |  Branch (710:7): [True: 0, False: 0]
  ------------------
  711|      0|			free(file->sec_attr);
  712|      0|		file->sec_attr     = NULL;
  713|      0|		file->sec_attr_len = 0;
  714|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  715|      0|	}
  716|    923|	file->sec_attr = tmp;
  717|    923|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  718|    923|	file->sec_attr_len = sec_attr_len;
  719|       |
  720|    923|	return 0;
  721|    923|}
sc_file_set_prop_attr:
  725|  8.71k|{
  726|  8.71k|	u8 *tmp;
  727|  8.71k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (727:6): [True: 0, False: 8.71k]
  ------------------
  728|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  729|      0|	}
  730|       |
  731|  8.71k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (731:6): [True: 7.29k, False: 1.41k]
  |  Branch (731:27): [True: 665, False: 749]
  ------------------
  732|  7.96k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (732:7): [True: 66, False: 7.89k]
  ------------------
  733|     66|			free(file->prop_attr);
  734|  7.96k|		file->prop_attr = NULL;
  735|  7.96k|		file->prop_attr_len = 0;
  736|  7.96k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.96k|#define SC_SUCCESS				0
  ------------------
  737|  7.96k|	 }
  738|    749|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  739|    749|	if (!tmp) {
  ------------------
  |  Branch (739:6): [True: 0, False: 749]
  ------------------
  740|      0|		if (file->prop_attr)
  ------------------
  |  Branch (740:7): [True: 0, False: 0]
  ------------------
  741|      0|			free(file->prop_attr);
  742|      0|		file->prop_attr = NULL;
  743|      0|		file->prop_attr_len = 0;
  744|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  745|      0|	}
  746|    749|	file->prop_attr = tmp;
  747|    749|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  748|    749|	file->prop_attr_len = prop_attr_len;
  749|       |
  750|    749|	return SC_SUCCESS;
  ------------------
  |  |   28|    749|#define SC_SUCCESS				0
  ------------------
  751|    749|}
sc_file_set_type_attr:
  755|  10.3k|{
  756|  10.3k|	u8 *tmp;
  757|  10.3k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (757:6): [True: 0, False: 10.3k]
  ------------------
  758|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  759|      0|	}
  760|       |
  761|  10.3k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (761:6): [True: 6.20k, False: 4.17k]
  |  Branch (761:27): [True: 0, False: 4.17k]
  ------------------
  762|  6.20k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (762:7): [True: 0, False: 6.20k]
  ------------------
  763|      0|			free(file->type_attr);
  764|  6.20k|		file->type_attr = NULL;
  765|  6.20k|		file->type_attr_len = 0;
  766|  6.20k|		return SC_SUCCESS;
  ------------------
  |  |   28|  6.20k|#define SC_SUCCESS				0
  ------------------
  767|  6.20k|	 }
  768|  4.17k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  769|  4.17k|	if (!tmp) {
  ------------------
  |  Branch (769:6): [True: 0, False: 4.17k]
  ------------------
  770|      0|		if (file->type_attr)
  ------------------
  |  Branch (770:7): [True: 0, False: 0]
  ------------------
  771|      0|			free(file->type_attr);
  772|      0|		file->type_attr = NULL;
  773|      0|		file->type_attr_len = 0;
  774|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  775|      0|	}
  776|  4.17k|	file->type_attr = tmp;
  777|  4.17k|	memcpy(file->type_attr, type_attr, type_attr_len);
  778|  4.17k|	file->type_attr_len = type_attr_len;
  779|       |
  780|  4.17k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.17k|#define SC_SUCCESS				0
  ------------------
  781|  4.17k|}
sc_file_set_content:
  786|  7.31k|{
  787|  7.31k|	u8 *tmp;
  788|  7.31k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (788:6): [True: 0, False: 7.31k]
  ------------------
  789|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  790|      0|	}
  791|       |
  792|  7.31k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (792:6): [True: 7.31k, False: 0]
  |  Branch (792:25): [True: 0, False: 0]
  ------------------
  793|  7.31k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (793:7): [True: 0, False: 7.31k]
  ------------------
  794|      0|			free(file->encoded_content);
  795|  7.31k|		file->encoded_content = NULL;
  796|  7.31k|		file->encoded_content_len = 0;
  797|  7.31k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.31k|#define SC_SUCCESS				0
  ------------------
  798|  7.31k|	}
  799|       |
  800|      0|	tmp = (u8 *) realloc(file->encoded_content, content_len);
  801|      0|	if (!tmp) {
  ------------------
  |  Branch (801:6): [True: 0, False: 0]
  ------------------
  802|      0|		if (file->encoded_content)
  ------------------
  |  Branch (802:7): [True: 0, False: 0]
  ------------------
  803|      0|			free(file->encoded_content);
  804|      0|		file->encoded_content = NULL;
  805|      0|		file->encoded_content_len = 0;
  806|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  807|      0|	}
  808|       |
  809|      0|	file->encoded_content = tmp;
  810|      0|	memcpy(file->encoded_content, content, content_len);
  811|      0|	file->encoded_content_len = content_len;
  812|       |
  813|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  814|      0|}
sc_file_valid:
  817|   124k|int sc_file_valid(const sc_file_t *file) {
  818|   124k|	if (file == NULL)
  ------------------
  |  Branch (818:6): [True: 0, False: 124k]
  ------------------
  819|      0|		return 0;
  820|   124k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   57|   124k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  821|   124k|}
_sc_parse_atr:
  824|  15.0k|{
  825|  15.0k|	u8 *p = reader->atr.value;
  826|  15.0k|	int atr_len = (int) reader->atr.len;
  827|  15.0k|	int n_hist, x;
  828|  15.0k|	int tx[4] = {-1, -1, -1, -1};
  829|  15.0k|	int i, FI, DI;
  830|  15.0k|	const int Fi_table[] = {
  831|  15.0k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  832|  15.0k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  833|  15.0k|	const int f_table[] = {
  834|  15.0k|		40, 50, 60, 80, 120, 160, 200, -1,
  835|  15.0k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  836|  15.0k|	const int Di_table[] = {
  837|  15.0k|		-1, 1, 2, 4, 8, 16, 32, -1,
  838|  15.0k|		12, 20, -1, -1, -1, -1, -1, -1 };
  839|       |
  840|  15.0k|	reader->atr_info.hist_bytes_len = 0;
  841|  15.0k|	reader->atr_info.hist_bytes = NULL;
  842|       |
  843|  15.0k|	if (atr_len == 0) {
  ------------------
  |  Branch (843:6): [True: 3.78k, False: 11.2k]
  ------------------
  844|  3.78k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  3.78k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  845|  3.78k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.78k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  846|  3.78k|	}
  847|       |
  848|  11.2k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (848:6): [True: 1.28k, False: 9.94k]
  |  Branch (848:22): [True: 1.26k, False: 20]
  ------------------
  849|  1.26k|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   71|  1.26k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  850|  1.26k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.26k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  851|  1.26k|	}
  852|  9.96k|	n_hist = p[1] & 0x0F;
  853|  9.96k|	x = p[1] >> 4;
  854|  9.96k|	p += 2;
  855|  9.96k|	atr_len -= 2;
  856|  49.7k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (856:14): [True: 39.8k, False: 9.93k]
  |  Branch (856:23): [True: 39.7k, False: 26]
  ------------------
  857|  39.7k|                if (x & (1 << i)) {
  ------------------
  |  Branch (857:21): [True: 26.8k, False: 12.9k]
  ------------------
  858|  26.8k|                        tx[i] = *p;
  859|  26.8k|                        p++;
  860|  26.8k|                        atr_len--;
  861|  26.8k|                } else
  862|  12.9k|                        tx[i] = -1;
  863|  39.7k|        }
  864|  9.96k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (864:6): [True: 8.72k, False: 1.23k]
  ------------------
  865|  8.72k|		reader->atr_info.FI = FI = tx[0] >> 4;
  866|  8.72k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  867|  8.72k|		reader->atr_info.Fi = Fi_table[FI];
  868|  8.72k|		reader->atr_info.f = f_table[FI];
  869|  8.72k|		reader->atr_info.Di = Di_table[DI];
  870|  8.72k|	} else {
  871|  1.23k|		reader->atr_info.Fi = -1;
  872|  1.23k|		reader->atr_info.f = -1;
  873|  1.23k|		reader->atr_info.Di = -1;
  874|  1.23k|	}
  875|  9.96k|	if (tx[2] >= 0)
  ------------------
  |  Branch (875:6): [True: 6.35k, False: 3.60k]
  ------------------
  876|  6.35k|		reader->atr_info.N = tx[3];
  877|  3.60k|	else
  878|  3.60k|		reader->atr_info.N = -1;
  879|  22.5k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (879:9): [True: 13.1k, False: 9.39k]
  |  Branch (879:22): [True: 12.6k, False: 519]
  |  Branch (879:38): [True: 12.6k, False: 48]
  ------------------
  880|  12.6k|		x = tx[3] >> 4;
  881|  63.0k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (881:15): [True: 50.4k, False: 12.5k]
  |  Branch (881:24): [True: 50.4k, False: 26]
  ------------------
  882|  50.4k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (882:22): [True: 19.0k, False: 31.3k]
  ------------------
  883|  19.0k|	                        tx[i] = *p;
  884|  19.0k|	                        p++;
  885|  19.0k|	                        atr_len--;
  886|  19.0k|	                } else
  887|  31.3k|	                        tx[i] = -1;
  888|  50.4k|		}
  889|  12.6k|	}
  890|  9.96k|	if (atr_len <= 0)
  ------------------
  |  Branch (890:6): [True: 112, False: 9.84k]
  ------------------
  891|    112|		return SC_SUCCESS;
  ------------------
  |  |   28|    112|#define SC_SUCCESS				0
  ------------------
  892|  9.84k|	if (n_hist > atr_len)
  ------------------
  |  Branch (892:6): [True: 959, False: 8.89k]
  ------------------
  893|    959|		n_hist = atr_len;
  894|  9.84k|	reader->atr_info.hist_bytes_len = n_hist;
  895|  9.84k|	reader->atr_info.hist_bytes = p;
  896|  9.84k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.84k|#define SC_SUCCESS				0
  ------------------
  897|  9.96k|}
sc_mem_secure_alloc:
  900|      8|{
  901|      8|	void *p;
  902|       |
  903|       |#ifdef _WIN32
  904|       |	p = VirtualAlloc(NULL, len, MEM_COMMIT, PAGE_READWRITE);
  905|       |	if (p != NULL) {
  906|       |		VirtualLock(p, len);
  907|       |	}
  908|       |#else
  909|      8|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  910|      8|	if (p != NULL) {
  ------------------
  |  Branch (910:6): [True: 8, False: 0]
  ------------------
  911|      8|		mlock(p, len);
  912|      8|	}
  913|      8|#endif
  914|       |
  915|      8|	return p;
  916|      8|}
sc_mem_secure_free:
  919|      8|{
  920|       |#ifdef _WIN32
  921|       |	VirtualUnlock(ptr, len);
  922|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  923|       |#else
  924|      8|	munlock(ptr, len);
  925|      8|	munmap(ptr, len);
  926|      8|#endif
  927|      8|}
sc_mem_clear:
  930|  60.1k|{
  931|  60.1k|	if (len > 0)   {
  ------------------
  |  Branch (931:6): [True: 60.1k, False: 0]
  ------------------
  932|       |#ifdef HAVE_MEMSET_S
  933|       |		memset_s(ptr, len, 0, len);
  934|       |#elif _WIN32
  935|       |		SecureZeroMemory(ptr, len);
  936|       |#elif HAVE_EXPLICIT_BZERO
  937|       |		explicit_bzero(ptr, len);
  938|       |#elif ENABLE_OPENSSL
  939|       |		OPENSSL_cleanse(ptr, len);
  940|       |#else
  941|       |		memset(ptr, 0, len);
  942|       |#endif
  943|  60.1k|	}
  944|  60.1k|}
sc_compacttlv_find_tag:
 1058|    738|{
 1059|    738|	if (buf != NULL) {
  ------------------
  |  Branch (1059:6): [True: 738, False: 0]
  ------------------
 1060|    738|		size_t idx;
 1061|    738|		u8 plain_tag = tag & 0xF0;
 1062|    738|		size_t expected_len = tag & 0x0F;
 1063|       |
 1064|  10.1k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1064:17): [True: 9.61k, False: 560]
  ------------------
 1065|  9.61k|			u8 ctag = buf[idx] & 0xF0;
 1066|  9.61k|			size_t ctag_len = buf[idx] & 0x0F;
 1067|  9.61k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1067:8): [True: 793, False: 8.82k]
  |  Branch (1067:29): [True: 775, False: 18]
  ------------------
 1068|    775|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1068:7): [True: 127, False: 648]
  |  Branch (1068:28): [True: 51, False: 597]
  ------------------
 1069|    178|				if (outlen != NULL)
  ------------------
  |  Branch (1069:9): [True: 127, False: 51]
  ------------------
 1070|    127|					*outlen = ctag_len;
 1071|    178|				return buf + (idx + 1);
 1072|    178|			}
 1073|  9.44k|			idx += ctag_len;
 1074|  9.44k|		}
 1075|    738|	}
 1076|    560|	return NULL;
 1077|    738|}
sc_mutex_create:
 1082|  30.0k|{
 1083|  30.0k|	if (ctx == NULL)
  ------------------
  |  Branch (1083:6): [True: 0, False: 30.0k]
  ------------------
 1084|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1085|  30.0k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1085:6): [True: 0, False: 30.0k]
  |  Branch (1085:33): [True: 0, False: 0]
  ------------------
 1086|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1087|  30.0k|	else
 1088|  30.0k|		return SC_SUCCESS;
  ------------------
  |  |   28|  30.0k|#define SC_SUCCESS				0
  ------------------
 1089|  30.0k|}
sc_mutex_lock:
 1092|  1.22M|{
 1093|  1.22M|	if (ctx == NULL)
  ------------------
  |  Branch (1093:6): [True: 0, False: 1.22M]
  ------------------
 1094|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1095|  1.22M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1095:6): [True: 0, False: 1.22M]
  |  Branch (1095:33): [True: 0, False: 0]
  ------------------
 1096|      0|		return ctx->thread_ctx->lock_mutex(mutex);
 1097|  1.22M|	else
 1098|  1.22M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.22M|#define SC_SUCCESS				0
  ------------------
 1099|  1.22M|}
sc_mutex_unlock:
 1102|  1.22M|{
 1103|  1.22M|	if (ctx == NULL)
  ------------------
  |  Branch (1103:6): [True: 0, False: 1.22M]
  ------------------
 1104|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1105|  1.22M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1105:6): [True: 0, False: 1.22M]
  |  Branch (1105:33): [True: 0, False: 0]
  ------------------
 1106|      0|		return ctx->thread_ctx->unlock_mutex(mutex);
 1107|  1.22M|	else
 1108|  1.22M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.22M|#define SC_SUCCESS				0
  ------------------
 1109|  1.22M|}

sc_verify:
  131|    770|{
  132|    770|	struct sc_pin_cmd_data data;
  133|       |
  134|    770|	memset(&data, 0, sizeof(data));
  135|    770|	data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|    770|#define SC_PIN_CMD_VERIFY	0
  ------------------
  136|    770|	data.pin_type = type;
  137|    770|	data.pin_reference = ref;
  138|    770|	data.pin1.data = pin;
  139|    770|	data.pin1.len = pinlen;
  140|       |
  141|    770|	int r = sc_pin_cmd(card, &data);
  142|    770|	if (tries_left)
  ------------------
  |  Branch (142:6): [True: 770, False: 0]
  ------------------
  143|    770|		*tries_left = data.pin1.tries_left;
  144|       |
  145|    770|	return r;
  146|    770|}
sc_pin_cmd:
  204|  1.67k|{
  205|  1.67k|	int r, debug;
  206|       |
  207|  1.67k|	if (card == NULL) {
  ------------------
  |  Branch (207:6): [True: 0, False: 1.67k]
  ------------------
  208|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  209|      0|	}
  210|  1.67k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.67k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.67k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.67k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.67k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.67k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|       |
  212|  1.67k|	debug = card->ctx->debug;
  213|  1.67k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  425|  3.35k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (213:6): [True: 770, False: 907]
  ------------------
  214|    770|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (214:7): [True: 770, False: 0]
  ------------------
  215|    770|		card->ctx->debug = 0;
  216|    770|	}
  217|       |
  218|  1.67k|	if (card->ops->pin_cmd) {
  ------------------
  |  Branch (218:6): [True: 1.67k, False: 0]
  ------------------
  219|  1.67k|		r = card->ops->pin_cmd(card, data);
  220|  1.67k|	} else if (!(data->flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (220:13): [True: 0, False: 0]
  ------------------
  221|       |		/* Card driver doesn't support new style pin_cmd, fall
  222|       |		 * back to old interface */
  223|       |
  224|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  225|      0|		switch (data->cmd) {
  ------------------
  |  Branch (225:11): [True: 0, False: 0]
  ------------------
  226|      0|		case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (226:3): [True: 0, False: 0]
  ------------------
  227|      0|			if (card->ops->verify != NULL)
  ------------------
  |  Branch (227:8): [True: 0, False: 0]
  ------------------
  228|      0|				r = card->ops->verify(card,
  229|      0|					data->pin_type,
  230|      0|					data->pin_reference,
  231|      0|					data->pin1.data,
  232|      0|					(size_t) data->pin1.len,
  233|      0|					&data->pin1.tries_left);
  234|      0|			break;
  235|      0|		case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (235:3): [True: 0, False: 0]
  ------------------
  236|      0|			if (card->ops->change_reference_data != NULL)
  ------------------
  |  Branch (236:8): [True: 0, False: 0]
  ------------------
  237|      0|				r = card->ops->change_reference_data(card,
  238|      0|					data->pin_type,
  239|      0|					data->pin_reference,
  240|      0|					data->pin1.data,
  241|      0|					(size_t) data->pin1.len,
  242|      0|					data->pin2.data,
  243|      0|					(size_t) data->pin2.len,
  244|      0|					&data->pin1.tries_left);
  245|      0|			break;
  246|      0|		case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (246:3): [True: 0, False: 0]
  ------------------
  247|      0|			if (card->ops->reset_retry_counter != NULL)
  ------------------
  |  Branch (247:8): [True: 0, False: 0]
  ------------------
  248|      0|				r = card->ops->reset_retry_counter(card,
  249|      0|					data->pin_type,
  250|      0|					data->pin_reference,
  251|      0|					data->pin1.data,
  252|      0|					(size_t) data->pin1.len,
  253|      0|					data->pin2.data,
  254|      0|					(size_t) data->pin2.len);
  255|      0|			break;
  256|      0|		}
  257|      0|		if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (257:7): [True: 0, False: 0]
  ------------------
  258|      0|			sc_log(card->ctx,  "unsupported PIN operation (%d)",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  259|      0|					data->cmd);
  260|      0|	} else {
  261|      0|		sc_log(card->ctx,  "Use of pin pad not supported by card driver");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  262|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  263|      0|	}
  264|  1.67k|	card->ctx->debug = debug;
  265|       |
  266|  1.67k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.67k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.67k|	int _ret = r; \
  |  |  155|  1.67k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.67k, False: 0]
  |  |  ------------------
  |  |  156|  1.67k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    828|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 828, False: 849]
  |  |  ------------------
  |  |  157|  1.67k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.67k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.67k|	return _ret; \
  |  |  163|  1.67k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  267|  1.67k|}

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

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

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

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

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

LLVMFuzzerTestOneInput:
   32|  15.0k|{
   33|  15.0k|	struct sc_context       *ctx = NULL;
   34|  15.0k|	struct sc_card          *card = NULL;
   35|  15.0k|	struct sc_pkcs15_card   *p15card = NULL;
   36|  15.0k|	struct sc_pkcs15_object *obj;
   37|  15.0k|	unsigned char           *unused_space = NULL;
   38|  15.0k|	size_t                   unused_space_len = 0;
   39|       |
   40|  15.0k|	sc_establish_context(&ctx, "fuzz");
   41|  15.0k|	if (!ctx)
  ------------------
  |  Branch (41:6): [True: 0, False: 15.0k]
  ------------------
   42|      0|		return 0;
   43|       |
   44|  15.0k|	if (fuzz_connect_card(ctx, &card, NULL, Data, Size) != SC_SUCCESS)
  ------------------
  |  |   28|  15.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (44:6): [True: 3.10k, False: 11.9k]
  ------------------
   45|  3.10k|		goto err;
   46|       |
   47|  11.9k|	if (sc_pkcs15_bind(card, NULL, &p15card) != 0)
  ------------------
  |  Branch (47:6): [True: 7.57k, False: 4.33k]
  ------------------
   48|  7.57k|		goto err;
   49|       |
   50|  28.0k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (50:32): [True: 23.7k, False: 4.33k]
  ------------------
   51|  23.7k|		u8 *buf = NULL;
   52|  23.7k|		size_t buf_len = 0;
   53|  23.7k|		struct sc_pkcs15_object *key_object = NULL;
   54|  23.7k|		sc_pkcs15_pubkey_t *pkey = NULL;
   55|  23.7k|		switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  23.7k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (55:11): [True: 23.7k, False: 0]
  ------------------
   56|    208|		case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    208|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (56:3): [True: 208, False: 23.5k]
  ------------------
   57|    208|			sc_pkcs15_encode_pukdf_entry(ctx, obj, &buf, &buf_len);
   58|    208|			sc_pkcs15_read_pubkey(p15card, obj, &pkey);
   59|    208|			sc_pkcs15_free_pubkey(pkey);
   60|    208|			break;
   61|  1.68k|		case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  1.68k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (61:3): [True: 1.68k, False: 22.0k]
  ------------------
   62|  1.68k|			sc_pkcs15_encode_prkdf_entry(ctx, obj, &buf, &buf_len);
   63|  1.68k|			break;
   64|  17.6k|		case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  17.6k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (64:3): [True: 17.6k, False: 6.10k]
  ------------------
   65|  17.6k|			sc_pkcs15_encode_dodf_entry(ctx, obj, &buf, &buf_len);
   66|  17.6k|			break;
   67|      0|		case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (67:3): [True: 0, False: 23.7k]
  ------------------
   68|      0|			sc_pkcs15_encode_skdf_entry(ctx, obj, &buf, &buf_len);
   69|      0|			break;
   70|  3.67k|		case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  3.67k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (70:3): [True: 3.67k, False: 20.0k]
  ------------------
   71|  3.67k|			sc_pkcs15_encode_aodf_entry(ctx, obj, &buf, &buf_len);
   72|  3.67k|			break;
   73|    539|		case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|    539|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (73:3): [True: 539, False: 23.1k]
  ------------------
   74|    539|			sc_pkcs15_encode_cdf_entry(ctx, obj, &buf, &buf_len);
   75|    539|			sc_pkcs15_prkey_attrs_from_cert(p15card, obj, &key_object);
   76|    539|			break;
   77|  23.7k|		}
   78|  23.7k|		free(buf);
   79|  23.7k|	}
   80|  4.33k|	sc_pkcs15_encode_unusedspace(ctx, p15card, &unused_space, &unused_space_len);
   81|  4.33k|	free(unused_space);
   82|       |
   83|  15.0k|err:
   84|  15.0k|	sc_pkcs15_card_free(p15card);
   85|  15.0k|	sc_disconnect_card(card);
   86|  15.0k|	sc_release_context(ctx);
   87|       |
   88|  15.0k|	return 0;
   89|  4.33k|}

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

