LibJWT Dev
The C JSON Web Token Library +JWK +JWKS
Object Creation
Collaboration diagram for Object Creation:

Typedefs

typedef struct jwt jwt_t
 <
 

Enumerations

enum  jwt_alg_t {
  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_PS256 , JWT_ALG_PS384 ,
  JWT_ALG_PS512 , JWT_ALG_ES256K , JWT_ALG_EDDSA , JWT_ALG_INVAL
}
 JWT algorithm types. More...
 

Functions

int jwt_new (jwt_t **jwt)
 Allocate a new, empty, JWT object.
 
void jwt_free (jwt_t *jwt)
 Free a JWT object and any other resources it is using.
 
jwt_tjwt_dup (jwt_t *jwt)
 Duplicate an existing JWT object.
 

Detailed Description

Functions used to create and destroy JWT objects.

Typedef Documentation

◆ jwt_t

typedef struct jwt jwt_t

<

Opaque JWT object

This object is used throughout the JWT functions.

Remarks
When creating a JWT object (encoding), this stores state until you call one of the encoding functions. When dedcoding a JSON Web Token this object is returned so you can inspect it further (e.g. retrieve grants).

Definition at line 63 of file jwt.h.

Enumeration Type Documentation

◆ jwt_alg_t

enum jwt_alg_t

JWT algorithm types.

These are the supported algorithm types for LibJWT.

Warning
You should not assume that this directly relates to what may be in the JWT header. The internal state of the jwt_t object and the JSON data are only guarateed to be in sync during encoding and decoding.
Note
For HMAC algorithms, the key can be any data, even binary. However, for all the other algorithms, the key is expected to be in a format that the underlying Cryptographic Operations can interpret. Generally, PEM is a safe bet.

RFC-7518 Sec 3.1

Enumerator
JWT_ALG_NONE 

No signature.

JWT_ALG_HS256 

HMAC using SHA-256.

JWT_ALG_HS384 

HMAC using SHA-384.

JWT_ALG_HS512 

HMAC using SHA-512.

JWT_ALG_RS256 

RSASSA-PKCS1-v1_5 using SHA-256.

JWT_ALG_RS384 

RSASSA-PKCS1-v1_5 using SHA-384.

JWT_ALG_RS512 

RSASSA-PKCS1-v1_5 using SHA-512.

JWT_ALG_ES256 

ECDSA using P-256 and SHA-256.

JWT_ALG_ES384 

ECDSA using P-384 and SHA-384.

JWT_ALG_ES512 

ECDSA using P-521 and SHA-512.

JWT_ALG_PS256 

RSASSA-PSS using SHA-256 and MGF1 with SHA-256.

JWT_ALG_PS384 

RSASSA-PSS using SHA-384 and MGF1 with SHA-384.

JWT_ALG_PS512 

RSASSA-PSS using SHA-512 and MGF1 with SHA-512.

JWT_ALG_ES256K 

ECDSA using secp256k1 and SHA-256.

JWT_ALG_EDDSA 

EdDSA using Ed25519.

JWT_ALG_INVAL 

An invalid algorithm from the caller or the token.

Definition at line 100 of file jwt.h.

Function Documentation

◆ jwt_dup()

jwt_t * jwt_dup ( jwt_t * jwt)

Duplicate an existing JWT object.

Copies all grants and algorithm specific bits to a new JWT object.

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

◆ jwt_free()

void jwt_free ( jwt_t * jwt)

Free a JWT object and any other resources it is using.

After calling, the JWT object referenced will no longer be valid and its memory will be freed.

Parameters
jwtPointer to a JWT object previously created object

◆ jwt_new()

int jwt_new ( jwt_t ** jwt)

Allocate a new, empty, JWT object.

This is used to create a new object that would be passed to one of the Encoding and Output functions once setup.

{
jwt_t *MyJWT = NULL;
if (jwt_new(&MyJWT))
...handle error...
...create JWT...
jwt_free(MyJWT);
}
int jwt_new(jwt_t **jwt)
Allocate a new, empty, JWT object.
struct jwt jwt_t
<
Definition jwt.h:63
void jwt_free(jwt_t *jwt)
Free a JWT object and any other resources it is using.
Parameters
jwtPointer to a JWT object pointer. Will be allocated on success.
Returns
0 on success, valid errno otherwise.