SMIME_WRITE_CMS(3SSL)

πŸ’– SMIME_WRITE_CMS β€” the OpenSSL 3SSL manual, but make it make sense πŸ’–

okay bestie, gather round, because today we're talking about SMIME_write_CMS, and she's from the OpenSSL family of manual pages, section 3SSL. literally the glow-up machine that takes your raw CMS structure and dresses it up all pretty in S/MIME format. periodt. πŸŽ€


✨ NAME ✨

SMIME_write_CMS β€” convert CMS structure to S/MIME format


🌸 SYNOPSIS 🌸

#include <openssl/cms.h>

int SMIME_write_CMS(BIO *out, CMS_ContentInfo *cms, BIO *data, int flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: SMIME_write_CMS() takes a CMS structure and slaps the appropriate MIME headers onto it, which is how you get a whole S/MIME message. it's giving "I woke up and chose formatting." πŸ’…

out is the BIO where the data gets written to. cms is the relevant CMS_ContentInfo structure, aka the main character. and if streaming is enabled, you have to hand over the content in the data argument. flags is an optional set of flags β€” optional, but iconic. ✨


πŸ‘‘ NOTES πŸ‘‘

you can pass the following flags in that flags parameter. buckle up, we're going one by one:

  • if CMS_DETACHED is set, cleartext signing gets used. ngl this option only makes sense for SignedData, and only when CMS_DETACHED was also set back when CMS_sign() was called. they gotta match, fr fr.
  • if the CMS_TEXT flag is set, MIME headers for type text/plain get added to the content. again, this only makes sense if CMS_DETACHED is also set. them's the rules.
  • if the CMS_STREAM flag is set, streaming is performed. super important: only set this if CMS_STREAM was also set in the previous call to a CMS_ContentInfo creation function. don't be out here setting flags alone, bestie. 🫢
  • if cleartext signing is being used and CMS_STREAM is not set, then the data must be read twice: once to compute the signature in CMS_sign(), and once to output the S/MIME message. yes, twice. it's giving cardio. 😭
  • if streaming is performed, the content is output in BER format using indefinite length constructed encoding β€” except in the case of signed data with detached content, where the content is absent and DER format is used instead. 🧚

πŸ’€ BUGS πŸ’€

real talk: SMIME_write_CMS() always base64 encodes CMS structures. there should be an option to disable this, and there isn't. we live in a society. πŸ™ˆ


⭐ RETURN VALUES ⭐

SMIME_write_CMS() returns 1 for success or 0 for failure. simple as that. slay.


🌈 SEE ALSO 🌈

ERR_get_error(3), CMS_sign(3), CMS_verify(3), CMS_encrypt(3) CMS_decrypt(3)


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 was version 4.0.3, dated 2026-09-29, straight from the SMIME_WRITE_CMS(3SSL) manual. go forth and MIME responsibly. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from