MONGOC_CLIENT_...YPTION_ENCRYPT(3)

πŸ’– mongoc_client_encryption_encrypt πŸ’–

okay bestie, welcome to the libmongoc manual, specifically the page for mongoc_client_encryption_encrypt β€” yes the header got chopped in the terminal like a bad screenshot, but that's the one. she does explicit encryption, and honestly? iconic behavior. let's get into it 🫢


✨ SYNOPSIS ✨

bool
mongoc_client_encryption_encrypt (
   mongoc_client_encryption_t *client_encryption,
   const bson_value_t *value,
   mongoc_client_encryption_encrypt_opts_t *opts,
   bson_value_t *ciphertext,
   bson_error_t *error);

🌸 DESCRIPTION 🌸

so what does she actually do? she performs explicit encryption. that's the whole vibe. πŸ’…

ciphertext is always initialized β€” even on failure, no cap, she never leaves you hanging with garbage memory. but bestie listen: the caller must call bson_value_destroy() to free it. literally your job, not hers. don't ghost your cleanup 🫢

now, the important part πŸ‘‘ β€” to insert or query with an "Indexed" or "Range" encrypted payload, you use a mongoc_client_t that's configured with mongoc_auto_encryption_opts_t.

that mongoc_auto_encryption_opts_t may be configured to bypass query analysis with mongoc_auto_encryption_opts_set_bypass_query_analysis().

but it must not be configured to bypass automatic encryption with mongoc_auto_encryption_opts_set_bypass_auto_encryption(). 🚫 like, absolutely not, that's the one thing you can't do here.

⚠️ read that again bestie β€” "may bypass query analysis" = fine, "must not bypass automatic encryption" = do not. they are NOT the same thing and mixing them up is a whole mess. 😭

to insert with a Range payload, mongoc_client_encryption_encrypt_range_opts_t must be set in opts. no shortcuts ✨

and to query with a Range payload? that's a whole different function β€” use mongoc_client_encryption_encrypt_expression(). different girl, different job πŸ’…


πŸŽ€ PARAMETERS πŸŽ€

  • client_encryption β€” a mongoc_client_encryption_t. the main character of this function ✨
  • value β€” the value to encrypt. the secret. the tea. πŸ“
  • opts β€” a mongoc_client_encryption_encrypt_opts_t. this is where you set your Range opts if you're doing the Range thing.
  • ciphertext β€” a bson_value_t that holds the resulting ciphertext β€” which is a BSON binary with subtype 6, iykyk πŸ¦‹
  • error β€” a bson_error_t that gets set on failure. she'll tell you what went wrong πŸ’€

⭐ RETURNS ⭐

returns true if it worked β€” slay, we love a success πŸ’–

returns false and sets error otherwise. so like, always check. always. πŸ™ˆ

πŸ‘€ SEE ALSO πŸ‘€

  • mongoc_client_encryption_encrypt_opts_t
  • mongoc_client_enable_auto_encryption()
  • mongoc_client_decryption_decrypt()
  • mongoc_client_encryption_encrypt_expression()

go read those next, they're lowkey required reading for the full lore πŸ“š


πŸ’œ AUTHOR πŸ’œ

MongoDB, Inc β€” the icon, the legend, the whole team 🫢

2009-present, MongoDB, Inc. β€” periods and all, we respect the paperwork πŸ‘‘


and that's a wrap, bestie!! this page is from libmongoc version 2.5.6, date stamped Oct 09, 202 (yes the terminal ate the rest of the year, she's mysterious like that πŸ’€βœ¨). go forth, encrypt explicitly, and please call bson_value_destroy(). mwah πŸŽ€πŸ’–

πŸ“¦ where this page comes from