test5.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <zzz.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <time.h>
  6. int main(int argc, char **argv)
  7. {
  8. zzz_entity_t *ent;
  9. int ret;
  10. void *ctx = zzz_create_file("a.zzz");
  11. uint8_t *mem = NULL;
  12. uint64_t size;
  13. char buf[4096];
  14. char *content = "hello world\nmasik sor\nmeg valami hogy legyen hosszabb\nhello world\nmasik sor\nmeg valami hogy legye0123456789\n";
  15. char *password = "valami";
  16. (void)argc;
  17. (void)argv;
  18. /* encryption chain with entity compress */
  19. zzz_encrypt(ctx, ZZZ_ENC_AES_256_CBC, (uint8_t*)password, strlen(password));
  20. zzz_encrypt(ctx, ZZZ_ENC_SHA_256_XOR, (uint8_t*)password, strlen(password));
  21. zzz_encrypt(ctx, ZZZ_ENC_AES_256_CBC, (uint8_t*)password, strlen(password));
  22. zzz_entity_file(ctx, "valami.txt", 1, strlen(content));
  23. zzz_entity_mtime_t(ctx, time(NULL));
  24. zzz_entity_extra_mime(ctx, "text/plain");
  25. zzz_entity_data(ctx, (uint8_t*)content, strlen(content));
  26. zzz_entity_flush(ctx);
  27. zzz_entity_symlink(ctx, "link.txt", "valami.txt");
  28. zzz_entity_extra_mime(ctx, "text/plain");
  29. zzz_entity_flush(ctx);
  30. zzz_entity_dir(ctx, "directory");
  31. zzz_entity_flush(ctx);
  32. zzz_finish(ctx, &mem, NULL);
  33. free(mem);
  34. printf("\n\n");
  35. ctx = zzz_open_file("a.zzz");
  36. if(!ctx) { printf("unable to read\n"); return 0; }
  37. do {
  38. ret = zzz_read_header(ctx, &ent);
  39. printf("read header %d\n",ret);
  40. switch(ret) {
  41. case ZZZ_END: printf("end.\n"); break;
  42. case ZZZ_ENCRYPTED:
  43. ret = zzz_decrypt(ctx, (uint8_t*)password, strlen(password));
  44. continue;
  45. case ZZZ_OK:
  46. printf("fn '%s'\ntype %02x uncompressed %ld compressed %ld filt %d %d\n", ent->filename, ent->header.type,
  47. ent->header.uncompressed, ent->header.contentsize, ent->filter[0].method, ent->filter[1].method);
  48. if(ent->header.uncompressed) {
  49. size = ent->header.uncompressed;
  50. ret = zzz_read_data(ctx, (uint8_t*)&buf, &size);
  51. printf("data read uncomp %ld ret %d\n", size, ret);
  52. ret = ZZZ_OK;
  53. }
  54. break;
  55. default:
  56. printf("error %d\n", ret);
  57. break;
  58. }
  59. } while(ret == ZZZ_OK);
  60. zzz_close(ctx);
  61. return 0;
  62. }