libssh2_session_supported_algs(3)

πŸ“¦
version 1.11.1 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ libssh2_session_supported_algs ✨

okay bestie, welcome to the libssh2 manual page for libssh2_session_supported_algs πŸ’– this one's all about finding out which algorithms your SSH session can actually speak. no cap.


🌸 NAME 🌸

libssh2_session_supported_algs β€” get the list of supported algorithms πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <libssh2.h>

int
libssh2_session_supported_algs(LIBSSH2_SESSION* session,
                               int method_type,
                               const char*** algs);

πŸ’… DESCRIPTION πŸ’…

okay so here's the tea on the parameters, literally:

  • session β€” an instance of an initialized LIBSSH2_SESSION. fun fact: the function uses its pointer to the memory allocation function πŸ‘‘
  • method_type β€” the method type. see libssh2_session_method_pref(3) for the deets.
  • algs β€” the address of a pointer that's gonna end up pointing at an array of returned algorithms ✨

So what does it do? It gets you a list of supported algorithms for the given method_type. the method_type parameter is equivalent to method_type in libssh2_session_method_pref(3). If it works, the function will allocate the appropriate amount of memory. And when you don't need it anymore, it must be deallocated by calling libssh2_free(3). 🫢 But if this function is unsuccessful, then you must not do that. so like, don't free a thing that never got allocated, bestie, that's not the vibe.

also, if you wanna get a list of all supported compression algorithms, you have to call libssh2_session_flag(session, LIBSSH2_FLAG_COMPRESS, 1) before calling this function. otherwise only "none" will be returned. 😭 that's the whole list. just "none". tragic.

If successful, the function will allocate and fill the array with supported algorithms (the same names as defined in RFC 4253). and heads up: the array is not NULL terminated. so don't go looping on a NULL, use the return value instead 🧚


🌈 EXAMPLE 🌈

here's how it looks in the wild, fr fr:

#include "libssh2.h"

const char **algorithms;
int rc, i;
LIBSSH2_SESSION *session;

/* initialize session */
session = libssh2_session_init();
rc = libssh2_session_supported_algs(session,
                                    LIBSSH2_METHOD_CRYPT_CS,
                                    &algorithms);
if(rc > 0) {
    /* the call succeeded, do sth. with the list of algorithms
       (e.g. list them)... */
    printf("Supported symmetric algorithms:\n");
    for(i = 0; i < rc; i++)
        printf("\t%s\n", algorithms[i]);

    /* ... and free the allocated memory when not needed anymore */
    libssh2_free(session, algorithms);
}
else {
    /* call failed, error handling */
}

⭐ RETURN VALUE ⭐

On success, you get the number of returned algorithms (so, a positive number will be returned). πŸ’š

In case of a failure, you get an error code (a negative number, see below). and 0 should never be returned. like, ever. if you see a zero, something is deeply not okay πŸ‘€


πŸ’€ ERRORS πŸ’€

  • LIBSSH2_ERROR_BAD_USE β€” invalid address of algs. πŸ™ˆ
  • LIBSSH2_ERROR_METHOD_NOT_SUPPORTED β€” unknown method type. 🀷
  • LIBSSH2_ERROR_INVAL β€” internal error (normally should not occur). 😭
  • LIBSSH2_ERROR_ALLOC β€” allocation of memory failed. πŸ’€

πŸ¦‹ AVAILABILITY πŸ¦‹

Added in 1.4.0 ✨ so it's been iconic for a minute.


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie πŸ’– this was libssh2_session_supported_algs(3) from the libssh2 manual, dated 23 Oct 2011 β€” yes it's giving vintage but she still slays πŸŽ€ go free your arrays, periodt 🌸