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
|
/*
webid-oidc, implementation of the Solid specification
Copyright (C) 2020, 2021 Vivien Kraus
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef H_RANDOM_INCLUDED
#define H_RANDOM_INCLUDED
struct webid_oidc_random_context;
typedef struct webid_oidc_random_context webid_oidc_random_context;
/* These functions allocate data, they are not reentrant. */
struct webid_oidc_random_context *webid_oidc_random_context_alloc (void);
void webid_oidc_random_context_free (struct webid_oidc_random_context *ctx);
enum webid_oidc_random_context_state
{
WEBID_OIDC_RANDOM_CONTEXT_READY = 0,
WEBID_OIDC_RANDOM_CONTEXT_WAIT_LOCK_FILE,
WEBID_OIDC_RANDOM_CONTEXT_WAIT_FILE_READ,
WEBID_OIDC_RANDOM_CONTEXT_WAIT_FILE_WRITE,
WEBID_OIDC_RANDOM_CONTEXT_WAIT_UNLOCK_FILE
};
typedef enum webid_oidc_random_context_state webid_oidc_random_context_state;
enum webid_oidc_random_context_state
webid_oidc_random_context_get_state (const struct webid_oidc_random_context
*ctx);
int webid_oidc_random_context_get_wait_bytes (const struct
webid_oidc_random_context *ctx,
size_t max, size_t start,
uint8_t * bytes,
size_t *n_bytes);
int webid_oidc_random_context_ok (struct webid_oidc_random_context *ctx);
int webid_oidc_random_context_bytes (struct webid_oidc_random_context *ctx,
size_t n_bytes, const uint8_t * bytes);
enum webid_oidc_random_context_spawn_flags
{
WEBID_OIDC_RANDOM_CONTEXT_THREAD_UNSAFE = 1
};
typedef enum webid_oidc_random_context_spawn_flags
webid_oidc_random_context_spawn_flags;
int webid_oidc_random_context_spawn (struct webid_oidc_random_context *parent,
struct webid_oidc_random_context *child,
enum
webid_oidc_random_context_spawn_flags
flags);
int webid_oidc_random_context_get (struct webid_oidc_random_context *ctx,
size_t request_size, uint8_t * data);
/* These functions set up and use a global state. Neither are
reentrant. */
void webid_oidc_random_init (void);
/* This function is thread-safe. */
void webid_oidc_random (size_t request_size, uint8_t * data);
#endif /* not H_RANDOM_INCLUDED */
|