Method: Mosquitto::Client#tls_psk_set

Defined in:
ext/mosquitto/client.c

#tls_psk_set("deadbeef", "psk-id", nil) ⇒ Boolean

Note:

This must be called before calling Mosquitto::Client#connect

Configure the client for pre-shared-key based TLS support.

Examples:

client.tls_psk_set("deadbeef", "psk-id", nil)

Returns:

  • (Boolean)

Parameters:

  • psk (String)

    the pre-shared-key in hex format with no leading “0x”.

  • identity (String)

    the identity of this client. May be used as the username depending on the server settings.

  • ciphers (String)

    a string describing the ciphers available for use. See the ‘openssl ciphers` tool for more information. If nil, the default ciphers will be used.

Returns:

  • (true)

    on success

Raises:

See Also:

  • ciphers`


887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'ext/mosquitto/client.c', line 887

static VALUE rb_mosquitto_client_tls_psk_set(VALUE obj, VALUE psk, VALUE identity, VALUE ciphers)
{
    int ret;
    MosquittoGetClient(obj);
    Check_Type(psk, T_STRING);
    Check_Type(identity, T_STRING);
    if (!NIL_P(ciphers)) {
        Check_Type(ciphers, T_STRING);
        MosquittoEncode(ciphers);
    }

    ret = mosquitto_tls_psk_set(client->mosq, StringValueCStr(psk), StringValueCStr(identity), (NIL_P(ciphers) ? NULL : StringValueCStr(ciphers)));
    switch (ret) {
       case MOSQ_ERR_INVAL:
           MosquittoError("invalid input params");
           break;
       case MOSQ_ERR_NOMEM:
           rb_memerror();
           break;
       case MOSQ_ERR_NOT_SUPPORTED:
           MosquittoError("TLS support is not available");
       default:
           return Qtrue;
    }
}