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