---
name: "libressl-PKCS7_dataFinal"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-PKCS7_dataFinal"
---

# libressl-PKCS7\_dataFinal(3)

move data from a BIO chain to a ContentInfo object

## NAME

**PKCS7\_dataFinal** – move data from a BIO chain to a ContentInfo object

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/pkcs7.h\>**

*int*\

**PKCS7\_dataFinal**(*PKCS7 \*p7*, *BIO \*chain*);

## DESCRIPTION

**PKCS7\_dataFinal**() transfers the data from the memory BIO at the end of the given *chain* into the appropriate content field of *p7* itself or of its appropriate substructure. It is typically used as the final step of populating *p7*, after creating the *chain* with PKCS7\_dataInit(3) and after writing the data into it.

After calling **PKCS7\_dataFinal**(), the program can call BIO\_free\_all(3) on the *chain* because such chains are not designed for reuse.

Depending on the *contentType* of *p7*, **PKCS7\_dataFinal**() sets the following fields:

- for *SignedData* or *DigestedData*:

  in substructures of the *content* field of *p7*: the *content* field in the *ContentInfo* structure (unless *p7* is configured to store a detached signature) and the *encryptedDigest* fields in all the *SignerInfo* structures

- for *EnvelopedData* or *SignedAndEnvelopedData*:

  the *encryptedContent* field in the *EncryptedContentInfo* structure contained in the *content* field of *p7*

- for arbitrary data:

  the *content* field of *p7* itself

## RETURN VALUES

**PKCS7\_dataFinal**() returns 1 on success or 0 on failure.

Possible reasons for failure include:

- *p7* is NULL.

- The *content* field of *p7* is empty.

- The *contentType* of *p7* is unsupported.

- The *chain* does not contain the expected memory BIO.

- Signing or digesting is requested and *p7* is 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.

## SEE ALSO

BIO\_new(3), PKCS7\_dataInit(3), PKCS7\_final(3), PKCS7\_new(3), PKCS7\_sign(3)

## HISTORY

**PKCS7\_dataFinal**() first appeared in SSLeay 0.9.1 and has been available since OpenBSD 2.6.

## CAVEATS

This function does not support *EncryptedData*.

Even though this function is typically used after PKCS7\_dataInit(3) and even though PKCS7\_dataInit(3) also supports reading from *ContentInfo* structures that are already fully populated, do not use **PKCS7\_dataFinal**() on fully populated structures. It is only intended for putting data into new structures and it is neither needed nor suitable for reading.
