libjwt-1.12.0
jwt.h File Reference

JWT C Library. More...

#include <stdio.h>
#include <time.h>

Go to the source code of this file.

Macros

#define DEPRECATED(func)
 
#define JWT_EXPORT
 
#define JWT_ALG_INVAL
 
#define JWT_VALIDATION_SUCCESS
 JWT Validation exception types. More...
 
#define JWT_VALIDATION_ERROR
 
#define JWT_VALIDATION_ALG_MISMATCH
 
#define JWT_VALIDATION_EXPIRED
 
#define JWT_VALIDATION_TOO_NEW
 
#define JWT_VALIDATION_ISS_MISMATCH
 
#define JWT_VALIDATION_SUB_MISMATCH
 
#define JWT_VALIDATION_AUD_MISMATCH
 
#define JWT_VALIDATION_GRANT_MISSING
 
#define JWT_VALIDATION_GRANT_MISMATCH
 

Typedefs

typedef struct jwt jwt_t
 Opaque JWT object. More...
 
typedef struct jwt_valid jwt_valid_t
 Opaque JWT validation object. More...
 
typedef enum jwt_alg jwt_alg_t
 JWT algorithm types. More...
 
typedef void *(* jwt_malloc_t )(size_t)
 JWT Memory allocation overrides. More...
 
typedef void *(* jwt_realloc_t )(void *, size_t)
 
typedef void(* jwt_free_t )(void *)
 

Enumerations

enum  jwt_alg {
  JWT_ALG_NONE, JWT_ALG_HS256, JWT_ALG_HS384, JWT_ALG_HS512,
  JWT_ALG_RS256, JWT_ALG_RS384, JWT_ALG_RS512, JWT_ALG_ES256,
  JWT_ALG_ES384, JWT_ALG_ES512, JWT_ALG_TERM
}
 JWT algorithm types. More...
 

Functions

int jwt_new (jwt_t **jwt)
 Allocate a new, empty, JWT object. More...
 
int jwt_decode (jwt_t **jwt, const char *token, const unsigned char *key, int key_len)
 Verify an existing JWT and allocate a new JWT object from it. More...
 
void jwt_free (jwt_t *jwt)
 Free a JWT object and any other resources it is using. More...
 
jwt_tjwt_dup (jwt_t *jwt)
 Duplicate an existing JWT object. More...
 
const char * jwt_get_grant (jwt_t *jwt, const char *grant)
 Return the value of a string grant. More...
 
long jwt_get_grant_int (jwt_t *jwt, const char *grant)
 Return the value of an integer grant. More...
 
int jwt_get_grant_bool (jwt_t *jwt, const char *grant)
 Return the value of an boolean grant. More...
 
char * jwt_get_grants_json (jwt_t *jwt, const char *grant)
 Return the value of a grant as JSON encoded object string. More...
 
int jwt_add_grant (jwt_t *jwt, const char *grant, const char *val)
 Add a new string grant to this JWT object. More...
 
int jwt_add_grant_int (jwt_t *jwt, const char *grant, long val)
 Add a new integer grant to this JWT object. More...
 
int jwt_add_grant_bool (jwt_t *jwt, const char *grant, int val)
 Add a new boolean grant to this JWT object. More...
 
int jwt_add_grants_json (jwt_t *jwt, const char *json)
 Add grants from a JSON encoded object string. More...
 
int jwt_del_grants (jwt_t *jwt, const char *grant)
 Delete a grant from this JWT object. More...
 
int jwt_del_grant (jwt_t *jwt, const char *grant)
 
const char * jwt_get_header (jwt_t *jwt, const char *header)
 Return the value of a string header. More...
 
long jwt_get_header_int (jwt_t *jwt, const char *header)
 Return the value of an integer header. More...
 
int jwt_get_header_bool (jwt_t *jwt, const char *header)
 Return the value of an boolean header. More...
 
char * jwt_get_headers_json (jwt_t *jwt, const char *header)
 Return the value of a header as JSON encoded object string. More...
 
int jwt_add_header (jwt_t *jwt, const char *header, const char *val)
 Add a new string header to this JWT object. More...
 
int jwt_add_header_int (jwt_t *jwt, const char *header, long val)
 Add a new integer header to this JWT object. More...
 
int jwt_add_header_bool (jwt_t *jwt, const char *header, int val)
 Add a new boolean header to this JWT object. More...
 
int jwt_add_headers_json (jwt_t *jwt, const char *json)
 Add headers from a JSON encoded object string. More...
 
int jwt_del_headers (jwt_t *jwt, const char *header)
 Delete a header from this JWT object. More...
 
int jwt_dump_fp (jwt_t *jwt, FILE *fp, int pretty)
 Output plain text representation to a FILE pointer. More...
 
char * jwt_dump_str (jwt_t *jwt, int pretty)
 Return plain text representation as a string. More...
 
int jwt_encode_fp (jwt_t *jwt, FILE *fp)
 Fully encode a JWT object and write it to FILE. More...
 
char * jwt_encode_str (jwt_t *jwt)
 Fully encode a JWT object and return as a string. More...
 
void jwt_free_str (char *str)
 Free a string returned from the library. More...
 
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. More...
 
jwt_alg_t jwt_get_alg (jwt_t *jwt)
 Get the jwt_alg_t set for this JWT object. More...
 
