diff options
author | Matt Caswell <matt@openssl.org> | 2015-01-22 03:40:55 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-01-22 09:20:09 +0000 |
commit | 0f113f3ee4d629ef9a4a30911b22b224772085e5 (patch) | |
tree | e014603da5aed1d0751f587a66d6e270b6bda3de /demos/cms | |
parent | 22b52164aaed31d6e93dbd2d397ace041360e6aa (diff) | |
download | openssl-0f113f3ee4d629ef9a4a30911b22b224772085e5.tar.gz |
Run util/openssl-format-source -v -c .
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'demos/cms')
-rw-r--r-- | demos/cms/cms_comp.c | 79 | ||||
-rw-r--r-- | demos/cms/cms_ddec.c | 120 | ||||
-rw-r--r-- | demos/cms/cms_dec.c | 103 | ||||
-rw-r--r-- | demos/cms/cms_denc.c | 133 | ||||
-rw-r--r-- | demos/cms/cms_enc.c | 126 | ||||
-rw-r--r-- | demos/cms/cms_sign.c | 119 | ||||
-rw-r--r-- | demos/cms/cms_sign2.c | 129 | ||||
-rw-r--r-- | demos/cms/cms_uncomp.c | 69 | ||||
-rw-r--r-- | demos/cms/cms_ver.c | 110 |
9 files changed, 491 insertions, 497 deletions
diff --git a/demos/cms/cms_comp.c b/demos/cms/cms_comp.c index 01bf092546..059152fe0e 100644 --- a/demos/cms/cms_comp.c +++ b/demos/cms/cms_comp.c @@ -4,58 +4,57 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - /* - * On OpenSSL 1.0.0+ only: - * for streaming set CMS_STREAM - */ - int flags = CMS_STREAM; + /* + * On OpenSSL 1.0.0+ only: + * for streaming set CMS_STREAM + */ + int flags = CMS_STREAM; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Open content being compressed */ + /* Open content being compressed */ - in = BIO_new_file("comp.txt", "r"); + in = BIO_new_file("comp.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* compress content */ - cms = CMS_compress(in, NID_zlib_compression, flags); + /* compress content */ + cms = CMS_compress(in, NID_zlib_compression, flags); - if (!cms) - goto err; + if (!cms) + goto err; - out = BIO_new_file("smcomp.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("smcomp.txt", "w"); + if (!out) + goto err; - /* Write out S/MIME message */ - if (!SMIME_write_CMS(out, cms, in, flags)) - goto err; + /* Write out S/MIME message */ + if (!SMIME_write_CMS(out, cms, in, flags)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Compressing Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Compressing Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); - if (in) - BIO_free(in); - if (out) - BIO_free(out); + if (cms) + CMS_ContentInfo_free(cms); + if (in) + BIO_free(in); + if (out) + BIO_free(out); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_ddec.c b/demos/cms/cms_ddec.c index ba68cfdf76..37ac97fd01 100644 --- a/demos/cms/cms_ddec.c +++ b/demos/cms/cms_ddec.c @@ -1,89 +1,89 @@ -/* S/MIME detached data decrypt example: rarely done but - * should the need arise this is an example.... +/* + * S/MIME detached data decrypt example: rarely done but should the need + * arise this is an example.... */ #include <openssl/pem.h> #include <openssl/cms.h> #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL, *dcont = NULL; - X509 *rcert = NULL; - EVP_PKEY *rkey = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL, *dcont = NULL; + X509 *rcert = NULL; + EVP_PKEY *rkey = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Read in recipient certificate and private key */ - tbio = BIO_new_file("signer.pem", "r"); + /* Read in recipient certificate and private key */ + tbio = BIO_new_file("signer.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + BIO_reset(tbio); - rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); + rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); - if (!rcert || !rkey) - goto err; + if (!rcert || !rkey) + goto err; - /* Open PEM file containing enveloped data */ + /* Open PEM file containing enveloped data */ - in = BIO_new_file("smencr.pem", "r"); + in = BIO_new_file("smencr.pem", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* Parse PEM content */ - cms = PEM_read_bio_CMS(in, NULL, 0, NULL); + /* Parse PEM content */ + cms = PEM_read_bio_CMS(in, NULL, 0, NULL); - if (!cms) - goto err; + if (!cms) + goto err; - /* Open file containing detached content */ - dcont = BIO_new_file("smencr.out", "rb"); + /* Open file containing detached content */ + dcont = BIO_new_file("smencr.out", "rb"); - if (!in) - goto err; + if (!in) + goto err; - out = BIO_new_file("encrout.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("encrout.txt", "w"); + if (!out) + goto err; - /* Decrypt S/MIME message */ - if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0)) - goto err; + /* Decrypt S/MIME message */ + if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Decrypting Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Decrypting Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); - if (rcert) - X509_free(rcert); - if (rkey) - EVP_PKEY_free(rkey); + if (cms) + CMS_ContentInfo_free(cms); + if (rcert) + X509_free(rcert); + if (rkey) + EVP_PKEY_free(rkey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); - if (dcont) - BIO_free(dcont); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (tbio) + BIO_free(tbio); + if (dcont) + BIO_free(dcont); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_dec.c b/demos/cms/cms_dec.c index 9fee0a3ebf..3291eacab4 100644 --- a/demos/cms/cms_dec.c +++ b/demos/cms/cms_dec.c @@ -4,76 +4,75 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL; - X509 *rcert = NULL; - EVP_PKEY *rkey = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL; + X509 *rcert = NULL; + EVP_PKEY *rkey = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Read in recipient certificate and private key */ - tbio = BIO_new_file("signer.pem", "r"); + /* Read in recipient certificate and private key */ + tbio = BIO_new_file("signer.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + BIO_reset(tbio); - rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); + rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); - if (!rcert || !rkey) - goto err; + if (!rcert || !rkey) + goto err; - /* Open S/MIME message to decrypt */ + /* Open S/MIME message to decrypt */ - in = BIO_new_file("smencr.txt", "r"); + in = BIO_new_file("smencr.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* Parse message */ - cms = SMIME_read_CMS(in, NULL); + /* Parse message */ + cms = SMIME_read_CMS(in, NULL); - if (!cms) - goto err; + if (!cms) + goto err; - out = BIO_new_file("decout.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("decout.txt", "w"); + if (!out) + goto err; - /* Decrypt S/MIME message */ - if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0)) - goto err; + /* Decrypt S/MIME message */ + if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Decrypting Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Decrypting Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); - if (rcert) - X509_free(rcert); - if (rkey) - EVP_PKEY_free(rkey); + if (cms) + CMS_ContentInfo_free(cms); + if (rcert) + X509_free(rcert); + if (rkey) + EVP_PKEY_free(rkey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (tbio) + BIO_free(tbio); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_denc.c b/demos/cms/cms_denc.c index 9265e47bf9..c86a5fd728 100644 --- a/demos/cms/cms_denc.c +++ b/demos/cms/cms_denc.c @@ -1,97 +1,98 @@ -/* S/MIME detached data encrypt example: rarely done but - * should the need arise this is an example.... +/* + * S/MIME detached data encrypt example: rarely done but should the need + * arise this is an example.... */ #include <openssl/pem.h> #include <openssl/cms.h> #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL, *dout = NULL; - X509 *rcert = NULL; - STACK_OF(X509) *recips = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL, *dout = NULL; + X509 *rcert = NULL; + STACK_OF(X509) *recips = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - int flags = CMS_STREAM|CMS_DETACHED; + int flags = CMS_STREAM | CMS_DETACHED; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Read in recipient certificate */ - tbio = BIO_new_file("signer.pem", "r"); + /* Read in recipient certificate */ + tbio = BIO_new_file("signer.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - if (!rcert) - goto err; + if (!rcert) + goto err; - /* Create recipient STACK and add recipient cert to it */ - recips = sk_X509_new_null(); + /* Create recipient STACK and add recipient cert to it */ + recips = sk_X509_new_null(); - if (!recips || !sk_X509_push(recips, rcert)) - goto err; + if (!recips || !sk_X509_push(recips, rcert)) + goto err; - /* sk_X509_pop_free will free up recipient STACK and its contents - * so set rcert to NULL so it isn't freed up twice. - */ - rcert = NULL; + /* + * sk_X509_pop_free will free up recipient STACK and its contents so set + * rcert to NULL so it isn't freed up twice. + */ + rcert = NULL; - /* Open content being encrypted */ + /* Open content being encrypted */ - in = BIO_new_file("encr.txt", "r"); + in = BIO_new_file("encr.txt", "r"); - dout = BIO_new_file("smencr.out", "wb"); + dout = BIO_new_file("smencr.out", "wb"); - if (!in) - goto err; + if (!in) + goto err; - /* encrypt content */ - cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags); + /* encrypt content */ + cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags); - if (!cms) - goto err; + if (!cms) + goto err; - out = BIO_new_file("smencr.pem", "w"); - if (!out) - goto err; + out = BIO_new_file("smencr.pem", "w"); + if (!out) + goto err; - if (!CMS_final(cms, in, dout, flags)) - goto err; + if (!CMS_final(cms, in, dout, flags)) + goto err; - /* Write out CMS structure without content */ - if (!PEM_write_bio_CMS(out, cms)) - goto err; + /* Write out CMS structure without content */ + if (!PEM_write_bio_CMS(out, cms)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Encrypting Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Encrypting Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); - if (rcert) - X509_free(rcert); - if (recips) - sk_X509_pop_free(recips, X509_free); + if (cms) + CMS_ContentInfo_free(cms); + if (rcert) + X509_free(rcert); + if (recips) + sk_X509_pop_free(recips, X509_free); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (dout) - BIO_free(dout); - if (tbio) - BIO_free(tbio); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (dout) + BIO_free(dout); + if (tbio) + BIO_free(tbio); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_enc.c b/demos/cms/cms_enc.c index 916b479d3c..e8ecb48e27 100644 --- a/demos/cms/cms_enc.c +++ b/demos/cms/cms_enc.c @@ -4,89 +4,89 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL; - X509 *rcert = NULL; - STACK_OF(X509) *recips = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL; + X509 *rcert = NULL; + STACK_OF(X509) *recips = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - /* - * On OpenSSL 1.0.0 and later only: - * for streaming set CMS_STREAM - */ - int flags = CMS_STREAM; + /* + * On OpenSSL 1.0.0 and later only: + * for streaming set CMS_STREAM + */ + int flags = CMS_STREAM; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Read in recipient certificate */ - tbio = BIO_new_file("signer.pem", "r"); + /* Read in recipient certificate */ + tbio = BIO_new_file("signer.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - if (!rcert) - goto err; + if (!rcert) + goto err; - /* Create recipient STACK and add recipient cert to it */ - recips = sk_X509_new_null(); + /* Create recipient STACK and add recipient cert to it */ + recips = sk_X509_new_null(); - if (!recips || !sk_X509_push(recips, rcert)) - goto err; + if (!recips || !sk_X509_push(recips, rcert)) + goto err; - /* sk_X509_pop_free will free up recipient STACK and its contents - * so set rcert to NULL so it isn't freed up twice. - */ - rcert = NULL; + /* + * sk_X509_pop_free will free up recipient STACK and its contents so set + * rcert to NULL so it isn't freed up twice. + */ + rcert = NULL; - /* Open content being encrypted */ + /* Open content being encrypted */ - in = BIO_new_file("encr.txt", "r"); + in = BIO_new_file("encr.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* encrypt content */ - cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags); + /* encrypt content */ + cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags); - if (!cms) - goto err; + if (!cms) + goto err; - out = BIO_new_file("smencr.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("smencr.txt", "w"); + if (!out) + goto err; - /* Write out S/MIME message */ - if (!SMIME_write_CMS(out, cms, in, flags)) - goto err; + /* Write out S/MIME message */ + if (!SMIME_write_CMS(out, cms, in, flags)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Encrypting Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Encrypting Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); - if (rcert) - X509_free(rcert); - if (recips) - sk_X509_pop_free(recips, X509_free); + if (cms) + CMS_ContentInfo_free(cms); + if (rcert) + X509_free(rcert); + if (recips) + sk_X509_pop_free(recips, X509_free); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (tbio) + BIO_free(tbio); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_sign.c b/demos/cms/cms_sign.c index 6823c34a0e..4bf85d1384 100644 --- a/demos/cms/cms_sign.c +++ b/demos/cms/cms_sign.c @@ -4,86 +4,85 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL; - X509 *scert = NULL; - EVP_PKEY *skey = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL; + X509 *scert = NULL; + EVP_PKEY *skey = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - /* For simple S/MIME signing use CMS_DETACHED. - * On OpenSSL 1.0.0 only: - * for streaming detached set CMS_DETACHED|CMS_STREAM - * for streaming non-detached set CMS_STREAM - */ - int flags = CMS_DETACHED|CMS_STREAM; + /* + * For simple S/MIME signing use CMS_DETACHED. On OpenSSL 1.0.0 only: for + * streaming detached set CMS_DETACHED|CMS_STREAM for streaming + * non-detached set CMS_STREAM + */ + int flags = CMS_DETACHED | CMS_STREAM; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Read in signer certificate and private key */ - tbio = BIO_new_file("signer.pem", "r"); + /* Read in signer certificate and private key */ + tbio = BIO_new_file("signer.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + BIO_reset(tbio); - skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); + skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); - if (!scert || !skey) - goto err; + if (!scert || !skey) + goto err; - /* Open content being signed */ + /* Open content being signed */ - in = BIO_new_file("sign.txt", "r"); + in = BIO_new_file("sign.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* Sign content */ - cms = CMS_sign(scert, skey, NULL, in, flags); + /* Sign content */ + cms = CMS_sign(scert, skey, NULL, in, flags); - if (!cms) - goto err; + if (!cms) + goto err; - out = BIO_new_file("smout.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("smout.txt", "w"); + if (!out) + goto err; - if (!(flags & CMS_STREAM)) - BIO_reset(in); + if (!(flags & CMS_STREAM)) + BIO_reset(in); - /* Write out S/MIME message */ - if (!SMIME_write_CMS(out, cms, in, flags)) - goto err; + /* Write out S/MIME message */ + if (!SMIME_write_CMS(out, cms, in, flags)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Signing Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Signing Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); - if (scert) - X509_free(scert); - if (skey) - EVP_PKEY_free(skey); + if (cms) + CMS_ContentInfo_free(cms); + if (scert) + X509_free(scert); + if (skey) + EVP_PKEY_free(skey); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (tbio) + BIO_free(tbio); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_sign2.c b/demos/cms/cms_sign2.c index 36adee7304..7e98a51713 100644 --- a/demos/cms/cms_sign2.c +++ b/demos/cms/cms_sign2.c @@ -4,100 +4,99 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL; - X509 *scert = NULL, *scert2 = NULL; - EVP_PKEY *skey = NULL, *skey2 = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL; + X509 *scert = NULL, *scert2 = NULL; + EVP_PKEY *skey = NULL, *skey2 = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - tbio = BIO_new_file("signer.pem", "r"); + tbio = BIO_new_file("signer.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + BIO_reset(tbio); - skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); + skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); - BIO_free(tbio); + BIO_free(tbio); - tbio = BIO_new_file("signer2.pem", "r"); + tbio = BIO_new_file("signer2.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL); + scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + BIO_reset(tbio); - skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); + skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); - if (!scert2 || !skey2) - goto err; + if (!scert2 || !skey2) + goto err; - in = BIO_new_file("sign.txt", "r"); + in = BIO_new_file("sign.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM|CMS_PARTIAL); + cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM | CMS_PARTIAL); - if (!cms) - goto err; + if (!cms) + goto err; - /* Add each signer in turn */ + /* Add each signer in turn */ - if (!CMS_add1_signer(cms, scert, skey, NULL, 0)) - goto err; + if (!CMS_add1_signer(cms, scert, skey, NULL, 0)) + goto err; - if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0)) - goto err; + if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0)) + goto err; - out = BIO_new_file("smout.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("smout.txt", "w"); + if (!out) + goto err; - /* NB: content included and finalized by SMIME_write_CMS */ + /* NB: content included and finalized by SMIME_write_CMS */ - if (!SMIME_write_CMS(out, cms, in, CMS_STREAM)) - goto err; + if (!SMIME_write_CMS(out, cms, in, CMS_STREAM)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Signing Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Signing Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); + if (cms) + CMS_ContentInfo_free(cms); - if (scert) - X509_free(scert); - if (skey) - EVP_PKEY_free(skey); + if (scert) + X509_free(scert); + if (skey) + EVP_PKEY_free(skey); - if (scert2) - X509_free(scert2); - if (skey) - EVP_PKEY_free(skey2); + if (scert2) + X509_free(scert2); + if (skey) + EVP_PKEY_free(skey2); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (tbio) + BIO_free(tbio); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_uncomp.c b/demos/cms/cms_uncomp.c index f15ae2f132..392f4b4502 100644 --- a/demos/cms/cms_uncomp.c +++ b/demos/cms/cms_uncomp.c @@ -4,53 +4,52 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL; - CMS_ContentInfo *cms = NULL; - int ret = 1; +{ + BIO *in = NULL, *out = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Open compressed content */ + /* Open compressed content */ - in = BIO_new_file("smcomp.txt", "r"); + in = BIO_new_file("smcomp.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* Sign content */ - cms = SMIME_read_CMS(in, NULL); + /* Sign content */ + cms = SMIME_read_CMS(in, NULL); - if (!cms) - goto err; + if (!cms) + goto err; - out = BIO_new_file("smuncomp.txt", "w"); - if (!out) - goto err; + out = BIO_new_file("smuncomp.txt", "w"); + if (!out) + goto err; - /* Uncompress S/MIME message */ - if (!CMS_uncompress(cms, out, NULL, 0)) - goto err; + /* Uncompress S/MIME message */ + if (!CMS_uncompress(cms, out, NULL, 0)) + goto err; - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Uncompressing Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Uncompressing Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); + if (cms) + CMS_ContentInfo_free(cms); - if (in) - BIO_free(in); - if (out) - BIO_free(out); + if (in) + BIO_free(in); + if (out) + BIO_free(out); - return ret; + return ret; - } +} diff --git a/demos/cms/cms_ver.c b/demos/cms/cms_ver.c index bf1145ed8b..ca935517a7 100644 --- a/demos/cms/cms_ver.c +++ b/demos/cms/cms_ver.c @@ -4,84 +4,82 @@ #include <openssl/err.h> int main(int argc, char **argv) - { - BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL; - X509_STORE *st = NULL; - X509 *cacert = NULL; - CMS_ContentInfo *cms = NULL; +{ + BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL; + X509_STORE *st = NULL; + X509 *cacert = NULL; + CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = 1; - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - /* Set up trusted CA certificate store */ + /* Set up trusted CA certificate store */ - st = X509_STORE_new(); + st = X509_STORE_new(); - /* Read in CA certificate */ - tbio = BIO_new_file("cacert.pem", "r"); + /* Read in CA certificate */ + tbio = BIO_new_file("cacert.pem", "r"); - if (!tbio) - goto err; + if (!tbio) + goto err; - cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - if (!cacert) - goto err; + if (!cacert) + goto err; - if (!X509_STORE_add_cert(st, cacert)) - goto err; + if (!X509_STORE_add_cert(st, cacert)) + goto err; - /* Open message being verified */ + /* Open message being verified */ - in = BIO_new_file("smout.txt", "r"); + in = BIO_new_file("smout.txt", "r"); - if (!in) - goto err; + if (!in) + goto err; - /* parse message */ - cms = SMIME_read_CMS(in, &cont); + /* parse message */ + cms = SMIME_read_CMS(in, &cont); - if (!cms) - goto err; + if (!cms) + goto err; - /* File to output verified content to */ - out = BIO_new_file("smver.txt", "w"); - if (!out) - goto err; + /* File to output verified content to */ + out = BIO_new_file("smver.txt", "w"); + if (!out) + goto err; - if (!CMS_verify(cms, NULL, st, cont, out, 0)) - { - fprintf(stderr, "Verification Failure\n"); - goto err; - } + if (!CMS_verify(cms, NULL, st, cont, out, 0)) { + fprintf(stderr, "Verification Failure\n"); + goto err; + } - fprintf(stderr, "Verification Successful\n"); + fprintf(stderr, "Verification Successful\n"); - ret = 0; + ret = 0; - err: + err: - if (ret) - { - fprintf(stderr, "Error Verifying Data\n"); - ERR_print_errors_fp(stderr); - } + if (ret) { + fprintf(stderr, "Error Verifying Data\n"); + ERR_print_errors_fp(stderr); + } - if (cms) - CMS_ContentInfo_free(cms); + if (cms) + CMS_ContentInfo_free(cms); - if (cacert) - X509_free(cacert); + if (cacert) + X509_free(cacert); - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + if (tbio) + BIO_free(tbio); - return ret; + return ret; - } +} |