/* 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 . */ #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 */