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 |
|
---|
10 | #include <openssl/crypto.h>
|
---|
11 | #include <openssl/comp.h>
|
---|
12 | #include <openssl/obj_mac.h>
|
---|
13 |
|
---|
14 | #include "internal/cryptlib.h"
|
---|
15 | #include "internal/comp.h"
|
---|
16 |
|
---|
17 | #define SSL_COMP_NULL_IDX 0
|
---|
18 | #define SSL_COMP_ZLIB_IDX 1
|
---|
19 | #define SSL_COMP_NUM_IDX 2
|
---|
20 |
|
---|
21 | #ifndef OPENSSL_NO_COMP
|
---|
22 | static int sk_comp_cmp(const SSL_COMP *const *a, const SSL_COMP *const *b)
|
---|
23 | {
|
---|
24 | return ((*a)->id - (*b)->id);
|
---|
25 | }
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | STACK_OF(SSL_COMP) *ossl_load_builtin_compressions(void)
|
---|
29 | {
|
---|
30 | STACK_OF(SSL_COMP) *comp_methods = NULL;
|
---|
31 | #ifndef OPENSSL_NO_COMP
|
---|
32 | SSL_COMP *comp = NULL;
|
---|
33 | COMP_METHOD *method = COMP_zlib();
|
---|
34 |
|
---|
35 | comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
|
---|
36 |
|
---|
37 | if (COMP_get_type(method) != NID_undef && comp_methods != NULL) {
|
---|
38 | comp = OPENSSL_malloc(sizeof(*comp));
|
---|
39 | if (comp != NULL) {
|
---|
40 | comp->method = method;
|
---|
41 | comp->id = SSL_COMP_ZLIB_IDX;
|
---|
42 | comp->name = COMP_get_name(method);
|
---|
43 | if (!sk_SSL_COMP_push(comp_methods, comp))
|
---|
44 | OPENSSL_free(comp);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | #endif
|
---|
48 | return comp_methods;
|
---|
49 | }
|
---|
50 |
|
---|
51 | static void cmeth_free(SSL_COMP *cm)
|
---|
52 | {
|
---|
53 | OPENSSL_free(cm);
|
---|
54 | }
|
---|
55 |
|
---|
56 | void ossl_free_compression_methods_int(STACK_OF(SSL_COMP) *methods)
|
---|
57 | {
|
---|
58 | sk_SSL_COMP_pop_free(methods, cmeth_free);
|
---|
59 | }
|
---|