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β theBIOwhere the data gets written. the output runway. πvalueβ the appropriateASN1_VALUEstructure, and that's eitherCMS_ContentInfoorPKCS7. 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 datadigestAlgorithms.itβ the ASN.1 structure. the valid values you can use here areASN1_ITEM_rptr(PKCS7)orASN1_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 functionsSMIME_write_CMS(3)andSMIME_write_PKCS7(3)should be used instead ofSMIME_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 forSignedDatawhereCMS_DETACHEDis also set when thesign()method is called. it's a matching-set situation, okay? β¨CMS_TEXTβ if this is set, MIME headers for typetext/plainare added to the content. this only makes sense ifCMS_DETACHEDis also set. again: matching set. πCMS_STREAMβ if this is set, streaming is performed. this flag should only be set ifCMS_STREAMwas also set in the previous call to aCMS_ContentInfoorPKCS7creation function. do not freestyle this one. π€
and now the fine print, because facts are facts:
- 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. 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 π
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
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms