webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
pool.h
Go to the documentation of this file.
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 #ifndef OPENSSL_HEADER_POOL_H
16 #define OPENSSL_HEADER_POOL_H
17 
18 #include <openssl/base.h>
19 
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 
25 /* Buffers and buffer pools.
26  *
27  * |CRYPTO_BUFFER|s are simply reference-counted blobs. A |CRYPTO_BUFFER_POOL| is
28  * an intern table for |CRYPTO_BUFFER|s. This allows for a single copy of a given
29  * blob to be kept in memory and referenced from multiple places. */
30 
31 
32 /* CRYPTO_BUFFER_POOL_new returns a freshly allocated |CRYPTO_BUFFER_POOL| or
33  * NULL on error. */
34 OPENSSL_EXPORT CRYPTO_BUFFER_POOL* CRYPTO_BUFFER_POOL_new(void);
35 
36 /* CRYPTO_BUFFER_POOL_free frees |pool|, which must be empty. */
37 OPENSSL_EXPORT void CRYPTO_BUFFER_POOL_free(CRYPTO_BUFFER_POOL *pool);
38 
39 /* CRYPTO_BUFFER_new returns a |CRYPTO_BUFFER| containing a copy of |data|, or
40  * else NULL on error. If |pool| is not NULL then the returned value may be a
41  * reference to a previously existing |CRYPTO_BUFFER| that contained the same
42  * data. Otherwise, the returned, fresh |CRYPTO_BUFFER| will be added to the
43  * pool. */
44 OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len,
45  CRYPTO_BUFFER_POOL *pool);
46 
47 /* CRYPTO_BUFFER_new_from_CBS acts the same as |CRYPTO_BUFFER_new|. */
49  CBS *cbs, CRYPTO_BUFFER_POOL *pool);
50 
51 /* CRYPTO_BUFFER_free decrements the reference count of |buf|. If there are no
52  * other references, or if the only remaining reference is from a pool, then
53  * |buf| will be freed. */
54 OPENSSL_EXPORT void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf);
55 
56 /* CRYPTO_BUFFER_up_ref increments the reference count of |buf| and returns
57  * one. */
58 OPENSSL_EXPORT int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf);
59 
60 /* CRYPTO_BUFFER_data returns a pointer to the data contained in |buf|. */
61 OPENSSL_EXPORT const uint8_t *CRYPTO_BUFFER_data(const CRYPTO_BUFFER *buf);
62 
63 /* CRYPTO_BUFFER_len returns the length, in bytes, of the data contained in
64  * |buf|. */
65 OPENSSL_EXPORT size_t CRYPTO_BUFFER_len(const CRYPTO_BUFFER *buf);
66 
67 /* CRYPTO_BUFFER_init_CBS initialises |out| to point at the data from |buf|. */
68 OPENSSL_EXPORT void CRYPTO_BUFFER_init_CBS(const CRYPTO_BUFFER *buf, CBS *out);
69 
70 
71 #if defined(__cplusplus)
72 } /* extern C */
73 
74 extern "C++" {
75 
76 namespace bssl {
77 
78 BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_free)
79 BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER, CRYPTO_BUFFER_free)
80 
81 } // namespace bssl
82 
83 } /* extern C++ */
84 
85 #endif
86 
87 #endif // OPENSSL_HEADER_POOL_H
OPENSSL_EXPORT const uint8_t * CRYPTO_BUFFER_data(const CRYPTO_BUFFER *buf)
Definition: pool.c:190
uint8_t uint8_t CBS * cbs
Definition: internal.h:759
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: gl2ext.h:134
OPENSSL_EXPORT void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf)
Definition: pool.c:142
OPENSSL_EXPORT size_t CRYPTO_BUFFER_len(const CRYPTO_BUFFER *buf)
Definition: pool.c:194
OPENSSL_EXPORT const ASN1_OBJECT int const unsigned char int len
Definition: x509.h:1053
OPENSSL_EXPORT void CRYPTO_BUFFER_POOL_free(CRYPTO_BUFFER_POOL *pool)
Definition: pool.c:58
int int * out
Definition: gcc-loops.cpp:206
#define OPENSSL_EXPORT
Definition: base.h:160
unsigned char uint8_t
Definition: ptypes.h:89
Definition: bytestring.h:37
OPENSSL_EXPORT CRYPTO_BUFFER_POOL * CRYPTO_BUFFER_POOL_new(void)
Definition: pool.c:40
EGLStreamKHR EGLint EGLint EGLint const void * data
Definition: eglext.h:984
OPENSSL_EXPORT int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf)
Definition: pool.c:179
Definition: bytestring_test.cc:31
OPENSSL_EXPORT CRYPTO_BUFFER * CRYPTO_BUFFER_new(const uint8_t *data, size_t len, CRYPTO_BUFFER_POOL *pool)
Definition: pool.c:74
OPENSSL_EXPORT CRYPTO_BUFFER * CRYPTO_BUFFER_new_from_CBS(CBS *cbs, CRYPTO_BUFFER_POOL *pool)
Definition: pool.c:138
OPENSSL_EXPORT void CRYPTO_BUFFER_init_CBS(const CRYPTO_BUFFER *buf, CBS *out)
Definition: pool.c:198