CMS_COMPRESS(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… CMS_compress β€” create a CMS CompressedData structure πŸ’…

okay bestie, welcome to the CMS_COMPRESS(3ossl) page ✨ this is the OpenSSL manual for CMS_compress(), and it's lowkey the glow-up moment where you make a CMS CompressedData structure. no cap, the facts below are all main-character.

🌸 SYNOPSIS 🌸

#include <openssl/cms.h>

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

✨ DESCRIPTION ✨

CMS_compress() creates and returns a CMS_ContentInfo structure, and it's giving CompressedData energy πŸ’– comp_nid is the compression algorithm to use, or NID_undef to use the default algorithm (which is zlib compression). in is the content to be compressed. flags is an optional set of flags. periodt.

The only currently supported compression algorithm is zlib using the NID NID_zlib_compression. iykyk.

if zlib support is not compiled into OpenSSL, then CMS_compress() will return an error. not me finding out when it errors 😭

Now the flag vibe check:

  • CMS_TEXT β€” when this flag is set, MIME headers for type text/plain are prepended to the data. cute.
  • CMS_BINARY β€” 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 if the supplied data is in binary format, otherwise the translation will corrupt it πŸ’€ also, if CMS_BINARY is set, then CMS_TEXT is ignored.
  • CMS_STREAM β€” if this flag is set, a partial CMS_ContentInfo structure is returned that's suitable for streaming I/O: no data is read from the BIO in. iconic behavior.
  • CMS_DETACHED β€” the compressed data is included in the CMS_ContentInfo structure unless CMS_DETACHED is set, in which case it's omitted. this is rarely used in practice and is not supported by SMIME_write_CMS(). noted 🫢
⚠️ if the flag CMS_STREAM is set, the returned CMS_ContentInfo structure is not complete. outputting its contents via a function that doesn't properly finalize the CMS_ContentInfo structure will give unpredictable results. that's the drama we don't want.

Several functions finalize the structure, including SMIME_write_CMS(), i2d_CMS_bio_stream(), and PEM_write_bio_CMS_stream(). alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly using BIO_new_CMS(). slay.

Additional compression parameters such as the zlib compression level cannot currently be set. sad, but true.

πŸ’– RETURN VALUES πŸ’–

CMS_compress() returns either a CMS_ContentInfo structure or NULL if an error occurred. the error can be obtained from ERR_get_error(3). no guessing, bestie.

🌈 SEE ALSO 🌈

ERR_get_error(3), CMS_uncompress(3)

πŸ¦‹ HISTORY πŸ¦‹

The CMS_STREAM flag was added in OpenSSL 1.0.0. a little throwback ✨

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

stay compressed, bestie πŸ’… this page is from OpenSSL 3.5.0, dated 2026-09-25.

πŸ“¦ where this page comes from