<commit_before>
/* Copyright (C) 2001  <NAME> <<EMAIL>> 
 * All rights reserved.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sc.h"

int main(int argc, char **argv) {
  struct sc_context *ctx = NULL;
  struct sc_card *card = NULL;
  struct sc_pkcs15_card *p15_card = NULL;
  struct sc_pkcs15_pin_object pin;
  char buf[16], buf2[16];
  
  int i,c ;

  i = sc_establish_context(&ctx);
  if (i < 0) {
  	printf("sc_establish_context() failed (%d)\n", i);
  	return 1;
  }
  i = sc_detect_card(ctx, 0);
  printf("Card %s.\n", i == 1 ? "present" : "absent");
  if (i < 0) {
    return 1;
  }
  if (i == 0) {
    printf("Please insert a smart card.");
    fflush(stdout);
    i = sc_wait_for_card(ctx, 0, -1);
    if (i != 1)
    	return 1;
    printf("\n");
  }
  printf("Connecting... ");
  fflush(stdout);
  i = sc_connect_card(ctx, 0, &card);
  if (i != 0) {
    printf("Connecting to card failed\n");
    return 1;
  }
  printf("done.\n");
  fflush(stdout);

  i = sc_pkcs15_init(card, &p15_card);
  if (i != 0) {
    fprintf(stderr, "PKCS#15 card init failed: %s\n", sc_strerror(i));
    return 1;
  }

  printf("Searching for PIN codes...\n");

  c = 0;
  while (sc_pkcs15_read_pin_object(p15_card, ++c, &pin) == 0) {
  	sc_pkcs15_print_pin_object(&pin);
  }
  c--;
  if (c == 0) {
  	printf("No PIN codes found!\n");
  	return 1;
  }

  i = sc_sec_ask_pin_code(&p15_card->pins[0], buf, sizeof(buf), "Please enter PIN code");
  if (i) {
    fprintf(stderr, "\nFailed to ask PIN code from user\n");
    return 1;
  }
  i = sc_sec_ask_pin_code(&p15_card->pins[0], buf2, sizeof(buf2), "Please enter _new_ PIN code");
  if (i) {
    fprintf(stderr, "\nFailed to ask PIN code from user\n");
    return 1;
  }
  i = sc_pkcs15_change_pin(p15_card, &p15_card->pins[0], buf, strlen(buf), buf2, strlen(buf2));
//  i = sc_pkcs15_verify_pin(p15_card, &p15_card->pins[0], buf, strlen(buf));
  if (i) {
    if (i == SC_ERROR_PIN_CODE_INCORRECT)
    	fprintf(stderr, "Incorrect PIN code (%d tries left)\n", p15_card->pins[0].tries_left);
    else
	fprintf(stderr, "PIN verifying failed: %s\n", sc_strerror(i));
    return 1;
  }
  printf("PIN code correct.\n");
  
  printf("Cleaning up...\n");
  i = sc_pkcs15_destroy(p15_card);
  sc_disconnect_card(card);
  sc_destroy_context(ctx);

  return 0;
  
  i = sc_pkcs15_read_certificate(p15_card, 0);
  if (i) {
    fprintf(stderr, "Certificate read failed with %d\n", i);
    return 1;
  }
  return 0;
}<commit_msg>fixed a weird escaping bug in sc_read_binary(). this could affect other functions too. needs more research.<commit_after>
/* Copyright (C) 2001  <NAME> <<EMAIL>> 
 * All rights reserved.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sc.h"

int main(int argc, char **argv) {
  struct sc_context *ctx = NULL;
  struct sc_card *card = NULL;
  struct sc_pkcs15_card *p15_card = NULL;
  struct sc_pkcs15_pin_object pin;
  char buf[16], buf2[16];
  
  int i,c ;

  i = sc_establish_context(&ctx);
  if (i < 0) {
  	printf("sc_establish_context() failed (%d)\n", i);
  	return 1;
  }
  i = sc_detect_card(ctx, 0);
  printf("Card %s.\n", i == 1 ? "present" : "absent");
  if (i < 0) {
    return 1;
  }
  if (i == 0) {
    printf("Please insert a smart card.");
    fflush(stdout);
    i = sc_wait_for_card(ctx, 0, -1);
    if (i != 1)
    	return 1;
    printf("\n");
  }
  printf("Connecting... ");
  fflush(stdout);
  i = sc_connect_card(ctx, 0, &card);
  if (i != 0) {
    printf("Connecting to card failed\n");
    return 1;
  }
  printf("done.\n");
  fflush(stdout);

  i = sc_pkcs15_init(card, &p15_card);
  if (i != 0) {
    fprintf(stderr, "PKCS#15 card init failed: %s\n", sc_strerror(i));
    return 1;
  }
  return 0;
  i = sc_pkcs15_read_certificate(p15_card, 0);
  if (i) {
    fprintf(stderr, "Certificate read failed with %d\n", i);
    return 1;
  }

  return 0;

  printf("Searching for PIN codes...\n");

  c = 0;
  while (sc_pkcs15_read_pin_object(p15_card, ++c, &pin) == 0) {
  	sc_pkcs15_print_pin_object(&pin);
  }
  c--;
  if (c == 0) {
  	printf("No PIN codes found!\n");
  	return 1;
  }

  i = sc_sec_ask_pin_code(&p15_card->pins[0], buf, sizeof(buf), "Please enter PIN code");
  if (i) {
    fprintf(stderr, "\nFailed to ask PIN code from user\n");
    return 1;
  }
  i = sc_sec_ask_pin_code(&p15_card->pins[0], buf2, sizeof(buf2), "Please enter _new_ PIN code");
  if (i) {
    fprintf(stderr, "\nFailed to ask PIN code from user\n");
    return 1;
  }
  i = sc_pkcs15_change_pin(p15_card, &p15_card->pins[0], buf, strlen(buf), buf2, strlen(buf2));
//  i = sc_pkcs15_verify_pin(p15_card, &p15_card->pins[0], buf, strlen(buf));
  if (i) {
    if (i == SC_ERROR_PIN_CODE_INCORRECT)
    	fprintf(stderr, "Incorrect PIN code (%d tries left)\n", p15_card->pins[0].tries_left);
    else
	fprintf(stderr, "PIN verifying failed: %s\n", sc_strerror(i));
    return 1;
  }
  printf("PIN code correct.\n");
  
  printf("Cleaning up...\n");
  i = sc_pkcs15_destroy(p15_card);
  sc_disconnect_card(card);
  sc_destroy_context(ctx);

  return 0;
  
  return 0;
}
{'fraction_non_alphanumeric': 0.17077013984636596, 'fraction_numerical': 0.03545400827260193, 'mean_word_length': 3.332764505119454, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5590741', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2060, 'n_words': 503}