]>
Commit | Line | Data |
---|---|---|
dfeab068 RE |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <string.h> | |
ec577822 BM |
4 | #include <openssl/objects.h> |
5 | #include <openssl/comp.h> | |
dfeab068 | 6 | |
6b691a5c | 7 | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth) |
0f113f3e MC |
8 | { |
9 | COMP_CTX *ret; | |
dfeab068 | 10 | |
b196e7d9 | 11 | if ((ret = OPENSSL_malloc(sizeof(COMP_CTX))) == NULL) { |
0f113f3e MC |
12 | /* ZZZZZZZZZZZZZZZZ */ |
13 | return (NULL); | |
14 | } | |
15 | memset(ret, 0, sizeof(COMP_CTX)); | |
16 | ret->meth = meth; | |
17 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { | |
18 | OPENSSL_free(ret); | |
19 | ret = NULL; | |
20 | } | |
21 | return (ret); | |
22 | } | |
dfeab068 | 23 | |
6b691a5c | 24 | void COMP_CTX_free(COMP_CTX *ctx) |
0f113f3e MC |
25 | { |
26 | if (ctx == NULL) | |
27 | return; | |
e03ddfae | 28 | |
0f113f3e MC |
29 | if (ctx->meth->finish != NULL) |
30 | ctx->meth->finish(ctx); | |
dfeab068 | 31 | |
0f113f3e MC |
32 | OPENSSL_free(ctx); |
33 | } | |
dfeab068 | 34 | |
6b691a5c | 35 | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, |
0f113f3e MC |
36 | unsigned char *in, int ilen) |
37 | { | |
38 | int ret; | |
39 | if (ctx->meth->compress == NULL) { | |
40 | /* ZZZZZZZZZZZZZZZZZ */ | |
41 | return (-1); | |
42 | } | |
43 | ret = ctx->meth->compress(ctx, out, olen, in, ilen); | |
44 | if (ret > 0) { | |
45 | ctx->compress_in += ilen; | |
46 | ctx->compress_out += ret; | |
47 | } | |
48 | return (ret); | |
49 | } | |
dfeab068 | 50 | |
6b691a5c | 51 | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, |
0f113f3e MC |
52 | unsigned char *in, int ilen) |
53 | { | |
54 | int ret; | |
dfeab068 | 55 | |
0f113f3e MC |
56 | if (ctx->meth->expand == NULL) { |
57 | /* ZZZZZZZZZZZZZZZZZ */ | |
58 | return (-1); | |
59 | } | |
60 | ret = ctx->meth->expand(ctx, out, olen, in, ilen); | |
61 | if (ret > 0) { | |
62 | ctx->expand_in += ilen; | |
63 | ctx->expand_out += ret; | |
64 | } | |
65 | return (ret); | |
66 | } |