libjwt-1.17.0
JWT Algorithm Functions

Set and check algorithms and algorithm specific values. More...

Functions

int jwt_set_alg (jwt_t *jwt, jwt_alg_t alg, const unsigned char *key, int len)
 Set an algorithm from jwt_alg_t for this JWT object.
 
jwt_alg_t jwt_get_alg (const jwt_t *jwt)
 Get the jwt_alg_t set for this JWT object.
 
const char * jwt_alg_str (jwt_alg_t alg)
 Convert alg type to it's string representation.
 
jwt_alg_t jwt_str_alg (const char *alg)
 Convert alg string to type.
 

Detailed Description

Set and check algorithms and algorithm specific values.

When working with functions that require a key, the underlying library takes care to scrub memory when the key is no longer used (e.g. when calling jwt_free() or when changing the algorithm, the old key, if it exists, is scrubbed).

Function Documentation

◆ jwt_alg_str()

const char * jwt_alg_str ( jwt_alg_t alg)

Convert alg type to it's string representation.

Returns a string that matches the alg type provided.

Parameters
algA valid jwt_alg_t specifier.
Returns
Returns a string (e.g. "RS256") matching the alg or NULL for invalid alg.

◆ jwt_get_alg()

jwt_alg_t jwt_get_alg ( const jwt_t * jwt)

Get the jwt_alg_t set for this JWT object.

Returns the jwt_alg_t type for this JWT object.

Parameters
jwtPointer to a JWT object.
Returns
Returns a jwt_alg_t type for this object.

◆ jwt_set_alg()

int jwt_set_alg ( jwt_t * jwt,
jwt_alg_t alg,
const unsigned char * key,
int len )

Set an algorithm from jwt_alg_t for this JWT object.

Specifies an algorithm for a JWT object. If JWT_ALG_NONE is used, then key must be NULL and len must be 0. All other algorithms must have a valid pointer to key data, which may be specific to the algorithm (e.g RS256 expects a PEM formatted RSA key).

Parameters
jwtPointer to a JWT object.
algA valid jwt_alg_t specifier.
keyThe key data to use for the algorithm.
lenThe length of the key data.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_str_alg()

jwt_alg_t jwt_str_alg ( const char * alg)

Convert alg string to type.

Returns an alg type based on the string representation.

Parameters
algA valid string algorithm type (e.g. "RS256").
Returns
Returns an alg type matching the string or JWT_ALG_INVAL if no matches were found.

Note, this only works for algorithms that LibJWT supports or knows about.