cms_uncomp.c 956 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. fprintf(stderr, "Error Uncompressing Data\n");
  30. ERR_print_errors_fp(stderr);
  31. }
  32. if (cms)
  33. CMS_ContentInfo_free(cms);
  34. if (in)
  35. BIO_free(in);
  36. if (out)
  37. BIO_free(out);
  38. return ret;
  39. }