You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
3.2 KiB

  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. #ifndef OPENSSL_HEADER_POOL_H
  15. #define OPENSSL_HEADER_POOL_H
  16. #include <openssl/base.h>
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. /* Buffers and buffer pools.
  21. *
  22. * |CRYPTO_BUFFER|s are simply reference-counted blobs. A |CRYPTO_BUFFER_POOL|
  23. * is an intern table for |CRYPTO_BUFFER|s. This allows for a single copy of a
  24. * given blob to be kept in memory and referenced from multiple places. */
  25. /* CRYPTO_BUFFER_POOL_new returns a freshly allocated |CRYPTO_BUFFER_POOL| or
  26. * NULL on error. */
  27. OPENSSL_EXPORT CRYPTO_BUFFER_POOL* CRYPTO_BUFFER_POOL_new(void);
  28. /* CRYPTO_BUFFER_POOL_free frees |pool|, which must be empty. */
  29. OPENSSL_EXPORT void CRYPTO_BUFFER_POOL_free(CRYPTO_BUFFER_POOL *pool);
  30. /* CRYPTO_BUFFER_new returns a |CRYPTO_BUFFER| containing a copy of |data|, or
  31. * else NULL on error. If |pool| is not NULL then the returned value may be a
  32. * reference to a previously existing |CRYPTO_BUFFER| that contained the same
  33. * data. Otherwise, the returned, fresh |CRYPTO_BUFFER| will be added to the
  34. * pool. */
  35. OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len,
  36. CRYPTO_BUFFER_POOL *pool);
  37. /* CRYPTO_BUFFER_new_from_CBS acts the same as |CRYPTO_BUFFER_new|. */
  38. OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new_from_CBS(
  39. CBS *cbs, CRYPTO_BUFFER_POOL *pool);
  40. /* CRYPTO_BUFFER_free decrements the reference count of |buf|. If there are no
  41. * other references, or if the only remaining reference is from a pool, then
  42. * |buf| will be freed. */
  43. OPENSSL_EXPORT void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf);
  44. /* CRYPTO_BUFFER_up_ref increments the reference count of |buf| and returns
  45. * one. */
  46. OPENSSL_EXPORT int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf);
  47. /* CRYPTO_BUFFER_data returns a pointer to the data contained in |buf|. */
  48. OPENSSL_EXPORT const uint8_t *CRYPTO_BUFFER_data(const CRYPTO_BUFFER *buf);
  49. /* CRYPTO_BUFFER_len returns the length, in bytes, of the data contained in
  50. * |buf|. */
  51. OPENSSL_EXPORT size_t CRYPTO_BUFFER_len(const CRYPTO_BUFFER *buf);
  52. /* CRYPTO_BUFFER_init_CBS initialises |out| to point at the data from |buf|. */
  53. OPENSSL_EXPORT void CRYPTO_BUFFER_init_CBS(const CRYPTO_BUFFER *buf, CBS *out);
  54. #if defined(__cplusplus)
  55. } /* extern C */
  56. extern "C++" {
  57. namespace bssl {
  58. BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_free)
  59. BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER, CRYPTO_BUFFER_free)
  60. } // namespace bssl
  61. } /* extern C++ */
  62. #endif
  63. #endif // OPENSSL_HEADER_POOL_H