gnutls_credentials_set(3)

πŸ’– gnutls_credentials_set(3) β€” the gnutls girlies' guide πŸ’–

okay bestie, pull up a chair, we're looking at a page from the gnutls manual and it's literally the one that hands your session its little identity ✨


🌸 NAME 🌸

gnutls_credentials_set β€” the API function, she's the moment πŸ’…


✨ SYNOPSIS ✨

#include <gnutls/gnutls.h>

int gnutls_credentials_set(gnutls_session_t session,
gnutls_credentials_type_t type, void * cred);

πŸŽ€ ARGUMENTS πŸŽ€

  • gnutls_session_t session β€” yeah so this is a gnutls_session_t type, that's the vibe πŸ¦‹
  • gnutls_credentials_type_t type β€” this is the type of the credentials, like which flavour we're setting
  • void * cred β€” and these are the actual credentials you're setting, the goods πŸ’–

πŸ’œ DESCRIPTION πŸ’œ

So like, what she does is: she sets the needed credentials for the specified type. E.g. username, password β€” or public and private keys etc. Obsessed.

The cred parameter is a structure that depends on the specified type and on the current session (client or server). Important. Only a single cred may be set for each different type, and lowkey if you call her again with the same type, she just replaces the previously set credentials. No drama, she just swaps it out 🫢

Now the part that's giving ✨memory management✨: in order to minimize memory usage, and share credentials between several threads, gnutls keeps a pointer to cred, and not the whole cred structure. So no cap β€” you have to keep that structure allocated until you call gnutls_deinit(), or until a future call of gnutls_credentials_set() with the same type replaces the cred structure. Don't let her dangle, bestie 😭

And here's the tea on which struct goes with which type:

  • For GNUTLS_CRD_ANON, cred should be gnutls_anon_client_credentials_t in case of a client. In case of a server it should be gnutls_anon_server_credentials_t.
  • For GNUTLS_CRD_SRP, cred should be gnutls_srp_client_credentials_t in case of a client, and gnutls_srp_server_credentials_t, in case of a server.
  • For GNUTLS_CRD_CERTIFICATE, cred should be gnutls_certificate_credentials_t.

pick the right one or it's giving chaos 🧚


πŸ”₯ RETURNS πŸ”₯

On success, GNUTLS_E_SUCCESS (0) is returned β€” slay. Otherwise a negative error code is returned πŸ’€


πŸ› REPORTING BUGS πŸ›

Report bugs to <bugs@gnutls.org>. Home page: https://www.gnutls.org


Copyright Β© 2001-2023 Free Software Foundation, Inc., and others.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.


🌈 SEE ALSO 🌈

The full documentation for gnutls is maintained as a Texinfo manual. If the /usr/share/doc/gnutls/ directory does not contain the HTML form visit

https://www.gnutls.org/manual/


okay that's the whole page, you ate that πŸ“ this one's from the gnutls 3.8.13 manual, page gnutls_credentials_set(3), mwah πŸ’–βœ¨

πŸ“¦ where this page comes from