SMIME_WRITE_ASN1(3SSL)
๐ SMIME_WRITE_ASN1 ๐
okay bestie, so this is the SMIME_write_ASN1 page from the OpenSSL manual (section 3SSL, obvi) and it's literally about turning your lil object structure into a whole S/MIME message. it's giving mail-formatting main character energy ๐
โจ NAME โจ
SMIME_write_ASN1_ex, SMIME_write_ASN1 โ convert structure to S/MIME format ๐ฆ
๐ 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);
๐ธ DESCRIPTION ๐ธ
so SMIME_write_ASN1_ex() literally, no cap, adds the appropriate MIME headers to an object structure so you get an S/MIME message out the other side. it's the glow-up from "raw structure" to "sendable message" ๐
here's the breakdown, bestie:
outis theBIOyou're writing the data to.valueis the appropriateASN1_VALUEstructure โ so eitherCMS_ContentInfoorPKCS7. if streaming is enabled, then the content has to be supplied viadata.flagsis an optional set of flags. (optional bestie, but iconic.)ctype_nidis the NID of the content type.econt_nidis the NID of the embedded content type.mdalgsis a list of signed datadigestAlgorithms.- valid values that the ASN.1 structure
itcan use areASN1_ITEM_rptr(PKCS7)orASN1_ITEM_rptr(CMS_ContentInfo). - the library context
libctxand the property querypropqget used when retrieving algorithms from providers. ๐ฎ
๐ NOTES ๐
real talk: the higher level functionsSMIME_write_CMS(3)andSMIME_write_PKCS7(3)should be used instead ofSMIME_write_ASN1(). like, just use those, bestie, they're right there ๐
the following flags can be passed in the flags parameter:
- if
CMS_DETACHEDis set then cleartext signing will be used. this option only makes sense forSignedDatawhereCMS_DETACHEDis also set when thesign()method is called. (both or it doesn't count, periodt.) - if the
CMS_TEXTflag is set, MIME headers for typetext/plainare added to the content. this only makes sense ifCMS_DETACHEDis also set. - if the
CMS_STREAMflag is set, streaming is performed. this flag should only be set ifCMS_STREAMwas also set in the previous call to aCMS_ContentInfoorPKCS7creation function. don't be out here setting it randomly ๐ญ - if cleartext signing is being used and
CMS_STREAMis not set, then the data must be read twice: once to compute the signature in thesignmethod, and once to output the S/MIME message. yeah. twice. iconic but expensive ๐ - 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. very specific, very demure โจ
๐ซถ RETURN VALUES ๐ซถ
SMIME_write_ASN1_ex() and SMIME_write_ASN1() return 1 for success or 0 for failure. that's it, that's the vibe check. 1 = slay, 0 = not slay ๐ญ
๐ SEE ALSO ๐
go read those too, bestie, they're the supporting cast ๐ง
๐ COPYRIGHT ๐
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, fr fr ๐ this was SMIME_WRITE_ASN1 from OpenSSL version 4.0.3, dated 2026-09-29 โ mwah, stan, go write some S/MIME messages bestie ๐
โจ
๐ฆ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms