CMS_COMPRESS(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… CMS_COMPRESS (3ossl) πŸ’…

okay bestie so we're doing the CMS_compress page from the OpenSSL manual, third section, and honestly? it's giving "small function, big responsibilities" energy. let's get into it ✨


🌸 NAME 🌸

CMS_compress β€” literally just creates a CMS CompressedData structure. that's the whole job. iconic of it, honestly πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <openssl/cms.h>

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

✨ DESCRIPTION ✨

so CMS_compress() creates and returns a CMS CompressedData structure. that's the main character move.

  • comp_nid β€” the compression algorithm you wanna use, or NID_undef if you want the default algorithm (which is zlib compression, no cap). 🫢
  • in β€” the content that's getting compressed. that's your material, bestie.
  • flags β€” an optional set of flags. the sprinkle on top. ✨

lowkey important: the only currently supported compression algorithm is zlib, using the NID NID_zlib_compression. that's it. that's the whole menu. πŸ’€

and listen β€” if zlib support is not compiled into OpenSSL, then CMS_compress() will return an error. so like, vibe check your build first, fr fr. 😭

if the CMS_TEXT flag is set, MIME headers for type text/plain get prepended to the data. cute little header moment πŸ’Œ

normally, the supplied content gets translated into MIME canonical format (as required by the S/MIME specifications). but β€” plot twist β€” if CMS_BINARY is set, no translation occurs. so you should use this option if your supplied data is in binary format, otherwise that translation will straight up corrupt it. not dramatic, just true. πŸ™ˆ

⚠️ also, if CMS_BINARY is set, then CMS_TEXT is simply ignored. it's not even a rivalry, CMS_BINARY just wins. periodt.

if the CMS_STREAM flag is set, you get back a partial CMS_ContentInfo structure β€” one that's suitable for streaming I/O. and by "partial" we mean no data is read from the BIO in. zero. none. it's just vibes until later. 🌈

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(). so like, it exists, but it's giving deprecated-party-guest. πŸ’€

⚠️ big one, bestie: if the flag CMS_STREAM is set, the returned CMS_ContentInfo structure is not complete. if you output its contents via a function that doesn't properly finalize the CMS_ContentInfo structure, you will get unpredictable results. that's the scary kind of "unpredictable." handle it. 😭

several functions do 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(). iykyk 🧚

and one lil limitation that's lowkey a bummer: additional compression parameters, such as the zlib compression level, cannot currently be set. so no fine-tuning, bestie. we work with what we've got. πŸ“


πŸ”₯ RETURN VALUES πŸ”₯

CMS_compress() returns either a CMS_ContentInfo structure, or NULL if an error occurred. and the error can be obtained from ERR_get_error(3). gotta check your errors, always, no exceptions πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, bestie, they're the supporting cast 🫢


⭐ HISTORY ⭐

the CMS_STREAM flag was added in OpenSSL 1.0.0. so it's been around a minute. an OG. πŸŽ€


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!! πŸ’– this lil beauty is from OpenSSL 3.5.6, dated 2026-04-07, and it lives in section 3ossl of the manual. go compress something iconic. slay πŸ¦‹βœ¨

πŸ“¦ where this page comes from