Path: blob/main/crypto/openssl/demos/cms/cms_comp.c
34879 views
/*1* Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/* Simple S/MIME compress example */10#include <openssl/pem.h>11#include <openssl/cms.h>12#include <openssl/err.h>1314int main(int argc, char **argv)15{16BIO *in = NULL, *out = NULL;17CMS_ContentInfo *cms = NULL;18int ret = EXIT_FAILURE;1920/*21* On OpenSSL 1.0.0+ only:22* for streaming set CMS_STREAM23*/24int flags = CMS_STREAM;2526OpenSSL_add_all_algorithms();27ERR_load_crypto_strings();2829/* Open content being compressed */3031in = BIO_new_file("comp.txt", "r");3233if (!in)34goto err;3536/* compress content */37cms = CMS_compress(in, NID_zlib_compression, flags);3839if (!cms)40goto err;4142out = BIO_new_file("smcomp.txt", "w");43if (!out)44goto err;4546/* Write out S/MIME message */47if (!SMIME_write_CMS(out, cms, in, flags))48goto err;4950ret = EXIT_SUCCESS;5152err:5354if (ret != EXIT_SUCCESS) {55fprintf(stderr, "Error Compressing Data\n");56ERR_print_errors_fp(stderr);57}5859CMS_ContentInfo_free(cms);60BIO_free(in);61BIO_free(out);62return ret;63}646566