---
name: "libressl-SMIME_write_CMS"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SMIME_write_CMS"
---

# libressl-SMIME\_write\_CMS(3)

convert CMS structure to S/MIME format

## NAME

**SMIME\_write\_CMS** – convert CMS structure to S/MIME format

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/cms.h\>**

*int*\

**SMIME\_write\_CMS**(*BIO \*out*, *CMS\_ContentInfo \*cms*, *BIO \*data*, *int flags*);

## DESCRIPTION

**SMIME\_write\_CMS**() generates an S/MIME message on *out* by writing MIME 1.0 headers followed by a BER- and base64-encoded serialization of *cms*. The BER encoding uses the DER format except as described for CMS\_STREAM below. If streaming is enabled, the content must be supplied in the *data* argument.

The *flags* can be the logical OR of zero or more of the following bits:

- CMS\_DETACHED

  Use cleartext signing and generate a "multipart/signed" S/MIME message. The content is read from *data*. If *data* is a NULL pointer, this flag is ignored.

  This flag is only supported if *cms* is of the type *SignedData* and CMS\_DETACHED was also set when it was created with CMS\_sign(3).

  If CMS\_STREAM is not set, the data must be read twice: once to compute the signature in CMS\_sign(3) and once to output the S/MIME message.

  If CMS\_DETACHED is ignored or not specified, the smime-type is chosen according to CMS\_get0\_type(3):

  - NID\_pkcs7\_enveloped

    "enveloped-data"

  - NID\_pkcs7\_signed

    - "signed-receipt"

      if CMS\_get0\_eContentType(3) is NID\_id\_smime\_ct\_receipt

    - "signed-data"

      if *cms* specifies any digest algorithm

    - "certs-only"

      otherwise

  - NID\_id\_smime\_ct\_compressedData

    "compressed-data"

- CMS\_REUSE\_DIGEST

  Skip the calls to CMS\_dataInit(3) and CMS\_dataFinal(3). This flag has no effect unless CMS\_DETACHED is also set.

- CMS\_STREAM

  Perform streaming by reading the content from *data*. This only works if CMS\_DETACHED is not specified.

  This flag should only be set if CMS\_STREAM was also passed to the function that created *cms*.

  The content is output in BER format using indefinite length constructed encoding except in the case of *SignedData* with detached content where the content is absent and DER format is used.

- CMS\_TEXT

  Prepend the line "Content-Type: text/plain" to the content. This only makes sense if CMS\_DETACHED is also set. It is ignored if the flag SMIME\_BINARY is also set.

- SMIME\_BINARY

  If specified, this flag is passed through to SMIME\_crlf\_copy(3).

- SMIME\_CRLFEOL

  End MIME header lines with pairs of carriage return and newline characters. By default, no carriage return characters are written and header lines are ended with newline characters only.

## RETURN VALUES

**SMIME\_write\_CMS**() is intended to return 1 on success or 0 on failure.

## SEE ALSO

BIO\_f\_base64(3), BIO\_new(3), CMS\_ContentInfo\_new(3), CMS\_encrypt(3), CMS\_sign(3), d2i\_CMS\_ContentInfo(3), ERR\_get\_error(3), SMIME\_crlf\_copy(3), SMIME\_read\_CMS(3), SMIME\_write\_PKCS7(3)

## HISTORY

**SMIME\_write\_CMS**() first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 6.7.

## BUGS

**SMIME\_write\_CMS**() ignores most errors and is likely to return 1 even after producing corrupt or incomplete output.

**SMIME\_write\_CMS**() always base64 encodes CMS structures. There should be an option to disable this.
