]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/comp/comp_lib.c
Update copyright year
[thirdparty/openssl.git] / crypto / comp / comp_lib.c
CommitLineData
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 18COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
0f113f3e
MC
19{
20 COMP_CTX *ret;
dfeab068 21
fe1128dc 22 if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
9311d0c4 23 ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
26a7d938 24 return NULL;
fe1128dc 25 }
0f113f3e
MC
26 ret->meth = meth;
27 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
28 OPENSSL_free(ret);
29 ret = NULL;
30 }
26a7d938 31 return ret;
0f113f3e 32}
dfeab068 33
9a555706
RS
34const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx)
35{
36 return ctx->meth;
37}
38
39int COMP_get_type(const COMP_METHOD *meth)
40{
41 return meth->type;
42}
43
44const char *COMP_get_name(const COMP_METHOD *meth)
45{
46 return meth->name;
47}
48
6b691a5c 49void COMP_CTX_free(COMP_CTX *ctx)
0f113f3e 50{
e6e9170d
RS
51 if (ctx == NULL)
52 return;
0f113f3e
MC
53 if (ctx->meth->finish != NULL)
54 ctx->meth->finish(ctx);
dfeab068 55
0f113f3e
MC
56 OPENSSL_free(ctx);
57}
dfeab068 58
6b691a5c 59int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
0f113f3e
MC
60 unsigned char *in, int ilen)
61{
62 int ret;
63 if (ctx->meth->compress == NULL) {
26a7d938 64 return -1;
0f113f3e
MC
65 }
66 ret = ctx->meth->compress(ctx, out, olen, in, ilen);
67 if (ret > 0) {
68 ctx->compress_in += ilen;
69 ctx->compress_out += ret;
70 }
26a7d938 71 return ret;
0f113f3e 72}
dfeab068 73
6b691a5c 74int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
0f113f3e
MC
75 unsigned char *in, int ilen)
76{
77 int ret;
dfeab068 78
0f113f3e 79 if (ctx->meth->expand == NULL) {
26a7d938 80 return -1;
0f113f3e
MC
81 }
82 ret = ctx->meth->expand(ctx, out, olen, in, ilen);
83 if (ret > 0) {
84 ctx->expand_in += ilen;
85 ctx->expand_out += ret;
86 }
26a7d938 87 return ret;
0f113f3e 88}
9a555706
RS
89
90int COMP_CTX_get_type(const COMP_CTX* comp)
91{
92 return comp->meth ? comp->meth->type : NID_undef;
93}