Debian Codegraph @

external/boringssl/decrepit/obj/obj_decrepit.c

raw
1 /* Copyright (c) 2016, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15 #include <openssl/obj.h>
16
17 #include <assert.h>
18 #include <string.h>
19
20 #include <openssl/evp.h>
21
22
23 struct wrapped_callback {
24 void (*callback)(const OBJ_NAME *, void *arg);
25 void *arg;
26 };
27
28 static void cipher_callback(const EVP_CIPHER *cipher, const char *name,
29 const char *unused, void *arg) {
30 const struct wrapped_callback *wrapped = (struct wrapped_callback *)arg;
31 OBJ_NAME obj_name;
32
33 memset(&obj_name, 0, sizeof(obj_name));
34 obj_name.type = OBJ_NAME_TYPE_CIPHER_METH;
35 obj_name.name = name;
36
37 wrapped->callback(&obj_name, wrapped->arg);
38 }
39
40 static void md_callback(const EVP_MD *md, const char *name, const char *unused,
41 void *arg) {
42 const struct wrapped_callback *wrapped = (struct wrapped_callback*) arg;
43 OBJ_NAME obj_name;
44
45 memset(&obj_name, 0, sizeof(obj_name));
46 obj_name.type = OBJ_NAME_TYPE_MD_METH;
47 obj_name.name = name;
48
49 wrapped->callback(&obj_name, wrapped->arg);
50 }
51
52 void OBJ_NAME_do_all_sorted(int type,
53 void (*callback)(const OBJ_NAME *, void *arg),
54 void *arg) {
55 struct wrapped_callback wrapped;
56 wrapped.callback = callback;
57 wrapped.arg = arg;
58
59 if (type == OBJ_NAME_TYPE_CIPHER_METH) {
60 EVP_CIPHER_do_all_sorted(cipher_callback, &wrapped);
61 } else if (type == OBJ_NAME_TYPE_MD_METH) {
62 EVP_MD_do_all_sorted(md_callback, &wrapped);
63 } else {
64 assert(0);
65 }
66 }
67
68 void OBJ_NAME_do_all(int type, void (*callback)(const OBJ_NAME *, void *arg),
69 void *arg) {
70 OBJ_NAME_do_all_sorted(type, callback, arg);
71 }