CMS_COMPRESS(3ossl)
π CMS_COMPRESS π (that's the CMS_COMPRESS(3ossl) page bestie, yes it's an OpenSSL one)
okay so you want to squish some data down into a lil compressed blob for CMS? say less. this is the page for CMS_compress, and we're gonna get you all the way together. grab a snack π
β¨ SYNOPSIS β¨
#include <openssl/cms.h>
CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
πΈ DESCRIPTION πΈ
So CMS_compress() does the thing: it creates and returns a CMS CompressedData structure. iconic behaviour honestly.
Here's the cast of characters:
inβ the content you wanna compress. that's the whole point bestie.comp_nidβ which compression algorithm you want. or you can passNID_undefand it'll just use the default algorithm, which is zlib compression. easy.flagsβ an optional lil set of flags. more on those below π
ngl the only compression algorithm supported right now is zlib, using the NID NID_zlib_compression. that's it. that's the list.
and heads up π«Ά if zlib support was not compiled into OpenSSL, then CMS_compress() will just return an error. no zlib, no vibes.
π the flags, let's go π
- if the
CMS_TEXTflag is set, MIME headers for typetext/plainget prepended to the data. cute lil header moment. - normally the content you hand over gets translated into MIME canonical format, because the S/MIME specifications literally require it. but if
CMS_BINARYis set, no translation happens. use this one when your data is in binary format, because otherwise that translation will corrupt it. π and btw, ifCMS_BINARYis set thenCMS_TEXTjust gets ignored. sorry toCMS_TEXT. - if
CMS_STREAMis set, you get back a partialCMS_ContentInfostructure that's suitable for streaming I/O. lowkey important: no data is read from the BIOinin that case. - the compressed data gets included in the
CMS_ContentInfostructure... unlessCMS_DETACHEDis set, in which case it's omitted. this is rarely used in practice and it's not supported bySMIME_write_CMS(). so like, iykyk. - if
CMS_STREAMis set, the returnedCMS_ContentInfostructure is not complete, and outputting its contents via a function that doesn't properly finalize it will give unpredictable results. not the fun kind of unpredictable.
π¦ so who finalizes it?? π¦
several functions do the finalizing for you:
SMIME_write_CMS()i2d_CMS_bio_stream()PEM_write_bio_CMS_stream()
or alternatively you can do the finalization yourself by obtaining the streaming ASN1 BIO directly using BIO_new_CMS(). main character energy, do it manually if you want β¨
also just so you know: additional compression parameters β like the zlib compression level β cannot currently be set. yeah. we know. we're also sad about it. π
π RETURN VALUES π
CMS_compress() returns either a CMS_ContentInfo structure, or NULL if an error occurred. and if you got NULL, you can go get the error from ERR_get_error(3). go check on it, she's waiting.
π SEE ALSO π
β HISTORY β
the CMS_STREAM flag was added in OpenSSL 1.0.0. throwback era.
π COPYRIGHT π
Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use 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>.
okay that's the whole page, you ate that π this was CMS_COMPRESS(3ossl) from OpenSSL 3.5.9, dated 2026-09-29 β slay, go compress something, and remember: no cap, always finalize your stream π«Άβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms