cms_uncomp.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* Simple S/MIME uncompression example */
  10. #include <openssl/pem.h>
  11. #include <openssl/cms.h>
  12. #include <openssl/err.h>
  13. int main(int argc, char **argv)
  14. {
  15. BIO *in = NULL, *out = NULL;
  16. CMS_ContentInfo *cms = NULL;
  17. int ret = 1;
  18. OpenSSL_add_all_algorithms();
  19. ERR_load_crypto_strings();
  20. /* Open compressed content */
  21. in = BIO_new_file("smcomp.txt", "r");
  22. if (!in)
  23. goto err;
  24. /* Sign content */
  25. cms = SMIME_read_CMS(in, NULL);
  26. if (!cms)
  27. goto err;
  28. out = BIO_new_file("smuncomp.txt", "w");
  29. if (!out)
  30. goto err;
  31. /* Uncompress S/MIME message */
  32. if (!CMS_uncompress(cms, out, NULL, 0))
  33. goto err;
  34. ret = 0;
  35. err:
  36. if (ret) {
  37. fprintf(stderr, "Error Uncompressing Data\n");
  38. ERR_print_errors_fp(stderr);
  39. }
  40. CMS_ContentInfo_free(cms);
  41. BIO_free(in);
  42. BIO_free(out);
  43. return ret;
  44. }