3 #endif /* ifdef HAVE_CONFIG_H */
11 #endif /* ifdef HAVE_UNISTD_H */
15 #endif /* ifdef HAVE_EVIL */
19 static int _eet_main_log_dom = -1;
21 #ifdef EET_DEFAULT_LOG_COLOR
22 #undef EET_DEFAULT_LOG_COLOR
23 #endif /* ifdef EET_DEFAULT_LOG_COLOR */
24 #define EET_DEFAULT_LOG_COLOR EINA_COLOR_CYAN
27 #endif /* ifdef ERR */
28 #define ERR(...) EINA_LOG_DOM_ERR(_eet_main_log_dom, __VA_ARGS__)
31 #endif /* ifdef DBG */
32 #define DBG(...) EINA_LOG_DOM_DBG(_eet_main_log_dom, __VA_ARGS__)
35 #endif /* ifdef INF */
36 #define INF(...) EINA_LOG_DOM_INFO(_eet_main_log_dom, __VA_ARGS__)
39 #endif /* ifdef WRN */
40 #define WRN(...) EINA_LOG_DOM_WARN(_eet_main_log_dom, __VA_ARGS__)
43 #endif /* ifdef CRIT */
44 #define CRIT(...) EINA_LOG_DOM_CRIT(_eet_main_log_dom, __VA_ARGS__)
47 do_eet_list(const char *file)
53 ef = eet_open(file, EET_FILE_MODE_READ);
56 ERR("cannot open for reading: %s", file);
60 list = eet_list(ef, "*", &num);
63 for (i = 0; i < num; i++)
64 printf("%s\n", list[i]);
72 do_eet_stats(const char *file)
75 int count[2] = { 0, 0 };
76 int size[2] = { 0, 0 };
81 ef = eet_open(file, EET_FILE_MODE_READ);
84 ERR("cannot open for reading: %s", file);
88 printf("*** sections stats ***\n");
89 list = eet_list(ef, "*", &num);
92 for (i = 0; i < num; i++)
94 const void *ro = NULL;
98 ro = eet_read_direct(ef, list[i], &tsize);
99 if (!ro) rw = eet_read(ef, list[i], &tsize);
100 printf(rw ? "%s of size %i is compressed.\n" : "%s of size %i is not compressed.\n", list[i], tsize);
102 size[rw ? 0 : 1] += tsize;
108 printf("*** dictionary ***\n");
109 ed = eet_dictionary_get(ef);
112 printf("%i strings inside the dictionary.\n", eet_dictionary_count(ed));
116 printf("no dictionary in this file.\n");
118 printf("*** global ***\n");
119 printf("%i sections\n", num);
120 printf("- %i of them are compressed (%02.2f%%) expanding in %i bytes.\n",
121 count[0], (float) count[0] * 100 / (float) num, size[0]);
122 printf("- %i of them are directly mappable in memory (%02.2f%%) representing %i bytes.\n",
123 count[1], (float) count[1] * 100 / (float) num, size[1]);
129 do_eet_extract(const char *file,
132 const char *crypto_key)
139 ef = eet_open(file, EET_FILE_MODE_READ);
142 ERR("cannot open for reading: %s", file);
146 data = eet_read_cipher(ef, key, &size, crypto_key);
149 ERR("cannot read key %s", key);
155 f = fopen(out, "wb");
158 ERR("cannot open %s", out);
163 if (fwrite(data, size, 1, f) != 1)
165 ERR("cannot write to %s", out ? out : "standard output");
172 } /* do_eet_extract */
175 do_eet_decode_dump(void *data,
178 fputs(str, (FILE *)data);
179 } /* do_eet_decode_dump */
182 do_eet_decode(const char *file,
185 const char *crypto_key)
190 ef = eet_open(file, EET_FILE_MODE_READ);
193 ERR("cannot open for reading: %s", file);
199 f = fopen(out, "wb");
202 ERR("cannot open %s", out);
207 if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
209 ERR("cannot write to %s", out ? out : "standard output");
215 } /* do_eet_decode */
218 do_eet_insert(const char *file,
222 const char *crypto_key)
229 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
231 ef = eet_open(file, EET_FILE_MODE_WRITE);
235 ERR("cannot open for read+write: %s", file);
239 f = fopen(out, "rb");
242 ERR("cannot open %s", out);
246 fseek(f, 0, SEEK_END);
252 ERR("cannot allocate %i bytes", size);
256 if (fread(data, size, 1, f) != 1)
258 ERR("cannot read file %s", out);
263 eet_write_cipher(ef, key, data, size, compress, crypto_key);
266 } /* do_eet_insert */
269 do_eet_encode(const char *file,
273 const char *crypto_key)
281 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
283 ef = eet_open(file, EET_FILE_MODE_WRITE);
287 ERR("cannot open for read+write: %s", file);
291 f = fopen(out, "rb");
294 ERR("cannot open %s", out);
298 fseek(f, 0, SEEK_END);
301 text = malloc(textlen);
304 ERR("cannot allocate %i bytes", size);
308 if (fread(text, textlen, 1, f) != 1)
310 ERR("cannot read file %s", out);
315 if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
317 ERR("cannot parse %s", out);
323 } /* do_eet_encode */
326 do_eet_remove(const char *file,
331 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
334 ERR("cannot open for read+write: %s", file);
340 } /* do_eet_remove */
343 do_eet_check(const char *file)
350 ef = eet_open(file, EET_FILE_MODE_READ);
353 ERR("checking signature of `%s` failed", file);
357 der = eet_identity_x509(ef, &der_length);
359 fprintf(stdout, "Certificate length %i.\n", der_length);
360 eet_identity_certificate_print(der, der_length, stdout);
362 eet_identity_signature(ef, &sign_length);
363 fprintf(stdout, "Signature length %i.\n", sign_length);
369 do_eet_sign(const char *file,
370 const char *private_key,
371 const char *public_key)
376 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
379 ERR("cannot open for read+write: %s.", file);
383 key = eet_identity_open(public_key, private_key, NULL);
386 ERR("cannot open key '%s:%s'.", public_key, private_key);
390 fprintf(stdout, "Using the following key to sign `%s`.\n", file);
391 eet_identity_print(key, stdout);
393 eet_identity_set(ef, key);
405 _eet_main_log_dom = eina_log_domain_register("eet_main", EINA_COLOR_CYAN);
406 if(_eet_main_log_dom < -1)
408 EINA_LOG_ERR("Impossible to create a log domain for eet_main.");
418 " eet -l FILE.EET list all keys in FILE.EET\n"
419 " eet -x FILE.EET KEY [OUT-FILE] [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
420 " eet -d FILE.EET KEY [OUT-FILE] [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
421 " eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
422 " eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
423 " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
424 " eet -c FILE.EET report and check the signature information of an eet file\n"
425 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
426 " eet -t FILE.EET give some statistic about a file\n"
432 if ((!strncmp(argv[1], "-h", 2)))
434 else if ((!strcmp(argv[1], "-l")) && (argc > 2))
435 do_eet_list(argv[2]);
436 else if ((!strcmp(argv[1], "-x")) && (argc > 3))
442 do_eet_extract(argv[2], argv[3], NULL, NULL);
447 do_eet_extract(argv[2], argv[3], argv[4], NULL);
452 do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
457 else if ((!strcmp(argv[1], "-d")) && (argc > 3))
463 do_eet_decode(argv[2], argv[3], NULL, NULL);
468 do_eet_decode(argv[2], argv[3], argv[4], NULL);
473 do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
478 else if ((!strcmp(argv[1], "-i")) && (argc > 5))
481 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
483 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
485 else if ((!strcmp(argv[1], "-e")) && (argc > 5))
488 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
490 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
492 else if ((!strcmp(argv[1], "-r")) && (argc > 3))
493 do_eet_remove(argv[2], argv[3]);
494 else if ((!strcmp(argv[1], "-c")) && (argc > 2))
495 do_eet_check(argv[2]);
496 else if ((!strcmp(argv[1], "-s")) && (argc > 4))
497 do_eet_sign(argv[2], argv[3], argv[4]);
498 else if ((!strcmp(argv[1], "-t")) && (argc > 2))
499 do_eet_stats(argv[2]);
503 eina_log_domain_unregister(_eet_main_log_dom);