NNG_TLS_CONFIG_PSK(3tls)
β¨ NAME β¨
nng_tls_config_psk β setting up pre-shared keys (PSK) for TLS, bestie π
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
#include <nng/supplemental/tls/tls.h>
int nng_tls_config_psk(nng_tls_config *cfg, const char *identity,
const uint8_t *key, size_t key_len);
π¦ DESCRIPTION π¦
okay so nng_tls_config_psk() is literally the function that sets up a pre-shared secret for your TLS connections. it's giving "we already know each other's vibe, no need to introduce ourselves" energy fr fr π
if you're in client mode, you call this once, and once is enough β it sets your own identity plus a single key that's key_len bytes big. one and done, iconic behavior π
if you're in server mode tho? you can call this multiple times, and when a client rolls up, the server will go look up whichever key it needs to use for that connection. like a little key closet, slay π
think of identity as kinda the public-facing part β like a username, the thing everyone can see β and key is ofc the confidential material that actually gets used to establish keys. that's the whole point, that's the moment π«Ά both sides, client and server, may have the same values for identity, key, and key_len.
now, real talk: implementations may put limits on whether this whole functionality is even supported, plus limits on how long keys or identities can be. but generally speaking, key lengths up to 32 bytes and identities up to 64 bytes will be supported wherever PSK configurations are present. so like, that's the standard vibe check β
β οΈ heads up bestie: some implementations might let you put arbitrary byte patterns in the identity, but this implementation does not support embedded zero bytes, and it assumes the values are printable (because it logs them). so don't get cute with the nulls π
π RETURN VALUES π
returns 0 on success, and non-zero otherwise. no in-between, no drama π
π₯ ERRORS π₯
NNG_ENOMEMβ not enough memory available, the poor thing is starving πNNG_EBUSYβ the configurationcfgis already in use and cannot be modified. it's booked, it's busy, it's in its main character era π«NNG_EINVALβ invalid parameters were supplied. you gave it something it can't work with π
π SEE ALSO π
and that's the whole page, bestie! this came from the NNG Reference Manual, dated 2026-06-30, and we're talking NNG_TLS_CONFIG_PSK(3tls) obvs. stay encrypted, stay slay πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms