CMS_COMPRESS(3SSL)

πŸ’– CMS_COMPRESS πŸ’–

okay so bestie, welcome to CMS_compress(3SSL) β€” that's the OpenSSL manual, section 3SSL, and it's literally the glow-up button for your data. i'm your group-chat Unix bestie and today we are compressing things. buckle up πŸŽ€


✨ NAME ✨

CMS_compress β€” creates a CMS CompressedData structure πŸ’… (yes that's the whole job, and she does it flawlessly)


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <openssl/cms.h>

CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);

🌸 DESCRIPTION 🌸

okay so CMS_compress() creates and returns a CMS CompressedData structure. that's it, that's the whole main character moment. ✨

  • comp_nid β€” the compression algorithm to use, OR NID_undef if you want the default algorithm (that's zlib compression, bestie, the classic).
  • in β€” the content to be compressed. give her the goods 🫢
  • flags β€” an optional set of flags. optional!! girlies love options.

the only currently supported compression algorithm is zlib, using the NID NID_zlib_compression. that's it. no others. don't come for her with alternatives, she's not taking applications. πŸ’€

⚠️ if zlib support is not compiled into OpenSSL then CMS_compress() will return an error. no zlib = no slay. 😭

if the CMS_TEXT flag is set, MIME headers for type text/plain are prepended to the data. cute little hat for your data, iconic. πŸ‘‘

normally the supplied content is translated into MIME canonical format (as required by the S/MIME specifications). but if CMS_BINARY is set, no translation occurs. use this one if your supplied data is in binary format β€” otherwise the translation will corrupt it. like, actually corrupt it. not cute. πŸ™ˆ and heads up: if CMS_BINARY is set, then CMS_TEXT is ignored. she said pick a lane.

if the CMS_STREAM flag is set, a partial CMS_ContentInfo structure is returned, suitable for streaming I/O β€” meaning no data is read from the BIO in. she's just standing there, ready, not reading anything yet. ✨

the compressed data is included in the CMS_ContentInfo structure, unless CMS_DETACHED is set, in which case it is omitted. this is rarely used in practice and is not supported by SMIME_write_CMS(). fr fr, that combo?? not it. πŸ’€

⚠️ if the flag CMS_STREAM is set, the returned CMS_ContentInfo structure is not complete, and outputting its contents via a function that does not properly finalize the CMS_ContentInfo structure will give unpredictable results. like, undefined-vibes unpredictable. handle with care bestie, this is not a drill. 😭

several functions finalize the structure, including:

  • SMIME_write_CMS()
  • i2d_CMS_bio_stream()
  • PEM_write_bio_CMS_stream()

alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly using BIO_new_CMS(). your choice, queen. 🫢

additional compression parameters β€” such as the zlib compression level β€” cannot currently be set. so no, you can't turn the knob. she picked the level herself and she's not taking notes. πŸ’…


πŸ‘‘ RETURN VALUES πŸ‘‘

CMS_compress() returns either a CMS_ContentInfo structure, or NULL if an error occurred. if you got NULL, grab the tea from ERR_get_error(3). that's where the lore lives. πŸ“


🌈 SEE ALSO 🌈


⭐ HISTORY ⭐

the CMS_STREAM flag was added in OpenSSL 1.0.0. vintage behavior, still eating. πŸ”₯


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>.


and that's the whole page bestie!! ✨ shoutout to the manpage for OpenSSL 4.0.3, dated 2026-09-29 β€” that's the version, that's the date, and that's her sign-off. go compress something pretty πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from