SMIME_WRITE_CMS(3ossl)

✨ SMIME_WRITE_CMS πŸ’Œ

ok so bestie, meet SMIME_write_CMS β€” she's the one from the 3ossl manual fam whose whole job is turning a CMS structure into an actual S/MIME message. glow-up: applied. πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/cms.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so what she does is: she takes a CMS structure and slaps the appropriate MIME headers on top of it so it comes out looking like a real S/MIME message. it's giving ✨packaging queen✨.

Let's break down the cast:

  • out β€” the BIO you're writing the data to. that's the destination, the vibe.
  • cms β€” the CMS_ContentInfo structure in question. the actual main character.
  • data β€” if streaming is enabled, then the content must be supplied here. no content, no streaming, fr fr. πŸ™ˆ
  • flags β€” an optional set of flags. optional bestie, but she's got range, keep reading.

πŸ’– NOTES πŸ’–

so these are the flags you can pass in that flags parameter. take notes bestie, this is the good part:

  • If CMS_DETACHED is set, then cleartext signing will be used. lowkey this option only makes sense for SignedData where CMS_DETACHED is also set when CMS_sign() is called. like, they have to match, iykyk.
  • If the CMS_TEXT flag is set, MIME headers for type text/plain get added to the content. but this only makes sense if CMS_DETACHED is also set. otherwise she's just doing too much. πŸ’€
  • If the CMS_STREAM flag is set, streaming is performed. important: this flag should only be set if CMS_STREAM was also set in the previous call to a CMS_ContentInfo creation function. they gotta be in sync, periodt.
  • 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 bestie, twice. she's thorough like that. 😭
  • 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. not me remembering both of these... but you should 🫢

πŸ’€ BUGS πŸ’€

ok this is the part where we keep it real:

SMIME_write_CMS() always base64 encodes CMS structures. there should be an option to disable this, but there isn't. so. yeah. that's the tea. πŸ“

πŸ‘‘ RETURN VALUES πŸ‘‘

  • 1 for success ✨
  • 0 for failure 😭

that's it, that's the range.


🌈 SEE ALSO 🌈

go read these next, bestie, they're all in the group chat:


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 babe πŸ’œ this lil slice of OpenSSL is version 3.5.9, dated 2026-09-29, and she ate. no cap. 🫢✨

πŸ“¦ where this page comes from