2 * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include <openssl/crypto.h>
16 static long saved_argl;
17 static void *saved_argp;
20 static void exnew(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp)
23 assert(idx == saved_idx);
24 assert(argl == saved_argl);
25 assert(argp == saved_argp);
28 static int exdup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,
29 void *from_d, int idx, long argl, void *argp)
31 assert(idx == saved_idx);
32 assert(argl == saved_argl);
33 assert(argp == saved_argp);
37 static void exfree(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
38 int idx, long argl, void *argp)
40 assert(idx == saved_idx);
41 assert(argl == saved_argl);
42 assert(argp == saved_argp);
45 typedef struct myobj_st {
46 CRYPTO_EX_DATA ex_data;
51 static MYOBJ *MYOBJ_new()
54 MYOBJ *obj = OPENSSL_malloc(sizeof(*obj));
57 obj->st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);
62 static void MYOBJ_sethello(MYOBJ *obj, char *cp)
64 obj->st = CRYPTO_set_ex_data(&obj->ex_data, saved_idx, cp);
68 static char *MYOBJ_gethello(MYOBJ *obj)
70 return CRYPTO_get_ex_data(&obj->ex_data, saved_idx);
73 static void MYOBJ_free(MYOBJ *obj)
75 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);
85 p = strdup("hello world");
87 saved_argp = malloc(1);
88 saved_idx = CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_APP,
89 saved_argl, saved_argp,
90 exnew, exdup, exfree);
93 MYOBJ_sethello(t1, p);
94 cp = MYOBJ_gethello(t1);
98 cp = MYOBJ_gethello(t2);