5
5
#include <strings.h>
6
6
#include <jwt.h>
7
7
8
- install_t install (void );
8
+ install_t install (void );
9
9
10
- static void
11
- get_pl_arg_str (char * predicate_name , char * term_name , term_t term , char * * out )
12
- {
10
+ static void get_pl_arg_str (char * predicate_name , char * term_name , term_t term , char * * out ) {
13
11
if (!PL_get_atom_chars (term , out )) {
14
12
char * warning ;
15
13
asprintf (& warning , "%s: instantiation fault (%s)" , predicate_name , term_name );
@@ -18,31 +16,28 @@ get_pl_arg_str(char *predicate_name, char *term_name, term_t term, char **out)
18
16
}
19
17
}
20
18
21
- static foreign_t
22
- pl_jwt_encode (term_t in , term_t out , term_t key_term , term_t algorithm )
23
- {
24
- jwt_t * jwt ;
25
- char * result , * grants , * alg_str , * key ;
26
- int rval ;
19
+ static foreign_t pl_jwt_encode (term_t in , term_t out , term_t key_term , term_t algorithm ) {
20
+ jwt_t * jwt ;
21
+ char * result , * grants , * alg_str , * key ;
22
+ int rval ;
27
23
28
- get_pl_arg_str ("jwt_encode_from_string/4" , "in" , in , & grants );
29
- get_pl_arg_str ("jwt_encode_from_string/4" , "key" , key_term , & key );
30
- get_pl_arg_str ("jwt_encode_from_string/4" , "algorithm" , algorithm , & alg_str );
31
- jwt_new (& jwt );
32
- jwt_add_grants_json (jwt , grants );
33
- jwt_set_alg (jwt , jwt_str_alg (alg_str ), (const unsigned char * )key , strlen (key ));
34
- result = jwt_encode_str (jwt );
35
- rval = PL_unify_atom_chars (out , result );
36
- free (result );
37
- jwt_free (jwt );
38
- return rval ;
24
+ get_pl_arg_str ("jwt_encode_from_string/4" , "in" , in , & grants );
25
+ get_pl_arg_str ("jwt_encode_from_string/4" , "key" , key_term , & key );
26
+ get_pl_arg_str ("jwt_encode_from_string/4" , "algorithm" , algorithm , & alg_str );
27
+ jwt_new (& jwt );
28
+ jwt_add_grants_json (jwt , grants );
29
+ jwt_set_alg (jwt , jwt_str_alg (alg_str ), (const unsigned char * )key , strlen (key ));
30
+ result = jwt_encode_str (jwt );
31
+ rval = PL_unify_atom_chars (out , result );
32
+ free (result );
33
+ jwt_free (jwt );
34
+ return rval ;
39
35
}
40
36
41
- static foreign_t
42
- pl_jwt_parse_head (term_t in , term_t head_term ) {
43
- char * input , * head_payload ;
44
- jwt_t * jwt ;
45
- int jwt_result ;
37
+ static foreign_t pl_jwt_parse_head (term_t in , term_t head_term ) {
38
+ char * input , * head_payload ;
39
+ jwt_t * jwt ;
40
+ int jwt_result ;
46
41
get_pl_arg_str ("jwt_encode_from_string/4" , "in" , in , & input );
47
42
48
43
jwt_result = jwt_decode (& jwt , input , NULL , 0 );
@@ -57,38 +52,34 @@ pl_jwt_parse_head(term_t in, term_t head_term) {
57
52
}
58
53
}
59
54
60
- static foreign_t
61
- pl_jwt_decode (term_t in , term_t out_payload , term_t out_algorithm , term_t in_key )
62
- {
63
- char * input , * key , * payload ;
64
- const char * algorithm ;
65
- int jwt_result ;
66
- jwt_t * jwt ;
55
+ static foreign_t pl_jwt_decode (term_t in , term_t out_payload , term_t out_algorithm , term_t in_key ) {
56
+ char * input , * key , * payload ;
57
+ const char * algorithm ;
58
+ int jwt_result ;
59
+ jwt_t * jwt ;
67
60
68
- get_pl_arg_str ("jwt_encode_from_string/4" , "in" , in , & input );
69
- get_pl_arg_str ("jwt_encode_from_string/4" , "key" , in_key , & key );
70
- if (key == NULL || !strcmp ("" , key )) {
71
- jwt_result = jwt_decode (& jwt , input , NULL , 0 );
72
- } else {
73
- jwt_result = jwt_decode (& jwt , input , (const unsigned char * )key , strlen (key ));
74
- }
75
- if (!jwt_result ) {
76
- payload = jwt_get_grants_json (jwt , NULL );
77
- algorithm = jwt_alg_str (jwt_get_alg (jwt ));
78
- (void ) PL_unify_atom_chars (out_payload , payload );
79
- (void ) PL_unify_atom_chars (out_algorithm , algorithm );
80
- free (payload );
81
- jwt_free (jwt );
82
- PL_succeed ;
83
- } else {
84
- PL_fail ;
85
- }
61
+ get_pl_arg_str ("jwt_encode_from_string/4" , "in" , in , & input );
62
+ get_pl_arg_str ("jwt_encode_from_string/4" , "key" , in_key , & key );
63
+ if (key == NULL || !strcmp ("" , key )) {
64
+ jwt_result = jwt_decode (& jwt , input , NULL , 0 );
65
+ } else {
66
+ jwt_result = jwt_decode (& jwt , input , (const unsigned char * )key , strlen (key ));
67
+ }
68
+ if (!jwt_result ) {
69
+ payload = jwt_get_grants_json (jwt , NULL );
70
+ algorithm = jwt_alg_str (jwt_get_alg (jwt ));
71
+ (void ) PL_unify_atom_chars (out_payload , payload );
72
+ (void ) PL_unify_atom_chars (out_algorithm , algorithm );
73
+ free (payload );
74
+ jwt_free (jwt );
75
+ PL_succeed ;
76
+ } else {
77
+ PL_fail ;
78
+ }
86
79
}
87
80
88
- install_t
89
- install (void )
90
- {
91
- PL_register_foreign ("jwt_parse_head" , 2 , pl_jwt_parse_head , 0 );
92
- PL_register_foreign ("jwt_encode_from_string" , 4 , pl_jwt_encode , 0 );
93
- PL_register_foreign ("jwt_decode_from_string" , 4 , pl_jwt_decode , 0 );
81
+ install_t install (void ) {
82
+ PL_register_foreign ("jwt_parse_head" , 2 , pl_jwt_parse_head , 0 );
83
+ PL_register_foreign ("jwt_encode_from_string" , 4 , pl_jwt_encode , 0 );
84
+ PL_register_foreign ("jwt_decode_from_string" , 4 , pl_jwt_decode , 0 );
94
85
}
0 commit comments