cms_uncomp.c 841 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Simple S/MIME uncompression example */
  2. #include <openssl/pem.h>
  3. #include <openssl/cms.h>
  4. #include <openssl/err.h>
  5. int main(int argc, char **argv)
  6. {
  7. BIO *in = NULL, *out = NULL;
  8. CMS_ContentInfo *cms = NULL;
  9. int ret = 1;
  10. OpenSSL_add_all_algorithms();
  11. ERR_load_crypto_strings();
  12. /* Open compressed content */
  13. in = BIO_new_file("smcomp.txt", "r");
  14. if (!in)
  15. goto err;
  16. /* Sign content */
  17. cms = SMIME_read_CMS(in, NULL);
  18. if (!cms)
  19. goto err;
  20. out = BIO_new_file("smuncomp.txt", "w");
  21. if (!out)
  22. goto err;
  23. /* Uncompress S/MIME message */
  24. if (!CMS_uncompress(cms, out, NULL, 0))
  25. goto err;
  26. ret = 0;
  27. err:
  28. if (ret)
  29. {
  30. fprintf(stderr, "Error Uncompressing Data\n");
  31. ERR_print_errors_fp(stderr);
  32. }
  33. if (cms)
  34. CMS_ContentInfo_free(cms);
  35. if (in)
  36. BIO_free(in);
  37. if (out)
  38. BIO_free(out);
  39. return ret;
  40. }