PKCS7_SET_TYPE(3)

πŸ“¦ version 4.1.0, in opensuse-leap 16.0

πŸ’– PKCS7_SET_TYPE(3) β€” Library Functions Manual πŸ’–

okay bestie, welcome to the PKCS7_SET_TYPE(3) page from the Library Functions Manual β€” we’re doing PKCS#7 ContentInfo type stuff and it’s honestly giving β€œtiny setup functions with big main-character energy” ✨

πŸŽ€ NAME πŸŽ€

PKCS7_set_type, PKCS7_set0_type_other β€” initialize type of PKCS#7 ContentInfo πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

#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 🌸

So these functions set the type of an unused ContentInfo structure p7 β€” like, it has to be unused, okay? Don’t come in here with a p7 that’s already been living its best life 😭

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:

  • NID_pkcs7_data β€” child data type: ASN1_OCTET_STRING; version: n.a.
  • NID_pkcs7_digest β€” child data type: PKCS7_DIGEST; version: 0
  • NID_pkcs7_encrypted β€” child data type: PKCS7_ENCRYPT; version: 0
  • NID_pkcs7_enveloped β€” child data type: PKCS7_ENVELOPE; version: 0
  • NID_pkcs7_signed β€” child data type: PKCS7_SIGNED; version: 1
  • NID_pkcs7_signedAndEnveloped β€” child data type: PKCS7_SIGN_ENVELOPE; version: 1

If the provided type is invalid, p7 remains unchanged and PKCS7_set_type() fails. No spontaneous glow-up for p7, sadly πŸ™ˆ

If memory allocation fails, PKCS7_set_type() fails and p7 may remain in an inconsistent state. Yeah, that’s the messy part β€” not iconic, just inconsistent πŸ’€

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. Like… zero vibe check, zero copy, just straight in 🫢

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. Simple slay.

The function PKCS7_set0_type_other() does no error handling at all and always returns 1. Not me trusting the process fr fr 😭

🌈 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. Vintage but still relevant, iykyk πŸ’œ

πŸ’€ 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. Yikes. Later on, if other functions try to use p7 in its former role, they are likely to misbehave. That’s the β€œit said yes but it was lying” energy β€” please respect the unused-structure rule, bestie 🚨


xoxo, this little page comes from Debian, dated May 20, 2020 β€” periodt πŸ’…πŸŽ€

πŸ“¦ where this page comes from