Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorAdam Langley <agl@chromium.org>2015-02-12 01:27:21 +0300
committerAdam Langley <agl@chromium.org>2015-02-13 21:59:10 +0300
commita1048a772fc19a1c3b5572b780b7df174b231a7c (patch)
treeb5f3b2bbfcfc724ed421c438038f94f975b3eadc /crypto
parent2d96a67218eb954dc3cd8018f7716d2b6cac5a9a (diff)
Add sk_deep_copy and its macro.
The next change imported from upstream needs this function. Change-Id: I547efa1f7f46f0558e88047837a26ede32b19275
Diffstat (limited to 'crypto')
-rw-r--r--crypto/stack/make_macros.sh3
-rw-r--r--crypto/stack/stack.c28
2 files changed, 31 insertions, 0 deletions
diff --git a/crypto/stack/make_macros.sh b/crypto/stack/make_macros.sh
index f72aa334..4837e449 100644
--- a/crypto/stack/make_macros.sh
+++ b/crypto/stack/make_macros.sh
@@ -86,6 +86,9 @@ output_stack () {
#define sk_${type}_set_cmp_func(sk, comp)\\
((int (*) (const ${type} **a, const ${type} **b)) sk_set_cmp_func(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(stack_cmp_func, int (*) (const ${type} **a, const ${type} **b), comp)))
+#define sk_${type}_deep_copy(sk, copy_func, free_func)\\
+((STACK_OF(${type})*) sk_deep_copy(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk), CHECKED_CAST(void* (*) (void*), ${ptrtype} (*) (${ptrtype}), copy_func), CHECKED_CAST(void (*) (void*), void (*) (${ptrtype}), free_func)))
+
EOF
}
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index 0b336ba4..c8332de4 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -360,3 +360,31 @@ stack_cmp_func sk_set_cmp_func(_STACK *sk, stack_cmp_func comp) {
return old;
}
+
+_STACK *sk_deep_copy(const _STACK *sk, void *(*copy_func)(void *),
+ void (*free_func)(void *)) {
+ _STACK *ret = sk_dup(sk);
+ if (ret == NULL) {
+ return NULL;
+ }
+
+ size_t i;
+ for (i = 0; i < ret->num; i++) {
+ if (ret->data[i] == NULL) {
+ continue;
+ }
+ ret->data[i] = copy_func(ret->data[i]);
+ if (ret->data[i] == NULL) {
+ size_t j;
+ for (j = 0; j < i; j++) {
+ if (ret->data[j] != NULL) {
+ free_func(ret->data[j]);
+ }
+ }
+ sk_free(ret);
+ return NULL;
+ }
+ }
+
+ return ret;
+}