PKCS7_DATAFINAL(3)
π NAME π
okay bestie, welcome to the PKCS7_DATAFINAL(3) page from the Library Functions Manual β this is all about PKCS7_dataFinal, and its whole vibe is: move data from a BIO chain into a ContentInfo object. β¨π
π¦ SYNOPSIS π¦
library βlibcryptoβ #include <openssl/pkcs7.h>
int
PKCS7_dataFinal(PKCS7 *p7, BIO *chain);
πΈ DESCRIPTION πΈ
So the way that PKCS7_dataFinal() works is: it takes the data from the memory BIO at the end of the chain you hand it, and transfers that data into the appropriate content field of p7 itself or of its appropriate substructure. Itβs usually the final step of populating p7 β you create the chain with PKCS7_dataInit(3), write your data into it, and then call this. itβs giving βlast-step energyβ fr fr. π
After you call PKCS7_dataFinal(), your program can call BIO_free_all(3) on the chain, because these chains are literally not designed for reuse. no cap. π«Ά
Depending on the contentType of p7, PKCS7_dataFinal() sets these fields:
- for
SignedDataorDigestedDataβ in substructures of thecontentfield ofp7: thecontentfield in theContentInfostructure (unlessp7is configured to store a detached signature) and theencryptedDigestfields in all theSignerInfostructures. - for
EnvelopedDataorSignedAndEnvelopedDataβ theencryptedContentfield in theEncryptedContentInfostructure contained in thecontentfield ofp7. - for arbitrary data β the
contentfield ofp7itself.
π RETURN VALUES π
PKCS7_dataFinal() returns 1 on success or 0 on failure. periodt. π
Possible reasons for failure include:
p7isNULL.- The
contentfield ofp7is empty. - The
contentTypeofp7is unsupported. - The
chaindoes not contain the expected memoryBIO. - Signing or digesting is requested and
p7is not configured to store a detached signature, but does not contain the required field to store the content either. - At least one signer lacks a usable digest algorithm.
- Signing or digesting fails.
- Memory allocation fails.
Signers lacking private keys do not cause failure but are silently skipped. π«Ά like, theyβre not gonna ruin the party β they just get quietly left on read. π
π SEE ALSO π
π HISTORY π
PKCS7_dataFinal() first appeared in SSLeay 0.9.1 and has been available since OpenBSD 2.6. iconic behavior, honestly. β
π CAVEATS π
This function does not support EncryptedData. not me finding out the hard way, but okay ππ.
Even though this function is typically used afterPKCS7_dataInit(3)and even thoughPKCS7_dataInit(3)also supports reading fromContentInfostructures that are already fully populated, do not usePKCS7_dataFinal()on fully populated structures. It is only intended for putting data into new structures and it is neither needed nor suitable for reading.
mwah π β this page is from Debian, dated June 8, 2025, and yes bestie, itβs the PKCS7_DATAFINAL(3) manual page. π«Άβ¨
π¦ 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) 2020 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms