Run util/openssl-format-source -v -c .
[openssl.git] / crypto / comp / comp_lib.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <openssl/objects.h>
5 #include <openssl/comp.h>
6
7 COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
8 {
9     COMP_CTX *ret;
10
11     if ((ret = (COMP_CTX *)OPENSSL_malloc(sizeof(COMP_CTX))) == NULL) {
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 }
23
24 void COMP_CTX_free(COMP_CTX *ctx)
25 {
26     if (ctx == NULL)
27         return;
28
29     if (ctx->meth->finish != NULL)
30         ctx->meth->finish(ctx);
31
32     OPENSSL_free(ctx);
33 }
34
35 int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
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 }
50
51 int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
52                       unsigned char *in, int ilen)
53 {
54     int ret;
55
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 }