summaryrefslogtreecommitdiff
path: root/apps/enc.c
diff options
context:
space:
mode:
authorTodd Short <tshort@akamai.com>2021-08-09 16:56:29 -0400
committerTodd Short <todd.short@me.com>2022-10-18 09:30:18 -0400
commit12e96a23604a7aa1cd8f83486b02f1bcab6d468f (patch)
tree0b6be9589eaab31798122128c1237d40bff9bfe2 /apps/enc.c
parent846975f367f75f3503b44c12e49d980dca181647 (diff)
downloadopenssl-new-12e96a23604a7aa1cd8f83486b02f1bcab6d468f.tar.gz
Add brotli compression support (RFC7924)
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18186)
Diffstat (limited to 'apps/enc.c')
-rw-r--r--apps/enc.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/apps/enc.c b/apps/enc.c
index 26ad3deb9a..4da2342791 100644
--- a/apps/enc.c
+++ b/apps/enc.c
@@ -134,6 +134,8 @@ int enc_main(int argc, char **argv)
int do_zlib = 0;
BIO *bzl = NULL;
#endif
+ int do_brotli = 0;
+ BIO *bbrot = NULL;
/* first check the command name */
if (strcmp(argv[0], "base64") == 0)
@@ -142,6 +144,10 @@ int enc_main(int argc, char **argv)
else if (strcmp(argv[0], "zlib") == 0)
do_zlib = 1;
#endif
+#ifndef OPENSSL_NO_BROTLI
+ else if (strcmp(argv[0], "brotli") == 0)
+ do_brotli = 1;
+#endif
else if (strcmp(argv[0], "enc") != 0)
ciphername = argv[0];
@@ -321,14 +327,18 @@ int enc_main(int argc, char **argv)
BIO_printf(bio_err, "bufsize=%d\n", bsize);
#ifdef ZLIB
- if (!do_zlib)
+ if (do_zlib)
+ base64 = 0;
#endif
- if (base64) {
- if (enc)
- outformat = FORMAT_BASE64;
- else
- informat = FORMAT_BASE64;
- }
+ if (do_brotli)
+ base64 = 0;
+
+ if (base64) {
+ if (enc)
+ outformat = FORMAT_BASE64;
+ else
+ informat = FORMAT_BASE64;
+ }
strbuf = app_malloc(SIZE, "strbuf");
buff = app_malloc(EVP_ENCODE_LENGTH(bsize), "evp buffer");
@@ -398,7 +408,8 @@ int enc_main(int argc, char **argv)
rbio = in;
wbio = out;
-#ifdef ZLIB
+#ifndef OPENSSL_NO_COMP
+# ifdef ZLIB
if (do_zlib) {
if ((bzl = BIO_new(BIO_f_zlib())) == NULL)
goto end;
@@ -411,6 +422,20 @@ int enc_main(int argc, char **argv)
else
rbio = BIO_push(bzl, rbio);
}
+# endif
+
+ if (do_brotli) {
+ if ((bbrot = BIO_new(BIO_f_brotli())) == NULL)
+ goto end;
+ if (debug) {
+ BIO_set_callback_ex(bbrot, BIO_debug_callback_ex);
+ BIO_set_callback_arg(bbrot, (char *)bio_err);
+ }
+ if (enc)
+ wbio = BIO_push(bbrot, wbio);
+ else
+ rbio = BIO_push(bbrot, rbio);
+ }
#endif
if (base64) {
@@ -656,6 +681,7 @@ int enc_main(int argc, char **argv)
#ifdef ZLIB
BIO_free(bzl);
#endif
+ BIO_free(bbrot);
release_engine(e);
OPENSSL_free(pass);
return ret;