CryptoAuthLib
Microchip CryptoAuthentication Library
JSON Web Token (JWT) methods (atca_jwt_)

Methods for signing and verifying JSON Web Token (JWT) tokens. More...

Data Structures

struct  atca_jwt_t
 Structure to hold metadata information about the jwt being built. More...
 

Functions

ATCA_STATUS atca_jwt_init (atca_jwt_t *jwt, char *buf, uint16_t buflen)
 Initialize a JWT structure. More...
 
ATCA_STATUS atca_jwt_add_claim_string (atca_jwt_t *jwt, const char *claim, const char *value)
 Add a string claim to a token. More...
 
ATCA_STATUS atca_jwt_add_claim_numeric (atca_jwt_t *jwt, const char *claim, int32_t value)
 Add a numeric claim to a token. More...
 
ATCA_STATUS atca_jwt_finalize (atca_jwt_t *jwt, uint16_t key_id)
 Close the claims of a token, encode them, then sign the result. More...
 
void atca_jwt_check_payload_start (atca_jwt_t *jwt)
 Check the provided context to see what character needs to be added in order to append a claim. More...
 
ATCA_STATUS atca_jwt_verify (const char *buf, uint16_t buflen, const uint8_t *pubkey)
 Verifies the signature of a jwt using the provided public key. More...
 

Detailed Description

Methods for signing and verifying JSON Web Token (JWT) tokens.

Function Documentation

◆ atca_jwt_add_claim_numeric()

ATCA_STATUS atca_jwt_add_claim_numeric ( atca_jwt_t jwt,
const char *  claim,
int32_t  value 
)

Add a numeric claim to a token.

Note
This function does not escape strings so the user has to ensure the claim is valid first
Parameters
[in]jwtJWT Context to use
[in]claimName of the claim to be inserted
[in]valueinteger value to be inserted

◆ atca_jwt_add_claim_string()

ATCA_STATUS atca_jwt_add_claim_string ( atca_jwt_t jwt,
const char *  claim,
const char *  value 
)

Add a string claim to a token.

Note
This function does not escape strings so the user has to ensure they are valid for use in a JSON string first
Parameters
[in]jwtJWT Context to use
[in]claimName of the claim to be inserted
[in]valueNull terminated string to be insterted

◆ atca_jwt_check_payload_start()

void atca_jwt_check_payload_start ( atca_jwt_t jwt)

Check the provided context to see what character needs to be added in order to append a claim.

Parameters
[in]jwtJWT Context to use

◆ atca_jwt_finalize()

ATCA_STATUS atca_jwt_finalize ( atca_jwt_t jwt,
uint16_t  key_id 
)

Close the claims of a token, encode them, then sign the result.

Parameters
[in]jwtJWT Context to use
[in]key_idKey Id (Slot number) used to sign

◆ atca_jwt_init()

ATCA_STATUS atca_jwt_init ( atca_jwt_t jwt,
char *  buf,
uint16_t  buflen 
)

Initialize a JWT structure.

Parameters
[in]jwtJWT Context to initialize
[in,out]bufPointer to a buffer to store the token
[in]buflenLength of the buffer

◆ atca_jwt_verify()

ATCA_STATUS atca_jwt_verify ( const char *  buf,
uint16_t  buflen,
const uint8_t *  pubkey 
)

Verifies the signature of a jwt using the provided public key.

Parameters
[in]bufBuffer holding an encoded jwt
[in]buflenLength of the buffer/jwt
[in]pubkeyPublic key (raw byte format)