2019-01-24 10:15:54 +08:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2020-04-06 20:00:55 +08:00
|
|
|
OPENSSL_SA, ossl_sa_TYPE_new, ossl_sa_TYPE_free,
|
2019-01-24 10:15:54 +08:00
|
|
|
ossl_sa_TYPE_free_leaves, ossl_sa_TYPE_num, ossl_sa_TYPE_doall,
|
|
|
|
ossl_sa_TYPE_doall_arg, ossl_sa_TYPE_get, ossl_sa_TYPE_set
|
|
|
|
- sparse array container
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/sparse_array.h"
|
2019-01-24 10:15:54 +08:00
|
|
|
|
|
|
|
typedef struct sparse_array_st OPENSSL_SA;
|
|
|
|
|
|
|
|
SPARSE_ARRAY_OF(TYPE)
|
|
|
|
DEFINE_SPARSE_ARRAY_OF(TYPE)
|
|
|
|
|
|
|
|
SPARSE_ARRAY_OF(TYPE) *ossl_sa_TYPE_new(void);
|
|
|
|
void ossl_sa_TYPE_free(const SPARSE_ARRAY_OF(TYPE) *sa);
|
|
|
|
void ossl_sa_TYPE_free_leaves(const SPARSE_ARRAY_OF(TYPE) *sa);
|
2019-03-06 11:50:54 +08:00
|
|
|
size_t ossl_sa_TYPE_num(const SPARSE_ARRAY_OF(TYPE) *sa);
|
|
|
|
void ossl_sa_TYPE_doall(const OPENSSL_SA *sa, void (*leaf)(ossl_uintmax_t,
|
|
|
|
void *));
|
2019-02-14 06:13:58 +08:00
|
|
|
void ossl_sa_TYPE_doall_arg(const OPENSSL_SA *sa,
|
2019-03-06 11:50:54 +08:00
|
|
|
void (*leaf)(ossl_uintmax_t, void *, void *),
|
|
|
|
void *arg);
|
|
|
|
TYPE *ossl_sa_TYPE_get(const SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx);
|
|
|
|
int ossl_sa_TYPE_set(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx,
|
|
|
|
TYPE *value);
|
2019-01-24 10:15:54 +08:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
=begin comment
|
|
|
|
|
|
|
|
POD is pretty good at recognising function names and making them appropriately
|
|
|
|
bold... however, when part of the function name is variable, we have to help
|
|
|
|
the processor along
|
|
|
|
|
|
|
|
=end comment
|
|
|
|
|
2019-01-24 10:15:54 +08:00
|
|
|
SPARSE_ARRAY_OF() returns the name for a sparse array of the specified
|
2019-09-28 13:33:38 +08:00
|
|
|
B<I<TYPE>>. DEFINE_STACK_OF() creates set of functions for a sparse
|
|
|
|
array of B<I<TYPE>>. This will mean that a pointer to type B<I<TYPE>>
|
|
|
|
is stored in each element of a sparse array, the type is referenced by
|
|
|
|
B<SPARSE_ARRAY_OF>(B<I<TYPE>>) and each function name begins with
|
|
|
|
B<ossl_sa_I<TYPE>_>. For example:
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-03-06 11:50:54 +08:00
|
|
|
TYPE *ossl_sa_TYPE_get(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx);
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_num>() returns the number of elements in I<sa> or 0 if I<sa>
|
|
|
|
is NULL.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_get>() returns element I<idx> in I<sa>, where I<idx> starts
|
|
|
|
at zero. If I<idx> refers to a value that has not been set then NULL is
|
2019-01-24 10:15:54 +08:00
|
|
|
returned.
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_set>() sets element I<idx> in I<sa> to I<value>, where I<idx>
|
2019-01-24 10:15:54 +08:00
|
|
|
starts at zero. The sparse array will be resized as required.
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_new>() allocates a new empty sparse array.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_free>() frees up the I<sa> structure. It does I<not> free up any
|
2019-09-27 19:26:22 +08:00
|
|
|
elements of I<sa>. After this call I<sa> is no longer valid.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_free_leaves>() frees up the I<sa> structure and all of its
|
2019-09-27 19:26:22 +08:00
|
|
|
elements. After this call I<sa> is no longer valid.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_doall>() calls the function I<leaf> for each element in I<sa>
|
2019-02-14 06:13:58 +08:00
|
|
|
in ascending index order. The index position, within the sparse array,
|
|
|
|
of each item is passed as the first argument to the leaf function and a
|
2020-06-30 03:13:07 +08:00
|
|
|
pointer to the associated value is passed as the second argument.
|
2019-02-14 06:13:58 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_doall_arg>() calls the function I<leaf> for each element in
|
2019-09-27 19:26:22 +08:00
|
|
|
I<sa> in ascending index order. The index position, within the sparse
|
2019-02-14 06:13:58 +08:00
|
|
|
array, of each item is passed as the first argument to the leaf function,
|
|
|
|
a pointer to the associated value is passed as the second argument and
|
2019-09-27 19:26:22 +08:00
|
|
|
the third argument is the user supplied I<arg>.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
=head1 NOTES
|
|
|
|
|
|
|
|
Sparse arrays are an internal data structure and should B<not> be used by user
|
|
|
|
applications.
|
|
|
|
|
|
|
|
Care should be taken when accessing sparse arrays in multi-threaded
|
2019-09-28 11:48:54 +08:00
|
|
|
environments. The B<ossl_sa_I<TYPE>_set>() operation can cause the internal
|
|
|
|
structure of the sparse array to change which causes race conditions if the
|
|
|
|
sparse array is accessed in a different thread.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
|
|
|
SPARSE_ARRAY_OF() and DEFINE_SPARSE_ARRAY_OF() are implemented as macros.
|
|
|
|
|
|
|
|
The underlying utility B<OPENSSL_SA_> API should not be used directly. It
|
|
|
|
defines these functions: OPENSSL_SA_doall, OPENSSL_SA_doall_arg,
|
|
|
|
OPENSSL_SA_free, OPENSSL_SA_free_leaves, OPENSSL_SA_get, OPENSSL_SA_new,
|
|
|
|
OPENSSL_SA_num and OPENSSL_SA_set.
|
|
|
|
|
|
|
|
=head1 RETURN VALUES
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_num>() returns the number of elements in the sparse array or
|
|
|
|
B<0> if the passed sparse array is NULL.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_get>() returns a pointer to a sparse array element or NULL if
|
2019-01-24 10:15:54 +08:00
|
|
|
the element has not be set.
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_set>() return B<1> on success and B<0> on error. In the latter
|
2019-01-24 10:15:54 +08:00
|
|
|
case, the elements of the sparse array remain unchanged, although the internal
|
|
|
|
structures might have.
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_new>() returns an empty sparse array or NULL if an error
|
2019-01-24 10:15:54 +08:00
|
|
|
occurs.
|
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
B<ossl_sa_I<TYPE>_doall>(), B<ossl_sa_I<TYPE>_doall_arg>(),
|
|
|
|
B<ossl_sa_I<TYPE>_free>() and B<ossl_sa_I<TYPE>_free_leaves>()
|
|
|
|
do not return values.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
|
|
|
=head1 HISTORY
|
|
|
|
|
2019-07-15 21:03:44 +08:00
|
|
|
This functionality was added to OpenSSL 3.0.
|
2019-01-24 10:15:54 +08:00
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
2020-04-23 20:55:52 +08:00
|
|
|
Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. Copyright
|
2019-01-24 10:15:54 +08:00
|
|
|
(c) 2019, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License 2.0 (the "License"). You may not use this
|
|
|
|
file except in compliance with the License. You can obtain a copy in the file
|
|
|
|
LICENSE in the source distribution or at
|
|
|
|
L<https://www.openssl.org/source/license.html>.
|
|
|
|
|
|
|
|
=cut
|