test6.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 global compress */
  19. zzz_compression(ctx, ZZZ_FILTER_ZSTD, 5);
  20. zzz_encrypt(ctx, ZZZ_ENC_AES_256_CBC, (uint8_t*)password, strlen(password));
  21. zzz_encrypt(ctx, ZZZ_ENC_SHA_256_XOR, (uint8_t*)password, strlen(password));
  22. zzz_encrypt(ctx, ZZZ_ENC_AES_256_CBC, (uint8_t*)password, strlen(password));
  23. zzz_entity_file(ctx, "valami.txt", 1, strlen(content));
  24. zzz_entity_mtime_t(ctx, time(NULL));
  25. zzz_entity_extra_mime(ctx, "text/plain");
  26. zzz_entity_data(ctx, (uint8_t*)content, strlen(content));
  27. zzz_entity_flush(ctx);
  28. zzz_entity_symlink(ctx, "link.txt", "valami.txt");
  29. zzz_entity_extra_mime(ctx, "text/plain");
  30. zzz_entity_flush(ctx);
  31. zzz_entity_dir(ctx, "directory");
  32. zzz_entity_flush(ctx);
  33. zzz_finish(ctx, &mem, NULL);
  34. free(mem);
  35. printf("\n\n");
  36. ctx = zzz_open_file("a.zzz");
  37. if(!ctx) { printf("unable to read\n"); return 0; }
  38. do {
  39. ret = zzz_read_header(ctx, &ent);
  40. printf("read header %d\n",ret);
  41. switch(ret) {
  42. case ZZZ_END: printf("end.\n"); break;
  43. case ZZZ_ENCRYPTED:
  44. ret = zzz_decrypt(ctx, (uint8_t*)password, strlen(password));
  45. continue;
  46. case ZZZ_OK:
  47. printf("fn '%s'\ntype %02x uncompressed %ld compressed %ld filt %d %d\n", ent->filename, ent->header.type,
  48. ent->header.uncompressed, ent->header.contentsize, ent->filter[0].method, ent->filter[1].method);
  49. if(ent->header.uncompressed) {
  50. size = ent->header.uncompressed;
  51. ret = zzz_read_data(ctx, (uint8_t*)&buf, &size);
  52. printf("data read uncomp %ld ret %d\n", size, ret);
  53. ret = ZZZ_OK;
  54. }
  55. break;
  56. default:
  57. printf("error %d\n", ret);
  58. break;
  59. }
  60. } while(ret == ZZZ_OK);
  61. zzz_close(ctx);
  62. return 0;
  63. }