File: hooks.h

package info (click to toggle)
jose 10-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 2,772 kB
  • sloc: ansic: 9,696; sh: 4,816; makefile: 157
file content (186 lines) | stat: -rw-r--r-- 5,148 bytes parent folder | download | duplicates (2)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
/*
 * Copyright 2016 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <jose/jws.h>
#include <jose/jwe.h>

typedef enum {
    JOSE_HOOK_JWK_KIND_NONE = 0,
    JOSE_HOOK_JWK_KIND_TYPE,
    JOSE_HOOK_JWK_KIND_OPER,
    JOSE_HOOK_JWK_KIND_PREP,
    JOSE_HOOK_JWK_KIND_MAKE,
    JOSE_HOOK_JWK_KIND_LAST = JOSE_HOOK_JWK_KIND_MAKE
} jose_hook_jwk_kind_t;

typedef enum {
    JOSE_HOOK_ALG_KIND_NONE = 0,
    JOSE_HOOK_ALG_KIND_HASH,
    JOSE_HOOK_ALG_KIND_SIGN,
    JOSE_HOOK_ALG_KIND_WRAP,
    JOSE_HOOK_ALG_KIND_ENCR,
    JOSE_HOOK_ALG_KIND_COMP,
    JOSE_HOOK_ALG_KIND_EXCH,
    JOSE_HOOK_ALG_KIND_LAST = JOSE_HOOK_ALG_KIND_EXCH
} jose_hook_alg_kind_t;

typedef struct jose_hook_jwk jose_hook_jwk_t;
struct jose_hook_jwk {
    const jose_hook_jwk_t *next;
    jose_hook_jwk_kind_t kind;

    union {
        struct {
            const char  *kty;
            const char **req;
            const char **pub;
            const char **prv;
        } type;

        struct {
            const char *pub;
            const char *prv;
            const char *use;
        } oper;

        struct {
            bool
            (*handles)(jose_cfg_t *cfg, const json_t *jwk);

            json_t *
            (*execute)(jose_cfg_t *cfg, const json_t *jwk);
        } prep;

        struct {
            bool
            (*handles)(jose_cfg_t *cfg, const json_t *jwk);

            json_t *
            (*execute)(jose_cfg_t *cfg, const json_t *jwk);
        } make;
    };
};

typedef struct jose_hook_alg jose_hook_alg_t;
struct jose_hook_alg {
    const jose_hook_alg_t *next;
    jose_hook_alg_kind_t kind;
    const char *name;

    union {
        struct {
            size_t size;

            jose_io_t *
            (*hsh)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
        } hash;

        struct {
            const char *sprm;
            const char *vprm;

            const char *
            (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *jwk);

            jose_io_t *
            (*sig)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   json_t *jws, json_t *sig, const json_t *jwk);

            jose_io_t *
            (*ver)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *jws, const json_t *sig, const json_t *jwk);
        } sign;

        struct {
            const char *eprm;
            const char *dprm;

            const char *
            (*alg)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *jwk);

            const char *
            (*enc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *jwk);

            bool
            (*wrp)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   json_t *jwe, json_t *rcp,
                   const json_t *jwk, json_t *cek);

            bool
            (*unw)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *jwe, const json_t *rcp,
                   const json_t *jwk, json_t *cek);
        } wrap;

        struct {
            const char *eprm;
            const char *dprm;

            const char *
            (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *cek);

            jose_io_t *
            (*enc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   json_t *jwe, const json_t *cek, jose_io_t *next);

            jose_io_t *
            (*dec)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *jwe, const json_t *cek, jose_io_t *next);
        } encr;

        struct {
            jose_io_t *
            (*def)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);

            jose_io_t *
            (*inf)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
        } comp;

        struct {
            const char *prm;

            const char *
            (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *prv, const json_t *pub);

            json_t *
            (*exc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
                   const json_t *prv, const json_t *pub);
        } exch;
    };
};

void
jose_hook_jwk_push(jose_hook_jwk_t *reg);

const jose_hook_jwk_t *
jose_hook_jwk_list(void);

void
jose_hook_alg_push(jose_hook_alg_t *alg);

const jose_hook_alg_t *
jose_hook_alg_list(void);

const jose_hook_alg_t *
jose_hook_alg_find(jose_hook_alg_kind_t kind, const char *name);