-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjwt.h
70 lines (55 loc) · 1.81 KB
/
jwt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*!
* @file libxutils/src/data/jwt.h
*
* This source is part of "libxutils" project
* 2019-2023 Sun Dro ([email protected])
*
* @brief Implementation of JSON Web Tokens
*/
#ifndef __XUTILS_JWT_H__
#define __XUTILS_JWT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "xstd.h"
#include "crypt.h"
#include "xjson.h"
#include "xstr.h"
typedef enum {
XJWT_ALG_INVALID = 0,
XJWT_ALG_HS256,
#ifdef XCRYPT_USE_SSL
XJWT_ALG_RS256
#endif
} xjwt_alg_t;
typedef struct XJWT {
char *pHeader;
size_t nHeaderLen;
xjson_obj_t *pHeaderObj;
char *pPayload;
size_t nPayloadLen;
xjson_obj_t *pPayloadObj;
char *pSignature;
size_t nSignatureLen;
xjwt_alg_t eAlgorithm;
xbool_t bVerified;
} xjwt_t;
void XJWT_Init(xjwt_t *pJWT, xjwt_alg_t eAlg);
void XJWT_Destroy(xjwt_t *pJWT);
const char* XJWT_GetAlgStr(xjwt_alg_t eAlg);
xjwt_alg_t XJWT_GetAlg(const char *pAlgStr);
xjwt_alg_t XJWT_GetAlgorithm(xjwt_t *pJWT);
XSTATUS XJWT_AddPayload(xjwt_t *pJWT, const char *pPayload, size_t nPayloadLen, xbool_t bIsEncoded);
char* XJWT_GetPayload(xjwt_t *pJWT, xbool_t bDecode, size_t *pPayloadLen);
xjson_obj_t* XJWT_GetPayloadObj(xjwt_t *pJWT);
XSTATUS XJWT_AddHeader(xjwt_t *pJWT, const char *pHeader, size_t nHeaderLen, xbool_t bIsEncoded);
char* XJWT_GetHeader(xjwt_t *pJWT, xbool_t bDecode, size_t *pHeaderLen);
xjson_obj_t* XJWT_CreateHeaderObj(xjwt_alg_t eAlg);
xjson_obj_t* XJWT_GetHeaderObj(xjwt_t *pJWT);
char* XJWT_Create(xjwt_t *pJWT, const uint8_t *pSecret, size_t nSecretLen, size_t *pJWTLen);
XSTATUS XJWT_Parse(xjwt_t *pJWT, const char *pJWTStr, size_t nLength, const uint8_t *pSecret, size_t nSecretLen);
XSTATUS XJWT_Verify(xjwt_t *pJWT, const char *pSignature, size_t nSignatureLen, const uint8_t *pSecret, size_t nSecretLen);
#ifdef __cplusplus
}
#endif
#endif /* __XUTILS_JWT_H__ */