2
0

comp_methods.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/crypto.h>
  10. #include <openssl/comp.h>
  11. #include <openssl/obj_mac.h>
  12. #include "internal/cryptlib.h"
  13. #include "internal/comp.h"
  14. #define SSL_COMP_NULL_IDX 0
  15. #define SSL_COMP_ZLIB_IDX 1
  16. #define SSL_COMP_NUM_IDX 2
  17. #ifndef OPENSSL_NO_COMP
  18. static int sk_comp_cmp(const SSL_COMP *const *a, const SSL_COMP *const *b)
  19. {
  20. return ((*a)->id - (*b)->id);
  21. }
  22. #endif
  23. STACK_OF(SSL_COMP) *ossl_load_builtin_compressions(void)
  24. {
  25. STACK_OF(SSL_COMP) *comp_methods = NULL;
  26. #ifndef OPENSSL_NO_COMP
  27. SSL_COMP *comp = NULL;
  28. COMP_METHOD *method = COMP_zlib();
  29. comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
  30. if (COMP_get_type(method) != NID_undef && comp_methods != NULL) {
  31. comp = OPENSSL_malloc(sizeof(*comp));
  32. if (comp != NULL) {
  33. comp->method = method;
  34. comp->id = SSL_COMP_ZLIB_IDX;
  35. comp->name = COMP_get_name(method);
  36. if (!sk_SSL_COMP_push(comp_methods, comp))
  37. OPENSSL_free(comp);
  38. }
  39. }
  40. #endif
  41. return comp_methods;
  42. }
  43. static void cmeth_free(SSL_COMP *cm)
  44. {
  45. OPENSSL_free(cm);
  46. }
  47. void ossl_free_compression_methods_int(STACK_OF(SSL_COMP) *methods)
  48. {
  49. sk_SSL_COMP_pop_free(methods, cmeth_free);
  50. }