SMIME_WRITE_PKCS7(3)
β¨ SMIME_WRITE_PKCS7(3) β¨
okay so this is from the Library Functions Manual, section 3, and the main character is SMIME_write_PKCS7. bestie, it is literally the βconvert PKCS#7 structure to S/MIME formatβ girlie. π
π NAME π
SMIME_write_PKCS7 β convert PKCS#7 structure to S/MIME format
π¦ SYNOPSIS π¦
library βlibcryptoβ #include <openssl/pkcs7.h>
int
SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags);
πΈ DESCRIPTION πΈ
SMIME_write_PKCS7() generates an S/MIME message on out by writing MIME 1.0 headers followed by a BER- and base64-encoded serialization of p7. The BER encoding uses the DER format except as described for PKCS7_STREAM below. If streaming is enabled, then the content must be supplied in the data argument.
The flags can be the logical OR of zero or more of the following bits:
PKCS7_DETACHEDβ use cleartext signing and generate a"multipart/signed"S/MIME message. The content is read fromdata. Ifdatais aNULLpointer, this flag is ignored.
This flag is only supported for signedData where PKCS7_DETACHED is also set when PKCS7_sign(3) is called.
If PKCS7_STREAM is not set, the data must be read twice: once to compute the signature in PKCS7_sign(3) and once to output the S/MIME message.
If PKCS7_DETACHED is ignored or not specified, the smime-type is chosen according to the type of p7:
NID_pkcs7_envelopedβ"enveloped-data"NID_pkcs7_signedβ"signed-data"ifp7specifies any digest algorithm;"certs-only"otherwiseNID_id_smime_ct_compressedDataβ"compressed-data"
PKCS7_REUSE_DIGESTβ skip the calls toPKCS7_dataInit(3)andPKCS7_dataFinal(3). This flag has no effect unlessPKCS7_DETACHEDis also set.PKCS7_STREAMβ perform streaming by reading the content fromdata. This only works ifPKCS7_DETACHEDis not specified.
This flag should only be set if PKCS7_STREAM was also set in the previous call to PKCS7_sign(3) or PKCS7_encrypt(3).
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.
PKCS7_TEXTβ prepend the line"Content-Type: text/plain"to the content. This only makes sense ifPKCS7_DETACHEDis also set. It is ignored if the flagSMIME_BINARYis also set.SMIME_BINARYβ if specified, this flag is passed through toSMIME_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.SMIME_OLDMIMEβ if this bit is set in theflagsargument,"application/pkcs7-mime"or"application/pkcs7-signature"is used in Content-Type headers. Otherwise,"application/x-pkcs7-mime"or"application/x-pkcs7-signature"is used.
π RETURN VALUES π
so the intention, the vibe, the dream: SMIME_write_PKCS7() is intended to return 1 on success or 0 on failure. yes bestie, intended β see the BUGS section for the messy part. π
π SEE ALSO π
BIO_f_base64(3)BIO_new(3)i2d_PKCS7_bio_stream(3)PEM_write_bio_PKCS7_stream(3)PEM_write_PKCS7(3)PKCS7_final(3)PKCS7_new(3)SMIME_crlf_copy(3)SMIME_read_PKCS7(3)SMIME_write_CMS(3)
π°οΈ HISTORY π°οΈ
SMIME_write_PKCS7() first appeared in OpenSSL 0.9.5 and has been available since OpenBSD 2.7. cute legacy moment, no cap. π
π BUGS π
bestie, listen: this function ignores most errors and is likely to return 1 even after producing corrupt or incomplete output. that is not a drill. π¨
SMIME_write_PKCS7() always base64 encodes PKCS#7 structures. There should be an option to disable this.
source/version: Debian Β· date: June 11, 2025 Β· this was the SMIME_WRITE_PKCS7(3) page β bye bestie, mwah π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021, 2025 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2002, 2003, 2006, 2007, 2015 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms