SMIME_WRITE_ASN1(3ossl)

✨ SMIME_WRITE_ASN1 πŸ’…

okay so bestie, gather round, because today we're talking about SMIME_write_ASN1_ex and SMIME_write_ASN1 β€” the OpenSSL girlies whose whole job is converting a structure into S/MIME format. it's giving "glow up for your ASN.1" and honestly? we're obsessed. πŸŽ€


🌸 NAME 🌸

SMIME_write_ASN1_ex, SMIME_write_ASN1 β€” convert structure to S/MIME format. that's it. that's the whole job description. πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <openssl/asn1.h>

int SMIME_write_ASN1_ex(BIO *out, ASN1_VALUE *val, BIO *data, int flags,
                        int ctype_nid, int econt_nid,
                        STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it,
                        OSSL_LIB_CTX *libctx, const char *propq);

int SMIME_write_ASN1(BIO *out,
    ASN1_VALUE *val, BIO *data, int flags, int ctype_nid, int econt_nid,
    STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it);

two functions, one vibe, zero notes. slay. ✨


πŸ’– DESCRIPTION πŸ’–

so SMIME_write_ASN1_ex() is the main character here: it adds the appropriate MIME headers to an object structure to produce an S/MIME message. literally just dressing your object up in its cutest MIME fit. πŸ‘‘

let's break down the cast, because everyone has a role:

  • out β€” the BIO where the data gets written. the output runway. πŸ’…
  • value β€” the appropriate ASN1_VALUE structure, and that's either CMS_ContentInfo or PKCS7. no substitutions, bestie.
  • data β€” if streaming is enabled, then the content must be supplied through here. no data, no stream, no message. 😭
  • flags β€” an optional set of flags. we'll get to those, don't worry. πŸŽ€
  • ctype_nid β€” the NID of the content type.
  • econt_nid β€” the NID of the embedded content type.
  • mdalgs β€” a list of signed data digestAlgorithms.
  • it β€” the ASN.1 structure. the valid values you can use here are ASN1_ITEM_rptr(PKCS7) or ASN1_ITEM_rptr(CMS_ContentInfo). that's the whole guest list, no plus-ones.
  • libctx β€” the library context.
  • propq β€” the property query. both of these get used when retrieving algorithms from providers. 🧚

🌈 NOTES 🌈

lowkey important: the higher level functions SMIME_write_CMS(3) and SMIME_write_PKCS7(3) should be used instead of SMIME_write_ASN1(). like, bestie, use the glow-up versions. this is the raw one. πŸ™ˆ

the following flags can be passed in the flags parameter β€” here's the tea on each of them:

  • CMS_DETACHED β€” if this is set, then cleartext signing will be used. but heads up, this option only makes sense for SignedData where CMS_DETACHED is also set when the sign() method is called. it's a matching-set situation, okay? ✨
  • CMS_TEXT β€” if this is set, MIME headers for type text/plain are added to the content. this only makes sense if CMS_DETACHED is also set. again: matching set. πŸ’…
  • CMS_STREAM β€” if this is set, streaming is performed. this flag should only be set if CMS_STREAM was also set in the previous call to a CMS_ContentInfo or PKCS7 creation function. do not freestyle this one. 😀

and now the fine print, because facts are facts:

  • 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 the sign method, and once to output the S/MIME message. yes, twice. it's a lot of work but she does it. 😭
  • 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. exceptions are iconic, periodt. πŸ‘‘

⭐ RETURN VALUES ⭐

both SMIME_write_ASN1_ex() and SMIME_write_ASN1() return 1 for success or 0 for failure. simple as that, no cap. πŸ’–


🫢 SEE ALSO 🫢

go read these next bestie, they're the supporting cast. 🌸


Copyright 2020 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 the SMIME_WRITE_ASN1(3ossl) manual, version 3.5.9, dated 2026-09-29, straight from the OpenSSL girlies themselves. go forth and write your ASN.1 with main character energy. mwah. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from