---
name: "libressl-PKCS7_set_type"
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_set_type"
---

# libressl-PKCS7\_set\_type(3)

initialize type of PKCS#7 ContentInfo

## NAME

**PKCS7\_set\_type**, **PKCS7\_set0\_type\_other** – initialize type of PKCS#7 ContentInfo

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**PKCS7\_set\_type**(*PKCS7 \*p7*, *int type*);

*int*\

**PKCS7\_set0\_type\_other**(*PKCS7 \*p7*, *int type*, *ASN1\_TYPE \*content*);

## DESCRIPTION

These functions set the *type* of an unused *ContentInfo* structure *p7*.

The function **PKCS7\_set\_type**() also allocates and initializes an empty child object in *p7*. The *type* argument can be any of these NIDs, creating a child object of the indicated data type:

| | | |
| --- | --- | --- |
| *type* argument | data type of child | version |
| NID\_pkcs7\_data | *ASN1\_OCTET\_STRING* | n.a. |
| NID\_pkcs7\_digest | *PKCS7\_DIGEST* | 0 |
| NID\_pkcs7\_encrypted | *PKCS7\_ENCRYPT* | 0 |
| NID\_pkcs7\_enveloped | *PKCS7\_ENVELOPE* | 0 |
| NID\_pkcs7\_signed | *PKCS7\_SIGNED* | 1 |
| NID\_pkcs7\_signedAndEnveloped | *PKCS7\_SIGN\_ENVELOPE* | 1 |

If the provided *type* is invalid, *p7* remains unchanged and **PKCS7\_set\_type**() fails.

If memory allocation fails, **PKCS7\_set\_type**() fails and *p7* may remain in an inconsistent state.

The function **PKCS7\_set0\_type\_other**() accepts an arbitrary NID as the *type* and also sets the *content*, neither checking it in any way nor copying it.

For both functions, the rest of the internal state of *p7* remains unchanged.

## RETURN VALUES

The function **PKCS7\_set\_type**() returns 1 on success or 0 on failure.

The function **PKCS7\_set0\_type\_other**() does no error handling at all and always returns 1.

## SEE ALSO

ASN1\_OCTET\_STRING\_new(3), ASN1\_TYPE\_new(3), PKCS7\_encrypt(3), PKCS7\_new(3), PKCS7\_set\_content(3), PKCS7\_sign(3)

## HISTORY

The function **PKCS7\_set\_type**() first appeared in SSLeay 0.8.1 and **PKCS7\_set0\_type\_other**() in OpenSSL 0.9.8. Both have been available since OpenBSD 2.4.

## CAVEATS

If *p7* has already been in use before being passed to one of these functions, it will report success even though it leaks memory. Later on, if other functions try to use *p7* in its former role, they are likely to misbehave.
