2016-05-18 21:16:36 +08:00
|
|
|
/*
|
2023-09-07 16:59:15 +08:00
|
|
|
* Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.
|
2016-05-18 21:16:36 +08:00
|
|
|
*
|
2018-12-06 21:08:15 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 21:16:36 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
2008-04-12 01:33:29 +08:00
|
|
|
/* Simple S/MIME uncompression example */
|
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include <openssl/cms.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
BIO *in = NULL, *out = NULL;
|
|
|
|
CMS_ContentInfo *cms = NULL;
|
2023-03-20 12:48:33 +08:00
|
|
|
int ret = EXIT_FAILURE;
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
OpenSSL_add_all_algorithms();
|
|
|
|
ERR_load_crypto_strings();
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/* Open compressed content */
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
in = BIO_new_file("smcomp.txt", "r");
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!in)
|
|
|
|
goto err;
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/* Sign content */
|
|
|
|
cms = SMIME_read_CMS(in, NULL);
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!cms)
|
|
|
|
goto err;
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
out = BIO_new_file("smuncomp.txt", "w");
|
|
|
|
if (!out)
|
|
|
|
goto err;
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/* Uncompress S/MIME message */
|
|
|
|
if (!CMS_uncompress(cms, out, NULL, 0))
|
|
|
|
goto err;
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2023-03-20 12:48:33 +08:00
|
|
|
ret = EXIT_SUCCESS;
|
2015-01-22 11:40:55 +08:00
|
|
|
err:
|
2023-03-20 12:48:33 +08:00
|
|
|
if (ret != EXIT_SUCCESS) {
|
2015-01-22 11:40:55 +08:00
|
|
|
fprintf(stderr, "Error Uncompressing Data\n");
|
|
|
|
ERR_print_errors_fp(stderr);
|
|
|
|
}
|
2008-04-12 01:33:29 +08:00
|
|
|
|
2015-05-02 02:37:16 +08:00
|
|
|
CMS_ContentInfo_free(cms);
|
2015-03-25 23:31:18 +08:00
|
|
|
BIO_free(in);
|
|
|
|
BIO_free(out);
|
2015-01-22 11:40:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|