PKCS7_SET_TYPE(3)

NAME
PKCS7_set_type, PKCS7_set0_type_other - initialize type of PKCS#7 ContentInfo

SYNOPSIS
libcrypto
#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.