]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/comp/comp_lib.c
Run util/openssl-format-source -v -c .
[thirdparty/openssl.git] / crypto / comp / comp_lib.c
CommitLineData
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 7COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
ae5c8664
MC
8{
9 COMP_CTX *ret;
dfeab068 10
ae5c8664
MC
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}
dfeab068 23
6b691a5c 24void COMP_CTX_free(COMP_CTX *ctx)
ae5c8664
MC
25{
26 if (ctx == NULL)
27 return;
e03ddfae 28
ae5c8664
MC
29 if (ctx->meth->finish != NULL)
30 ctx->meth->finish(ctx);
dfeab068 31
ae5c8664
MC
32 OPENSSL_free(ctx);
33}
dfeab068 34
6b691a5c 35int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
ae5c8664
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 51int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
ae5c8664
MC
52 unsigned char *in, int ilen)
53{
54 int ret;
dfeab068 55
ae5c8664
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}