CMS_GET0_TYPE(3SSL)

✨ CMS_GET0_TYPE πŸ’… (the CMS_GET0_TYPE(3SSL) manual, bestie edition)

okay so you're in the OpenSSL section 3 docs, and today's main character is the CMS content-type situation β€” reading it, setting it, and getting at the actual content. no cap, this one's short and sweet but every single detail matters, so let's go πŸŽ€


🌸 NAME 🌸

CMS_get0_type, CMS_set1_eContentType, CMS_get0_eContentType, CMS_get0_content β€” literally just "get and set CMS content types and content." that's the whole vibe. πŸ¦‹


✨ SYNOPSIS ✨

#include <openssl/cms.h>

const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms);
int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid);
const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms);
ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms);

πŸ’– DESCRIPTION πŸ’–

CMS_get0_type() hands you the content type of a CMS_ContentInfo structure as an ASN1_OBJECT pointer. so then your app can look at that value and be like "okay, now I know how to process this CMS_ContentInfo structure." main character decision-making energy. πŸ‘‘

CMS_set1_eContentType() sets the embedded content type of a CMS_ContentInfo structure. ⚠️ important: you gotta call it alongside CMS functions (like CMS_sign(3), CMS_encrypt(3)) with the CMS_PARTIAL flag, and before the structure gets finalised β€” otherwise the results are undefined. that's not a vibe, that's a warning. respect it. πŸ’€

ASN1_OBJECT *CMS_get0_eContentType() gives you a pointer to the embedded content type. cute, simple, slay. ✨

CMS_get0_content() gives you a pointer to the ASN1_OCTET_STRING pointer that holds the embedded content. pointer-to-a-pointer, we love a nesting moment. 🫢


πŸ“ NOTES πŸ“

so the 0 in the name? that's giving internal pointer. as the 0 implies, CMS_get0_type(), CMS_get0_eContentType() and CMS_get0_content() all return internal pointers which should NOT be freed up. do not free them. do not pass go. πŸ™ˆ

meanwhile CMS_set1_eContentType() copies the supplied OID, so that one should be freed up after use. different rules, know the difference bestie. πŸ’…

the ASN1_OBJECT values you get back can be converted to an integer NID value using OBJ_obj2nid(). and for the currently supported content types, these are the values that come back:

 NID_pkcs7_data
 NID_pkcs7_signed
 NID_pkcs7_digest
 NID_id_smime_ct_compressedData:
 NID_pkcs7_encrypted
 NID_pkcs7_enveloped

and here's the lowkey tricky part: the return value of CMS_get0_content() is a pointer to the ASN1_OCTET_STRING content pointer. so, for example:

 ASN1_OCTET_STRING **pconf = CMS_get0_content(cms);

*pconf could be NULL if there's no embedded content. (yeah, check for that. 😭)

applications can access, modify or create the embedded content in a CMS_ContentInfo structure using this function. but honestly? applications usually will not need to modify the embedded content, because it's normally set by higher level functions. so like… it's there if you need it, but don't touch unless you must. ⭐


πŸŽ€ RETURN VALUES πŸŽ€

  • CMS_get0_type() and CMS_get0_eContentType() return an ASN1_OBJECT structure.
  • CMS_set1_eContentType() returns 1 for success, or 0 if an error occurred. and to find out what went wrong, grab the error from ERR_get_error(3). πŸ”₯

πŸ‘€ SEE ALSO πŸ‘€


Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie β€” this was OpenSSL version 4.0.3, dated 2026-09-29, from CMS_GET0_TYPE(3SSL). now go forth and set your content types responsibly, mwah πŸ’‹πŸ’–βœ¨

πŸ“¦ where this page comes from