<commit_before>#include <stdio.h>
#include <string.h>

#include <ksi/ksi.h>
#include <ksi/ksi_net_curl.h>

int main(int argc, char **argv) {
	KSI_CTX *ksi = NULL;
	int res = KSI_UNKNOWN_ERROR;

	FILE *in = NULL;
	FILE *inp = NULL;

	FILE *out = NULL;
	FILE *outp = NULL;

	KSI_DataHasher *hsr = NULL;
	KSI_DataHash *hsh = NULL;
	KSI_Signature *sign = NULL;

	unsigned char *raw;
	int raw_len;

	unsigned char buf[1024];
	int buf_len;

	/** Global init of KSI */
	res = KSI_global_init();
	if (res != KSI_OK) goto cleanup;

	/* Handle command line parameters */
	if (argc != 5) {
		fprintf(stderr, "Usage:\n"
				"  %s <in-file | - > <out-file | - > <aggregator url |-> <pub-file url | -> \n", argv[0]);
		res = KSI_INVALID_ARGUMENT;
		goto cleanup;
	}

	/* Input file */
	if (argv[1] == NULL || !strncmp("-", argv[1], 1)) {
		inp = stdin;
	} else {
		in = inp = fopen(argv[1], "rb");
	}
	if (inp == NULL) {
		fprintf(stderr, "Unable to open input file '%s'\n", argv[1]);
		res = KSI_IO_ERROR;

		goto cleanup;
	}

	/* Output file */
	if (argv[2] == NULL || !strncmp("-", argv[2], 1)) {
		outp = stdout;
	} else {
		out = outp = fopen(argv[2], "wb");
	}
	if (outp == NULL) {
		fprintf(stderr, "Unable to open input file '%s'\n", argv[2]);
		res = KSI_IO_ERROR;

		goto cleanup;
	}


	/* Create new KSI context for this thread. */
	res = KSI_CTX_new(&ksi);
	if (res != KSI_OK) {
		fprintf(stderr, "Unable to create context.\n");
		goto cleanup;
	}

	/* Check if uri's are specified. */
	if (strncmp("-", argv[3], 1) || strncmp("-", argv[4], 1)) {
		KSI_NetProvider *net = NULL;
		res = KSI_CurlNetProvider_new(ksi, &net);
		if (res != KSI_OK) {
			fprintf(stderr, "Unable to create new network provider.\n");
			goto cleanup;
		}

		/* Check aggregator url */
		if (strncmp("-", argv[3], 1)) {
			res = KSI_CurlNetProvider_setSignerUrl(net, argv[3]);
			if (res != KSI_OK) {
				fprintf(stderr, "Unable to set aggregator url.\n");
				goto cleanup;
			}
		}

		/* Check publications file url. */
		if (strncmp("-", argv[4], 1)) {
			res = KSI_CurlNetProvider_setPublicationUrl(net, argv[4]);
			if (res != KSI_OK) {
				fprintf(stderr, "Unable to set publications file url.\n");
				goto cleanup;
			}
		}

		/* Set the new network provider. */
		res = KSI_setNetworkProvider(ksi, net);
		if (res != KSI_OK) {
			fprintf(stderr, "Unable to set network provider.\n");
			res = KSI_UNKNOWN_ERROR;

			goto cleanup;
		}
	}

	/* Create a data hasher using default algorithm. */
	res = KSI_DataHasher_open(ksi, KSI_getHashAlgorithmByName("default"), &hsr);
	if (res != KSI_OK) {
		fprintf(stderr, "Unable to create hasher.\n");
		goto cleanup;
	}

	/* Read the input file and calculate the hash of its contents. */
	while (!feof(inp)) {
		buf_len = fread(buf, 1, sizeof(buf), inp);

		/* Add  next block to the calculation. */
		res = KSI_DataHasher_add(hsr, buf, buf_len);
		if (res != KSI_OK) {
			fprintf(stderr, "Unable to add data to hasher.\n");
			goto cleanup;
		}
	}

	/* Close the data hasher and retreive the data hash. */<commit_msg>Removed usage of stdin and stdout for data and signature.<commit_after>#include <stdio.h>
#include <string.h>

#include <ksi/ksi.h>
#include <ksi/ksi_net_curl.h>

int main(int argc, char **argv) {
	KSI_CTX *ksi = NULL;
	int res = KSI_UNKNOWN_ERROR;

	FILE *in = NULL;
	FILE *out = NULL;

	KSI_DataHasher *hsr = NULL;
	KSI_DataHash *hsh = NULL;
	KSI_Signature *sign = NULL;

	unsigned char *raw;
	int raw_len;

	unsigned char buf[1024];
	int buf_len;

	/** Global init of KSI */
	res = KSI_global_init();
	if (res != KSI_OK) goto cleanup;

	/* Handle command line parameters */
	if (argc != 5) {
		fprintf(stderr, "Usage:\n"
				"  %s <in-file> <out-file> <aggregator url |-> <pub-file url | -> \n", argv[0]);
		res = KSI_INVALID_ARGUMENT;
		goto cleanup;
	}

	/* Input file */
	in = fopen(argv[1], "rb");
	if (in == NULL) {
		fprintf(stderr, "Unable to open input file '%s'\n", argv[1]);
		res = KSI_IO_ERROR;
		goto cleanup;
	}

	/* Output file */
	out = fopen(argv[2], "wb");
	if (out == NULL) {
		fprintf(stderr, "Unable to open input file '%s'\n", argv[2]);
		res = KSI_IO_ERROR;
		goto cleanup;
	}


	/* Create new KSI context for this thread. */
	res = KSI_CTX_new(&ksi);
	if (res != KSI_OK) {
		fprintf(stderr, "Unable to create context.\n");
		goto cleanup;
	}

	/* Check if uri's are specified. */
	if (strncmp("-", argv[3], 1) || strncmp("-", argv[4], 1)) {
		KSI_NetProvider *net = NULL;
		res = KSI_CurlNetProvider_new(ksi, &net);
		if (res != KSI_OK) {
			fprintf(stderr, "Unable to create new network provider.\n");
			goto cleanup;
		}

		/* Check aggregator url */
		if (strncmp("-", argv[3], 1)) {
			res = KSI_CurlNetProvider_setSignerUrl(net, argv[3]);
			if (res != KSI_OK) {
				fprintf(stderr, "Unable to set aggregator url.\n");
				goto cleanup;
			}
		}

		/* Check publications file url. */
		if (strncmp("-", argv[4], 1)) {
			res = KSI_CurlNetProvider_setPublicationUrl(net, argv[4]);
			if (res != KSI_OK) {
				fprintf(stderr, "Unable to set publications file url.\n");
				goto cleanup;
			}
		}

		/* Set the new network provider. */
		res = KSI_setNetworkProvider(ksi, net);
		if (res != KSI_OK) {
			fprintf(stderr, "Unable to set network provider.\n");
			res = KSI_UNKNOWN_ERROR;

			goto cleanup;
		}
	}

	/* Create a data hasher using default algorithm. */
	res = KSI_DataHasher_open(ksi, KSI_getHashAlgorithmByName("default"), &hsr);
	if (res != KSI_OK) {
		fprintf(stderr, "Unable to create hasher.\n");
		goto cleanup;
	}

	/* Read the input file and calculate the hash of its contents. */
	while (!feof(in)) {
		buf_len = fread(buf, 1, sizeof(buf), in);

		/* Add  next block to the calculation. */
		res = KSI_DataHasher_add(hsr, buf, buf_len);
		if (res != KSI_OK) {
			fprintf(stderr, "Unable to add data to hasher.\n");
			goto cleanup;
		}
	}

	/* Close the data hasher and retreive the data hash. */
{'fraction_non_alphanumeric': 0.1629566694987256, 'fraction_numerical': 0.008156329651656755, 'mean_word_length': 3.2776162790697674, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '6915206', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2260, 'n_words': 637}