| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-02-18 22:57:13 +08:00
										 |  |  |  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |  * Copyright (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 | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:57 +08:00
										 |  |  | #ifndef OSSL_CRYPTO_SPARSE_ARRAY_H
 | 
					
						
							|  |  |  | # define OSSL_CRYPTO_SPARSE_ARRAY_H
 | 
					
						
							| 
									
										
										
										
											2021-02-07 05:36:46 +08:00
										 |  |  | # pragma once
 | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-15 15:06:36 +08:00
										 |  |  | # include <openssl/e_os2.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  | # ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # define SPARSE_ARRAY_OF(type) struct sparse_array_st_ ## type
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-01 15:55:33 +08:00
										 |  |  | # define DEFINE_SPARSE_ARRAY_OF_INTERNAL(type, ctype) \
 | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     SPARSE_ARRAY_OF(type); \ | 
					
						
							| 
									
										
										
										
											2019-02-15 15:06:36 +08:00
										 |  |  |     static ossl_unused ossl_inline SPARSE_ARRAY_OF(type) * \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |         ossl_sa_##type##_new(void) \ | 
					
						
							|  |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         return (SPARSE_ARRAY_OF(type) *)ossl_sa_new(); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline void \ | 
					
						
							|  |  |  |     ossl_sa_##type##_free(SPARSE_ARRAY_OF(type) *sa) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         ossl_sa_free((OPENSSL_SA *)sa); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline void \ | 
					
						
							|  |  |  |     ossl_sa_##type##_free_leaves(SPARSE_ARRAY_OF(type) *sa) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         ossl_sa_free_leaves((OPENSSL_SA *)sa); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline size_t \ | 
					
						
							|  |  |  |     ossl_sa_##type##_num(const SPARSE_ARRAY_OF(type) *sa) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         return ossl_sa_num((OPENSSL_SA *)sa); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline void \ | 
					
						
							|  |  |  |     ossl_sa_##type##_doall(const SPARSE_ARRAY_OF(type) *sa, \ | 
					
						
							|  |  |  |                            void (*leaf)(ossl_uintmax_t, type *)) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         ossl_sa_doall((OPENSSL_SA *)sa, \ | 
					
						
							|  |  |  |                       (void (*)(ossl_uintmax_t, void *))leaf); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline void \ | 
					
						
							|  |  |  |     ossl_sa_##type##_doall_arg(const SPARSE_ARRAY_OF(type) *sa, \ | 
					
						
							|  |  |  |                                void (*leaf)(ossl_uintmax_t, type *, void *), \ | 
					
						
							|  |  |  |                                void *arg) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         ossl_sa_doall_arg((OPENSSL_SA *)sa, \ | 
					
						
							|  |  |  |                           (void (*)(ossl_uintmax_t, void *, void *))leaf, arg); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline ctype \ | 
					
						
							|  |  |  |     *ossl_sa_##type##_get(const SPARSE_ARRAY_OF(type) *sa, ossl_uintmax_t n) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         return (type *)ossl_sa_get((OPENSSL_SA *)sa, n); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |     static ossl_unused ossl_inline int \ | 
					
						
							|  |  |  |     ossl_sa_##type##_set(SPARSE_ARRAY_OF(type) *sa, \ | 
					
						
							|  |  |  |                          ossl_uintmax_t n, ctype *val) \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     { \ | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  |         return ossl_sa_set((OPENSSL_SA *)sa, n, (void *)val); \ | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  |     } \ | 
					
						
							|  |  |  |     SPARSE_ARRAY_OF(type) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-01 15:55:33 +08:00
										 |  |  | # define DEFINE_SPARSE_ARRAY_OF(type) \
 | 
					
						
							|  |  |  |     DEFINE_SPARSE_ARRAY_OF_INTERNAL(type, type) | 
					
						
							|  |  |  | # define DEFINE_SPARSE_ARRAY_OF_CONST(type) \
 | 
					
						
							|  |  |  |     DEFINE_SPARSE_ARRAY_OF_INTERNAL(type, const type) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  | typedef struct sparse_array_st OPENSSL_SA; | 
					
						
							| 
									
										
										
										
											2021-03-09 10:07:36 +08:00
										 |  |  | OPENSSL_SA *ossl_sa_new(void); | 
					
						
							|  |  |  | void ossl_sa_free(OPENSSL_SA *sa); | 
					
						
							|  |  |  | void ossl_sa_free_leaves(OPENSSL_SA *sa); | 
					
						
							|  |  |  | size_t ossl_sa_num(const OPENSSL_SA *sa); | 
					
						
							|  |  |  | void ossl_sa_doall(const OPENSSL_SA *sa, void (*leaf)(ossl_uintmax_t, void *)); | 
					
						
							|  |  |  | void ossl_sa_doall_arg(const OPENSSL_SA *sa, | 
					
						
							|  |  |  |                        void (*leaf)(ossl_uintmax_t, void *, void *), void *); | 
					
						
							|  |  |  | void *ossl_sa_get(const OPENSSL_SA *sa, ossl_uintmax_t n); | 
					
						
							|  |  |  | int ossl_sa_set(OPENSSL_SA *sa, ossl_uintmax_t n, void *val); | 
					
						
							| 
									
										
										
										
											2019-01-24 10:15:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # ifdef  __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  | #endif
 |