const char * jwt_alg_str (jwt_alg_t alg)
 Convert alg type to it's string representation. More...
 
jwt_alg_t jwt_str_alg (const char *alg)
 Convert alg string to type. More...
 
int jwt_set_alloc (jwt_malloc_t pmalloc, jwt_realloc_t prealloc, jwt_free_t pfree)
 Set functions to be used for allocating and freeing memory. More...
 
void jwt_get_alloc (jwt_malloc_t *pmalloc, jwt_realloc_t *prealloc, jwt_free_t *pfree)
 Get functions used for allocating and freeing memory. More...
 
unsigned int jwt_validate (jwt_t *jwt, jwt_valid_t *jwt_valid)
 Validate a JWT object with a validation object. More...
 
int jwt_valid_new (jwt_valid_t **jwt_valid, jwt_alg_t alg)
 Allocate a new, JWT validation object. More...
 
void jwt_valid_free (jwt_valid_t *jwt_valid)
 Free a JWT validation object and any other resources it is using. More...
 
unsigned int jwt_valid_get_status (jwt_valid_t *jwt_valid)
 Return the status string for the validation object. More...
 
int jwt_valid_add_grant (jwt_valid_t *jwt_valid, const char *grant, const char *val)
 Add a new string grant requirement to this JWT validation object. More...
 
const char * jwt_valid_get_grant (jwt_valid_t *jwt_valid, const char *grant)
 Return the value of a string required grant. More...
 
int jwt_valid_add_grant_int (jwt_valid_t *jwt_valid, const char *grant, long val)
 Add a new integer grant requirement to this JWT validation object. More...
 
long jwt_valid_get_grant_int (jwt_valid_t *jwt_valid, const char *grant)
 Return the value of an integer required grant. More...
 
int jwt_valid_add_grant_bool (jwt_valid_t *jwt_valid, const char *grant, int val)
 Add a new boolean required grant to this JWT validation object. More...
 
int jwt_valid_get_grant_bool (jwt_valid_t *jwt_valid, const char *grant)
 Return the value of an boolean required grant. More...
 
int jwt_valid_add_grants_json (jwt_valid_t *jwt_valid, const char *json)
 Add required grants from a JSON encoded object string. More...
 
char * jwt_valid_get_grants_json (jwt_valid_t *jwt_valid, const char *grant)
 Return the value of a grant as JSON encoded object string. More...
 
int jwt_valid_del_grants (jwt_valid_t *jwt, const char *grant)
 Delete a grant from this JWT object. More...
 
int jwt_valid_set_now (jwt_valid_t *jwt_valid, const time_t now)
 Set the time for which expires and not-before claims should be evaluated. More...
 
int jwt_valid_set_headers (jwt_valid_t *jwt_valid, int hdr)
 Set validation for replicated claims in headers. More...
 

Detailed Description

JWT C Library.

Definition in file jwt.h.

Macro Definition Documentation

#define DEPRECATED (   func)

Definition at line 39 of file jwt.h.

#define JWT_ALG_INVAL

Definition at line 69 of file jwt.h.

#define JWT_EXPORT

Definition at line 40 of file jwt.h.

#define JWT_VALIDATION_ALG_MISMATCH

Definition at line 74 of file jwt.h.

#define JWT_VALIDATION_AUD_MISMATCH

Definition at line 79 of file jwt.h.

#define JWT_VALIDATION_ERROR

Definition at line 73 of file jwt.h.

#define JWT_VALIDATION_EXPIRED

Definition at line 75 of file jwt.h.

#define JWT_VALIDATION_GRANT_MISMATCH

Definition at line 81 of file jwt.h.

#define JWT_VALIDATION_GRANT_MISSING

Definition at line 80 of file jwt.h.

#define JWT_VALIDATION_ISS_MISMATCH

Definition at line 77 of file jwt.h.

#define JWT_VALIDATION_SUB_MISMATCH

Definition at line 78 of file jwt.h.

#define JWT_VALIDATION_SUCCESS

JWT Validation exception types.

These are bit values.

Definition at line 72 of file jwt.h.

#define JWT_VALIDATION_TOO_NEW

Definition at line 76 of file jwt.h.

Typedef Documentation

typedef enum jwt_alg jwt_alg_t

JWT algorithm types.

typedef void(* jwt_free_t)(void *)

Definition at line 86 of file jwt.h.

typedef void*(* jwt_malloc_t)(size_t)

JWT Memory allocation overrides.

Definition at line 84 of file jwt.h.

typedef void*(* jwt_realloc_t)(void *, size_t)

Definition at line 85 of file jwt.h.

typedef struct jwt jwt_t

Opaque JWT object.

Definition at line 49 of file jwt.h.

typedef struct jwt_valid jwt_valid_t

Opaque JWT validation object.

Definition at line 52 of file jwt.h.

Enumeration Type Documentation

enum jwt_alg

JWT algorithm types.

Enumerator
JWT_ALG_NONE 
JWT_ALG_HS256 
JWT_ALG_HS384 
JWT_ALG_HS512 
JWT_ALG_RS256 
JWT_ALG_RS384 
JWT_ALG_RS512 
JWT_ALG_ES256 
JWT_ALG_ES384 
JWT_ALG_ES512 
JWT_ALG_TERM 

Definition at line 55 of file jwt.h.