]>
Commit | Line | Data |
---|---|---|
62867571 | 1 | /* |
605856d7 | 2 | * Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved. |
9a555706 | 3 | * |
48f66f81 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
62867571 RS |
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 | |
9a555706 RS |
8 | */ |
9 | ||
dfeab068 RE |
10 | #include <stdio.h> |
11 | #include <stdlib.h> | |
12 | #include <string.h> | |
ec577822 BM |
13 | #include <openssl/objects.h> |
14 | #include <openssl/comp.h> | |
fe1128dc | 15 | #include <openssl/err.h> |
706457b7 | 16 | #include "comp_local.h" |
dfeab068 | 17 | |
6b691a5c | 18 | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth) |
0f113f3e MC |
19 | { |
20 | COMP_CTX *ret; | |
dfeab068 | 21 | |
7e3cacac TS |
22 | if (meth == NULL) |
23 | return NULL; | |
24 | ||
e077455e | 25 | if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) |
26a7d938 | 26 | return NULL; |
0f113f3e MC |
27 | ret->meth = meth; |
28 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { | |
29 | OPENSSL_free(ret); | |
30 | ret = NULL; | |
31 | } | |
26a7d938 | 32 | return ret; |
0f113f3e | 33 | } |
dfeab068 | 34 | |
9a555706 RS |
35 | const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx) |
36 | { | |
37 | return ctx->meth; | |
38 | } | |
39 | ||
40 | int COMP_get_type(const COMP_METHOD *meth) | |
41 | { | |
7e3cacac TS |
42 | if (meth == NULL) |
43 | return NID_undef; | |
9a555706 RS |
44 | return meth->type; |
45 | } | |
46 | ||
47 | const char *COMP_get_name(const COMP_METHOD *meth) | |
48 | { | |
7e3cacac TS |
49 | if (meth == NULL) |
50 | return NULL; | |
9a555706 RS |
51 | return meth->name; |
52 | } | |
53 | ||
6b691a5c | 54 | void COMP_CTX_free(COMP_CTX *ctx) |
0f113f3e | 55 | { |
e6e9170d RS |
56 | if (ctx == NULL) |
57 | return; | |
0f113f3e MC |
58 | if (ctx->meth->finish != NULL) |
59 | ctx->meth->finish(ctx); | |
dfeab068 | 60 | |
0f113f3e MC |
61 | OPENSSL_free(ctx); |
62 | } | |
dfeab068 | 63 | |
6b691a5c | 64 | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, |
0f113f3e MC |
65 | unsigned char *in, int ilen) |
66 | { | |
67 | int ret; | |
68 | if (ctx->meth->compress == NULL) { | |
26a7d938 | 69 | return -1; |
0f113f3e MC |
70 | } |
71 | ret = ctx->meth->compress(ctx, out, olen, in, ilen); | |
72 | if (ret > 0) { | |
73 | ctx->compress_in += ilen; | |
74 | ctx->compress_out += ret; | |
75 | } | |
26a7d938 | 76 | return ret; |
0f113f3e | 77 | } |
dfeab068 | 78 | |
6b691a5c | 79 | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, |
0f113f3e MC |
80 | unsigned char *in, int ilen) |
81 | { | |
82 | int ret; | |
dfeab068 | 83 | |
0f113f3e | 84 | if (ctx->meth->expand == NULL) { |
26a7d938 | 85 | return -1; |
0f113f3e MC |
86 | } |
87 | ret = ctx->meth->expand(ctx, out, olen, in, ilen); | |
88 | if (ret > 0) { | |
89 | ctx->expand_in += ilen; | |
90 | ctx->expand_out += ret; | |
91 | } | |
26a7d938 | 92 | return ret; |
0f113f3e | 93 | } |
9a555706 RS |
94 | |
95 | int COMP_CTX_get_type(const COMP_CTX* comp) | |
96 | { | |
97 | return comp->meth ? comp->meth->type : NID_undef; | |
98 | } |