CMS_COMPRESS(3ossl)
π 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, orNID_undefif 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, ifCMS_BINARYis set, thenCMS_TEXTis simply ignored. it's not even a rivalry,CMS_BINARYjust 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 flagCMS_STREAMis set, the returnedCMS_ContentInfostructure is not complete. if you output its contents via a function that doesn't properly finalize theCMS_ContentInfostructure, 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 π
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
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms