libjwt-2.1.0
JWT Output Functions

Functions that enable seeing the plain text or fully encoded version of a JWT object. More...

Functions

int jwt_dump_fp (jwt_t *jwt, FILE *fp, int pretty)
 Output plain text representation to a FILE pointer.
 
char * jwt_dump_str (jwt_t *jwt, int pretty)
 Return plain text representation as a string.
 
char * jwt_dump_grants_str (jwt_t *jwt, int pretty)
 Return plain text representation of grants as a string.
 
int jwt_encode_fp (jwt_t *jwt, FILE *fp)
 Fully encode a JWT object and write it to FILE.
 
char * jwt_encode_str (jwt_t *jwt)
 Fully encode a JWT object and return as a string.
 
void jwt_free_str (char *str)
 Free a string returned from the library.
 

Detailed Description

Functions that enable seeing the plain text or fully encoded version of a JWT object.

Function Documentation

◆ jwt_dump_fp()

int jwt_dump_fp ( jwt_t * jwt,
FILE * fp,
int pretty )

Output plain text representation to a FILE pointer.

This function will write a plain text representation of this JWT object without Base64 encoding. This only writes the header and body, and does not compute the signature or encryption (if such an algorithm were being used).

Note, this may change the content of JWT header if algorithm is set on the JWT object. If algorithm is set (jwt_set_alg was called on the jwt object) then dumping JWT attempts to append 'typ' header. If the 'typ' header already exists, then it is left untouched, otherwise it is added with default value of "JWT".

Parameters
jwtPointer to a JWT object.
fpValid FILE pointer to write data to.
prettyEnables better visual formatting of output. Generally only used for debugging.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_dump_grants_str()

char * jwt_dump_grants_str ( jwt_t * jwt,
int pretty )

Return plain text representation of grants as a string.

Similar to jwt_dump_str() except that only a string containing the grants string is returned. The string must be freed by the caller.

Parameters
jwtPointer to a JWT object.
prettyEnables better visual formatting of output. Generally only used for debugging.
Returns
A nul terminated string on success, NULL on error with errno set appropriately.

◆ jwt_dump_str()

char * jwt_dump_str ( jwt_t * jwt,
int pretty )

Return plain text representation as a string.

Similar to jwt_dump_fp() except that a string is returned. The string must be freed by the caller.

Note, this may change the content of JWT header if algorithm is set on the JWT object. If algorithm is set (jwt_set_alg was called on the jwt object) then dumping JWT attempts to append 'typ' header. If the 'typ' header already exists, then it is left untouched, otherwise it is added with default value of "JWT".

Parameters
jwtPointer to a JWT object.
prettyEnables better visual formatting of output. Generally only used for debugging.
Returns
A nul terminated string on success, NULL on error with errno set appropriately.

◆ jwt_encode_fp()

int jwt_encode_fp ( jwt_t * jwt,
FILE * fp )

Fully encode a JWT object and write it to FILE.

This will create and write the complete JWT object to FILE. All parts will be Base64 encoded and signatures or encryption will be applied if the algorithm specified requires it.

Parameters
jwtPointer to a JWT object.
fpValid FILE pointer to write data to.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_encode_str()

char * jwt_encode_str ( jwt_t * jwt)

Fully encode a JWT object and return as a string.

Similar to jwt_encode_fp() except that a string is returned. The string must be freed by the caller. If you changed the allocation method using jwt_set_alloc, then you must use jwt_free_str() to free the memory.

Parameters
jwtPointer to a JWT object.
Returns
A null terminated string on success, NULL on error with errno set appropriately.

◆ jwt_free_str()

void jwt_free_str ( char * str)

Free a string returned from the library.

Parameters
strPointer to a string previously created with jwt_encode_str().