cms_uncomp.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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 = EXIT_FAILURE;
  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 = EXIT_SUCCESS;
  35. err:
  36. if (ret != EXIT_SUCCESS) {
  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. }