2016-10-26 01:33:49 +01:00
|
|
|
/* Copyright (c) 2016, Google Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
|
|
|
|
#ifndef OPENSSL_HEADER_POOL_H
|
|
|
|
#define OPENSSL_HEADER_POOL_H
|
|
|
|
|
|
|
|
#include <openssl/base.h>
|
|
|
|
|
2017-04-15 23:12:55 +01:00
|
|
|
#include <openssl/stack.h>
|
|
|
|
|
2016-10-26 01:33:49 +01:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Buffers and buffer pools.
|
|
|
|
//
|
|
|
|
// |CRYPTO_BUFFER|s are simply reference-counted blobs. A |CRYPTO_BUFFER_POOL|
|
|
|
|
// is an intern table for |CRYPTO_BUFFER|s. This allows for a single copy of a
|
|
|
|
// given blob to be kept in memory and referenced from multiple places.
|
2016-10-26 01:33:49 +01:00
|
|
|
|
|
|
|
|
2017-04-15 23:12:55 +01:00
|
|
|
DEFINE_STACK_OF(CRYPTO_BUFFER)
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_POOL_new returns a freshly allocated |CRYPTO_BUFFER_POOL| or
|
|
|
|
// NULL on error.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT CRYPTO_BUFFER_POOL* CRYPTO_BUFFER_POOL_new(void);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_POOL_free frees |pool|, which must be empty.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT void CRYPTO_BUFFER_POOL_free(CRYPTO_BUFFER_POOL *pool);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_new returns a |CRYPTO_BUFFER| containing a copy of |data|, or
|
|
|
|
// else NULL on error. If |pool| is not NULL then the returned value may be a
|
|
|
|
// reference to a previously existing |CRYPTO_BUFFER| that contained the same
|
|
|
|
// data. Otherwise, the returned, fresh |CRYPTO_BUFFER| will be added to the
|
|
|
|
// pool.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len,
|
|
|
|
CRYPTO_BUFFER_POOL *pool);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_new_from_CBS acts the same as |CRYPTO_BUFFER_new|.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new_from_CBS(
|
|
|
|
CBS *cbs, CRYPTO_BUFFER_POOL *pool);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_free decrements the reference count of |buf|. If there are no
|
|
|
|
// other references, or if the only remaining reference is from a pool, then
|
|
|
|
// |buf| will be freed.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_up_ref increments the reference count of |buf| and returns
|
|
|
|
// one.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_data returns a pointer to the data contained in |buf|.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT const uint8_t *CRYPTO_BUFFER_data(const CRYPTO_BUFFER *buf);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_len returns the length, in bytes, of the data contained in
|
|
|
|
// |buf|.
|
2016-10-28 13:55:59 +01:00
|
|
|
OPENSSL_EXPORT size_t CRYPTO_BUFFER_len(const CRYPTO_BUFFER *buf);
|
2016-10-26 01:33:49 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CRYPTO_BUFFER_init_CBS initialises |out| to point at the data from |buf|.
|
2016-10-26 01:33:49 +01:00
|
|
|
OPENSSL_EXPORT void CRYPTO_BUFFER_init_CBS(const CRYPTO_BUFFER *buf, CBS *out);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
2017-08-19 00:21:50 +01:00
|
|
|
} // extern C
|
2016-10-26 01:33:49 +01:00
|
|
|
|
|
|
|
extern "C++" {
|
|
|
|
|
|
|
|
namespace bssl {
|
|
|
|
|
|
|
|
BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_free)
|
|
|
|
BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER, CRYPTO_BUFFER_free)
|
|
|
|
|
|
|
|
} // namespace bssl
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
} // extern C++
|
2016-10-26 01:33:49 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // OPENSSL_HEADER_POOL_H
|