VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.5/demos/cms/cms_comp.c@ 104658

Last change on this file since 104658 was 104078, checked in by vboxsync, 11 months ago

openssl-3.1.5: Applied and adjusted our OpenSSL changes to 3.1.4. bugref:10638

File size: 1.4 KB
Line 
1/*
2 * Copyright 2008-2016 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
10/* Simple S/MIME compress example */
11#include <openssl/pem.h>
12#include <openssl/cms.h>
13#include <openssl/err.h>
14
15int main(int argc, char **argv)
16{
17 BIO *in = NULL, *out = NULL;
18 CMS_ContentInfo *cms = NULL;
19 int ret = EXIT_FAILURE;
20
21 /*
22 * On OpenSSL 1.0.0+ only:
23 * for streaming set CMS_STREAM
24 */
25 int flags = CMS_STREAM;
26
27 OpenSSL_add_all_algorithms();
28 ERR_load_crypto_strings();
29
30 /* Open content being compressed */
31
32 in = BIO_new_file("comp.txt", "r");
33
34 if (!in)
35 goto err;
36
37 /* compress content */
38 cms = CMS_compress(in, NID_zlib_compression, flags);
39
40 if (!cms)
41 goto err;
42
43 out = BIO_new_file("smcomp.txt", "w");
44 if (!out)
45 goto err;
46
47 /* Write out S/MIME message */
48 if (!SMIME_write_CMS(out, cms, in, flags))
49 goto err;
50
51 ret = EXIT_SUCCESS;
52
53 err:
54
55 if (ret != EXIT_SUCCESS) {
56 fprintf(stderr, "Error Compressing Data\n");
57 ERR_print_errors_fp(stderr);
58 }
59
60 CMS_ContentInfo_free(cms);
61 BIO_free(in);
62 BIO_free(out);
63 return ret;
64}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette