]>
Commit | Line | Data |
---|---|---|
47a6d388 DSH |
1 | /* Simple S/MIME compress example */ |
2 | #include <openssl/pem.h> | |
3 | #include <openssl/cms.h> | |
4 | #include <openssl/err.h> | |
5 | ||
6 | int main(int argc, char **argv) | |
0f113f3e MC |
7 | { |
8 | BIO *in = NULL, *out = NULL; | |
9 | CMS_ContentInfo *cms = NULL; | |
10 | int ret = 1; | |
47a6d388 | 11 | |
0f113f3e MC |
12 | /* |
13 | * On OpenSSL 1.0.0+ only: | |
14 | * for streaming set CMS_STREAM | |
15 | */ | |
16 | int flags = CMS_STREAM; | |
47a6d388 | 17 | |
0f113f3e MC |
18 | OpenSSL_add_all_algorithms(); |
19 | ERR_load_crypto_strings(); | |
47a6d388 | 20 | |
0f113f3e | 21 | /* Open content being compressed */ |
47a6d388 | 22 | |
0f113f3e | 23 | in = BIO_new_file("comp.txt", "r"); |
47a6d388 | 24 | |
0f113f3e MC |
25 | if (!in) |
26 | goto err; | |
47a6d388 | 27 | |
0f113f3e MC |
28 | /* compress content */ |
29 | cms = CMS_compress(in, NID_zlib_compression, flags); | |
47a6d388 | 30 | |
0f113f3e MC |
31 | if (!cms) |
32 | goto err; | |
47a6d388 | 33 | |
0f113f3e MC |
34 | out = BIO_new_file("smcomp.txt", "w"); |
35 | if (!out) | |
36 | goto err; | |
47a6d388 | 37 | |
0f113f3e MC |
38 | /* Write out S/MIME message */ |
39 | if (!SMIME_write_CMS(out, cms, in, flags)) | |
40 | goto err; | |
47a6d388 | 41 | |
0f113f3e | 42 | ret = 0; |
47a6d388 | 43 | |
0f113f3e | 44 | err: |
47a6d388 | 45 | |
0f113f3e MC |
46 | if (ret) { |
47 | fprintf(stderr, "Error Compressing Data\n"); | |
48 | ERR_print_errors_fp(stderr); | |
49 | } | |
47a6d388 | 50 | |
0f113f3e MC |
51 | if (cms) |
52 | CMS_ContentInfo_free(cms); | |
53 | if (in) | |
54 | BIO_free(in); | |
55 | if (out) | |
56 | BIO_free(out); | |
47a6d388 | 57 | |
0f113f3e | 58 | return ret; |
47a6d388 | 59 | |
0f113f3e | 60 | } |